summaryrefslogtreecommitdiffstats
path: root/lib/Phi/Widget.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Phi/Widget.hs')
-rw-r--r--lib/Phi/Widget.hs12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/Phi/Widget.hs b/lib/Phi/Widget.hs
index f498b2c..5ffd534 100644
--- a/lib/Phi/Widget.hs
+++ b/lib/Phi/Widget.hs
@@ -13,6 +13,7 @@ module Phi.Widget ( Display(..)
, IOCache
, RenderCache
, createIOCache
+ , runIOCache
, createRenderCache
, renderCached
, Separator
@@ -73,7 +74,7 @@ unionArea a b = fromIntegral $ uw*uh
data SurfaceSlice = SurfaceSlice !Int !Surface
-class (Show w, Eq w, Eq s) => Widget w s c | w -> s, w -> c where
+class Eq s => Widget w s c | w -> s, w -> c where
initWidget :: w -> Phi -> Display -> IO s
initCache :: w -> c
@@ -97,6 +98,13 @@ type RenderCache w s = IOCache (w, s, Int, Int, Int, Int, Xlib.Rectangle) Surfac
createIOCache :: Eq a => (a -> IO b) -> IOCache a b
createIOCache = lift . Kleisli
+runIOCache :: Eq a => a -> StateT (IOCache a b) IO (b, Bool)
+runIOCache a = do
+ cache <- get
+ (b, updated, cache') <- liftIO $ runKleisli (runCache' cache) a
+ put cache'
+ return (b, updated)
+
createRenderCache :: (w -> s -> Int -> Int -> Int -> Int -> Xlib.Rectangle -> Render ())
-> CacheArrow (Kleisli IO) (w, s, Int, Int, Int, Int, Xlib.Rectangle) Surface
createRenderCache f = lift . Kleisli $ \(widget, state, x, y, w, h, screen) -> do
@@ -116,8 +124,6 @@ renderCached widget state x y w h screen = do
return [(updated, SurfaceSlice 0 surf)]
data CompoundWidget a sa ca b sb cb = (Widget a sa ca, Widget b sb cb) => CompoundWidget !a !b
-deriving instance Eq (CompoundWidget a sa ca b sb cb)
-deriving instance Show (CompoundWidget a sa ca b sb cb)
data CompoundState a sa ca b sb cb = (Widget a sa ca, Widget b sb cb) => CompoundState !sa !sb !Int
deriving instance Eq (CompoundState a sa ca b sb cb)