This module contains a set of data types and definitions of functions that are used in the other modules.
General type constructors for composing context-independent data structures.
infixr 9 :^: data Tup t1 t2 = t1 :^: t2
General type constructors for composing context-dependent data structures.
infixr 9 :~: data TupSt t1 t2 ps = (t1 ps) :~: (t2 ps) data ListCS t ps = ListCS [t ps] data NilCS ps = NilCS
General type constructors for composing local and context-dependent data structures.
infixr 9 :+: data TupLS t1 t2 ls ps = (t1 ls ps) :+: (t2 ls ps) data ListLS t ls ps = ListLS [t ls ps] data NilLS ls ps = NilLS data NewLS t ls ps = forall new . NewLS new (t new ps) data AddLS t ls ps = forall add . AddLS add (t (add,ls) ps)
data SelectState = Able | Unable deriving (Eq,Show) enabled :: SelectState -> Bool
SelectState is similar to Bool but it shows whether an object is enabled or disabled.
data MarkState = Mark | NoMark deriving (Eq,Show) marked :: MarkState -> Bool
MarkState is similar to Bool but it shows whether the
CheckControl
is marked.
class Toggle a where toggle :: a -> a
toggle
is a polymorphic version of
not
. There are
instance Toggle Bool -- toggle b = not b instance Toggle SelectState instance Toggle MarkState
Other type classes
class Zero a where zero :: a class One a where one :: a
There are instances for Zero and One for some of the following types.
type Index = Int type Title = String
data Vector2 = Vector2 {vx :: !Int, vy :: !Int} deriving (Eq,Show) instance Zero Vector2 where instance Num Vector2 where
Note that (*), abs, signum and fromInteger members of Num instance are undefined!!
class ToVector x where toVector :: x -> Vector2
ToVector allow coercion between Vector2 and Size and Point2 types.
data Size = Size {w :: !Int, h :: !Int} deriving (Eq,Show) instance Zero Size where -- {w=0,h=0} instance ToVector Size where -- {w,h}->{vx=w,vy=h}
data Point2 = Point2 {x :: !Int, y :: !Int} deriving (Eq,Show) instance Zero Point2 where instance Num Point2 where instance ToVector Point2 where
Note that (*), abs, signum and fromInteger members of Num instance are undefined!!
data Rectangle = Rectangle {corner1 :: !Point2, corner2 :: !Point2} deriving (Eq,Show) instance Zero Rectangle where
rectangleSize :: Rectangle -> Size -- {w=abs (@1.corner1-@1.corner2).x, -- h=abs (@1.corner1-@1.corner2).y} movePoint :: Vector2 -> Point2 -> Point2 -- {vx,vy} {x,y} -> {vx+x,vy+y}
data KeyboardState = CharKey Char KeyState -- ASCII character input | SpecialKey SpecialKey KeyState Modifiers -- Special key input | KeyLost -- Key input lost while key was down deriving (Eq,Show) data KeyState = KeyDown IsRepeatKey -- Key is down | KeyUp -- Key goes up deriving (Eq,Show) type IsRepeatKey -- Flag on key down: = Bool -- True iff key is repeating data Key = IsCharKey Char | IsSpecialKey SpecialKey
KeyboardState is passed to keyboard handler for every keyboard event.
getKeyboardStateKeyState:: KeyboardState -> KeyState
getKeyboardStateKeyState gets KeyState from KeyboardState (KeyUp if KeyboardState is KeyLost)
getKeyboardStateKey :: KeyboardState -> Maybe Key
getKeyboardStateKey gets Key value from KeyboardState (Nothing if KeyboardState is KeyLost)
data MouseState = MouseMove Point2 Modifiers -- Mouse is up (position,modifiers) | MouseDown Point2 Modifiers Int -- Mouse goes down (and nr down) | MouseDrag Point2 Modifiers -- Mouse is down (position,modifiers) | MouseUp Point2 Modifiers -- Mouse goes up (position,modifiers) | MouseLost -- Mouse input lost while mouse was down deriving (Eq, Show) data ButtonState = ButtonStillUp -- MouseMove | ButtonDown -- MouseDown _ _ 1 | ButtonDoubleDown -- _ _ 2 | ButtonTripleDown -- _ _ >2 | ButtonStillDown -- MouseDrag | ButtonUp -- MouseUp/MouseLost deriving (Eq, Show) type MouseStateFilter = -- Predicate on MouseState: MouseState -> Bool -- evaluate MouseFunction only if True
getMouseStatePos :: MouseState -> Point2 getMouseStateModifiers :: MouseState -> Modifiers getMouseStateButtonState:: MouseState -> ButtonState
data SliderState = SliderState { sliderMin :: !Int , sliderMax :: !Int , sliderThumb :: !Int } deriving (Eq, Show)
data UpdateState = UpdateState { oldFrame :: !ViewFrame , newFrame :: !ViewFrame , updArea :: !UpdateArea } deriving (Show) type ViewDomain = Rectangle type ViewFrame = Rectangle type UpdateArea = [ViewFrame]
rectangleToUpdateState :: Rectangle -> UpdateState
viewDomainRange :: ViewDomain viewFrameRange :: ViewFrame
viewDomainRange and viewFrameRange define the minimum and maximum values for ViewDomains and ViewFrames.
data Modifiers = Modifiers { shiftDown :: !Bool -- True iff shift down , optionDown :: !Bool -- True iff option down , commandDown :: !Bool -- True iff command down , controlDown :: !Bool -- True iff control down , altDown :: !Bool -- True iff alt down } deriving (Eq,Show)
Modifiers indicates the meta keys that have been pressed (True) or not (False).
noModifiers, shiftOnly, optionOnly, commandOnly, controlOnly, altOnly :: Modifiers
These are constants that check which of the Modifiers are pressed.
The layout language used for windows and controls.
type ItemPos = ( ItemLoc , ItemOffset ) data ItemLoc -- Absolute: = Fix -- Relative to corner: | LeftTop | RightTop | LeftBottom | RightBottom -- Relative in next line: | Left | Center | Right -- Relative to other item: | LeftOf Id | RightTo Id | Above Id | Below Id -- Relative to previous item: | LeftOfPrev | RightToPrev | AbovePrev | BelowPrev deriving (Eq,Show) type ItemOffset = Vector2 -- A constant offset vector
The Direction type.
data Direction = Horizontal | Vertical deriving Eq
The CursorShape type.
data CursorShape = StandardCursor | BusyCursor | IBeamCursor | CrossCursor | FatCrossCursor | ArrowCursor | HiddenCursor deriving Eq
Document interface of interactive processes.
data DocumentInterface = NDI -- No Document Interface | SDI -- Single Document Interface | MDI -- Multiple Document Interface deriving (Eq,Show)
data SliderMove = SliderIncSmall | SliderDecSmall | SliderIncLarge | SliderDecLarge | SliderThumb Int deriving Show
Common error report types. See throwGUI
data ErrorReport -- Usual cause: = ErrorViolateDI -- Violation against DocumentInterface | ErrorIdsInUse -- Object contains Ids that are bound | ErrorUnknownObject -- Object can not be found | ErrorNotifierOpen -- It was tried to open a second send notifier | ErrorUnableReceiver | ErrorDeadlock | OtherError !String -- Other kind of error deriving (Eq,Show) handleErrorReport :: Monad m => ErrorReport -> m a
handleErrorReport
is a help function
that just calls fail
with an appropriate
error message. It can be used with
catchGUI
. Example:
test1 :: GUI ps x test1 = . . . test :: GUI ps x test = catchGUI test1 handleErrorReport
Note: The Scheduler calls all object callbacks in that way.
Monad extensions
class Monad m => IOMonad m where liftIO :: IO a -> m a instance IOMonad IO where liftIO f = f
IOMonad
class is a simply way to call
IO
monads from other IO
-like
monads.