Stability | experimental |
---|---|
Maintainer | dwc@cs.yale.edu |
Safe Haskell | None |
A simple Graphical User Interface with concepts borrowed from Phooey by Conal Elliot.
- newtype UI a = UI {}
- ioToUI :: IO a -> UI a
- type ControlData = [ThreadId]
- nullCD :: ControlData
- addThreadID :: ThreadId -> UI ()
- mergeCD :: ControlData -> ControlData -> ControlData
- data CTX = CTX {}
- data Flow
- type Dimension = (Int, Int)
- type Rect = (Point, Dimension)
- data Layout = Layout {}
- data LayoutType
- makeLayout :: LayoutType -> LayoutType -> Layout
- nullLayout :: Layout
- divideCTX :: CTX -> Layout -> Layout -> (CTX, CTX)
- mergeLayout :: Flow -> Layout -> Layout -> Layout
- type Action = (Graphic, Sound)
- type Sound = IO ()
- nullSound :: Sound
- nullAction :: Action
- justSoundAction :: Sound -> Action
- justGraphicAction :: Graphic -> Action
- mergeAction :: Monad m => (Graphic, m a) -> (Graphic, m b) -> (Graphic, m b)
- scissorAction :: CTX -> Action -> Action
- type Focus = (WidgetID, FocusInfo)
- type WidgetID = Int
- data FocusInfo
- = HasFocus
- | NoFocus
- | SetFocusTo WidgetID
- type DirtyBit = Bool
UI Type Definition
A UI widget runs under a given context and any focus information from earlier widgets and maps input signals to outputs, which consists of 6 parts:
- its layout,
- whether the widget needs to be redrawn,
- any focus information that needs to be conveyed to future widgets
- the action (to render graphics or/and sounds),
- any new ThreadIds to keep track of (for proper shutdown when finished),
- and the parametrized output type.
Control Data
type ControlData = [ThreadId]Source
The control data is simply a list of Thread Ids.
No new thread ids.
addThreadID :: ThreadId -> UI ()Source
A thread handler for the UI monad.
mergeCD :: ControlData -> ControlData -> ControlDataSource
A method for merging to control data objects.
Rendering Context
A rendering context specifies the following:
CTX | |
|
Flow determines widget ordering.
UI Layout
The layout of a widget provides data to calculate its actual size in a given context.
- hFill/vFill specify how much stretching space (in units) in horizontal/vertical direction should be allocated for this widget.
- hFixedvFixed specify how much non-stretching space (widthheight in pixels) should be allocated for this widget.
- minWminH specify minimum values (widthheight in pixels) for the widget's dimensions.
data LayoutType Source
A dimension can either be:
makeLayout :: LayoutType -> LayoutType -> LayoutSource
This function takes layout information for first the horizontal dimension and then the vertical.
The null layout is useful for "widgets" that do not appear or take up space on the screen.
Context and Layout Functions
divideCTX :: CTX -> Layout -> Layout -> (CTX, CTX)Source
Divides the CTX according to the ratio of a widget's layout and the overall layout of the widget that receives this CTX. Therefore, the first layout argument should basically be a sublayout of the second.
Action and System State
type Action = (Graphic, Sound)Source
Actions include both Graphics and Sound output. Even though both are indeed just IO monads, we separate them because Sound output must be immediately delivered, while graphics can wait until the next screen refresh.
This is used when no Action happens at all.
justSoundAction :: Sound -> ActionSource
Convert a Sound to an Action with no Graphic.
justGraphicAction :: Graphic -> ActionSource
Convert a Graphic to an Action with no Sound.
mergeAction :: Monad m => (Graphic, m a) -> (Graphic, m b) -> (Graphic, m b)Source
Merge two actions into one.
scissorAction :: CTX -> Action -> ActionSource
Use a context to bound the graphical effects of an action.
type Focus = (WidgetID, FocusInfo)Source
The Focus type helps focusable widgets communicate with each other about which widget is in focus. It consists of a WidgetID and a FocusInfo.
The WidgetID for any given widget is dynamic based on how many focusable widgets are active at the moment. It is designed basically as a counter that focusable widgets will automatically (via the focusable function) increment.
The FocusInfo means one of the following:
HasFocus | Indicates that this widget is a subwidget of a widget that is in focus. Thus, this widget too is in focus, and this widget should pass HasFocus forward. |
NoFocus | Indicates that there is no focus information to communicate between widgets. |
SetFocusTo WidgetID | Indicates that the widget whose id is given should take focus. That widget should then pass NoFocus onward. |