From e4314c03faa77d71ad69ec37b83e2634e1a2a9c9 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 14 Jul 2011 06:16:04 +0200 Subject: Some more restructuring, WIP --- lib/Phi/Widget.hs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'lib/Phi/Widget.hs') diff --git a/lib/Phi/Widget.hs b/lib/Phi/Widget.hs index 9262aba..3f00508 100644 --- a/lib/Phi/Widget.hs +++ b/lib/Phi/Widget.hs @@ -1,6 +1,7 @@ {-# LANGUAGE ExistentialQuantification, TypeFamilies, StandaloneDeriving, FlexibleContexts #-} -module Phi.Widget ( Widget(..) +module Phi.Widget ( Message(..) + , Widget(..) , WidgetClass(..) , WidgetState(..) , separator @@ -14,6 +15,8 @@ import Data.Traversable import Graphics.Rendering.Cairo +import Phi.Phi + class Show a => WidgetClass a where type WidgetData a :: * @@ -29,6 +32,9 @@ class Show a => WidgetClass a where layout _ priv _ _ = priv render :: a -> WidgetData a -> Int -> Int -> Render () + + handleMessage :: a -> WidgetData a -> Message -> WidgetData a + handleMessage _ priv _ = priv data Widget = forall a. (WidgetClass a, Show (WidgetData a)) => Widget a deriving instance Show Widget @@ -67,7 +73,7 @@ layoutWidgets widgets x y width height = snd $ mapAccumL layoutWidgetAndX x widg WidgetState {stateWidget = w, statePrivateData = priv} -> let wWidth = floor $ (fromIntegral $ minSize w) + (fromIntegral surplus)*(nneg $ weight w)/wsum priv' = layout w priv wWidth height - in WidgetState { stateWidget = w, stateX = wX, stateY = y, stateWidth = wWidth, stateHeight = height, statePrivateData = priv' } + in WidgetState w wX y wWidth height priv' nneg :: (Num a, Ord a) => a -> a nneg x = max 0 x @@ -84,6 +90,10 @@ renderWidgets widgets = forM_ widgets $ \WidgetState { stateWidget = widget render widget priv w h restore +handleMessageWidgets :: Message -> [WidgetState] -> [WidgetState] +handleMessageWidgets message = map handleMessageWidget + where + handleMessageWidget (WidgetState w x y width height priv) = WidgetState w x y width height $ handleMessage w priv message data Separator = Separator Int Float deriving Show -- cgit v1.2.3