-
Notifications
You must be signed in to change notification settings - Fork 0
/
Types.hs
52 lines (39 loc) · 1.37 KB
/
Types.hs
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
44
45
46
47
48
49
50
51
52
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Hate.UI.Types where
import Hate.Fonts
import Hate.Graphics
import Hate.Math
import Control.Monad.State
data UIBase = UIBase {
uiFont :: Font
}
-- The s type is the ultimate type of state the UI can see
-- in other words, it can do only operations on s, and its
-- subcomponents can do operations on subparts on s
data UI s = UI {
base :: UIBase,
root :: AnyElement s
}
-- |This is an equivalent of the state monad, but tailored for the UI.
-- We'll see how useful this approach is.
class HasUI s where
getUI :: s -> UI s
putUI :: UI s -> s -> s
-- |Represents a binding to a type of value a inside of state s
data Binding s a = PlainValue a | Binding (s -> a)
type Effect s = s -> s
type SelfEffect s a = (Effect s, a)
class Element s a where
drawElement :: UIBase -> s -> a -> [DrawRequest]
click :: Vec2 -> a -> SelfEffect s a
click _ x = (id, x)
data AnyElement s = forall e. Element s e => AnyElement e
instance Element s (AnyElement s) where
drawElement ub s (AnyElement e) = drawElement ub s e
click mp (AnyElement (e :: e)) = (sE, AnyElement selfE)
where
(sE, selfE) = (click mp e :: SelfEffect s e)