summaryrefslogtreecommitdiffstats
path: root/lib/Phi/Panel.hs
blob: 42f4f9875a66ad22f84fc7232875261bc96b2f03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
{-# LANGUAGE ExistentialQuantification #-}

module Phi.Panel ( Position(..)
                 , Panel(..)
                 , PanelClass(..)
                 , (<~>)
                 , separator
                 ) where

import Data.Function

data Position = Top | Bottom

class PanelClass a where
  minSize :: a -> Int
  
  weight :: a -> Float
  weight _ = 0

data Panel = forall a. PanelClass a => Panel a

instance PanelClass Panel where
  minSize (Panel p) = minSize p
  weight (Panel p) = weight p

data CompoundPanel = CompoundPanel Panel Panel

instance PanelClass CompoundPanel where
  minSize (CompoundPanel a b) = ((+) `on` minSize) a b
  weight (CompoundPanel a b) = ((+) `on` weight) a b

(<~>) :: Panel -> Panel -> Panel
a <~> b = Panel $ CompoundPanel a b


data Separator = Separator Int Float

instance PanelClass Separator where
  minSize (Separator s _) = s
  weight (Separator _ w) = w

separator :: Int -> Float -> Panel
separator s w = Panel $ Separator s w