Copyright | (c) Daniel Winograd-Cort 2014 |
---|---|
License | see the LICENSE file in the distribution |
Maintainer | dwc@cs.yale.edu |
Stability | experimental |
Safe Haskell | None |
Language | Haskell98 |
- type TerminationProc = Maybe (IO ())
- nullTP :: TerminationProc
- mergeTP :: TerminationProc -> TerminationProc -> TerminationProc
- data CTX = CTX {}
- data Flow
- type Dimension = (Int, Int)
- type Rect = (Point, Dimension)
- makeLayout :: LayoutType -> LayoutType -> Layout
- data LayoutType
- nullLayout :: Layout
- data Layout = Layout {}
- divideCTX :: CTX -> Layout -> Layout -> (CTX, CTX)
- mergeLayout :: Flow -> Layout -> Layout -> Layout
- mergeGraphics :: CTX -> (Graphic, Layout) -> (Graphic, Layout) -> Graphic
- type DirtyBit = Bool
- type Focus = (WidgetID, FocusInfo)
- type WidgetID = Int
- data FocusInfo
UI Types
In this module, we will declare the various types to make creating the
overall UI possible. We will discuss the ideas for widgets in some
detail, but for specifics on the type of a widget (the UISF
type),
see the UISF type in FRP.UISF.UISF, and for information on specific
widgets, see FRP.UISF.Widget.
Widgets are arrows that map multiple inputs to multiple outputs. Additionally, they have a relatively static layout argument that, while it can change over time, is not dependent on any of its inputs at any given moment.
On the input end, a widget will accept:
- a graphical context,
- some information about which widget is in focus (for the purposes of routing key presses and mouse clicks and potentially for drawing the widget differently),
- and the current time.
- an event with data relating to UI actions.
On the output end, a widget will produce from these inputs:
- an indicator of whether the widget needs to be redrawn,
- any focus information that needs to be conveyed to future widgets,
- the graphics to render to display this widget,
- and a procedure to run upon termination (for proper shutdown when finished).
Additionally, as widgets are generic arrows, there will be a parameterized input and output types.
Control Data
type TerminationProc = Maybe (IO ()) Source
The termination procedure is simply a potential IO action.
nullTP :: TerminationProc Source
The null termination procedure is no action.
mergeTP :: TerminationProc -> TerminationProc -> TerminationProc Source
A method for merging two termination procedures.
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. Layout calculation makes use of lazy evaluation to do everything in one pass. Although the UI function maps from Context to Layout, all of the fields of Layout must be independent of the Context so that they are avaiable before the UI function is even evaluated.
:: LayoutType | Horizontal Layout information |
-> LayoutType | Vertical Layout information |
-> Layout |
Layouts for individual widgets typically come in a few standard flavors, so we have this convenience function for their creation. This function takes layout information for first the horizontal dimension and then the vertical.
data LayoutType Source
A dimension can either be:
The null layout is useful for "widgets" that do not appear or take up space on the screen.
More complicated layouts can be manually constructed with direct access to the Layout data type.
- hFill and vFill specify how much stretching space (in comparative units) in the horizontal and vertical directions should be allocated for this widget.
- hFixed and vFixed specify how much non-stretching space (in pixels) of width and height should be allocated for this widget.
- minW and minH specify minimum values (in pixels) of width and height for the widget's stretchy dimensions.
Context and Layout Functions
divideCTX :: CTX -> Layout -> Layout -> (CTX, CTX) Source
Divides the CTX among the two given layouts.
Graphics
mergeGraphics :: CTX -> (Graphic, Layout) -> (Graphic, Layout) -> Graphic Source
Merging two graphics can be achieved with overGraphic, but the mergeGraphic function additionally constrains the graphics based on their layouts and the context. TODO: Make sure this works as well as it should
System State
The DirtyBit and Focus types are for system state.
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. |
DenyFocus | Any widget that sees this value should recognize that they are no longer in focus. This is useful for nested focus. |