UISF-0.3.0.2: Library for Arrowized Graphical User Interfaces.

Copyright(c) Daniel Winograd-Cort 2014
Licensesee the LICENSE file in the distribution
Maintainerdwc@cs.yale.edu
Stabilityexperimental
Safe HaskellNone
LanguageHaskell98

FRP.UISF.UITypes

Contents

Description

 

Synopsis

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

data CTX Source

A rendering context specifies the following:

Constructors

CTX 

Fields

flow :: Flow

A layout direction to flow widgets.

bounds :: Rect

A rectangle bound of current drawing area to render a UI component. It specifies the max size of a widget, not the actual size. It's up to each individual widget to decide where in this bound to put itself.

isConjoined :: Bool

A flag to tell whether we are in a conjoined state or not. A conjoined context will duplicate itself for subcomponents rather than splitting. This can be useful for making compound widgets when one widget takes up space and the other performs some side effect having to do with that space.

Instances

data Flow Source

Flow determines widget ordering.

Instances

type Dimension = (Int, Int) Source

A dimension specifies size.

type Rect = (Point, Dimension) Source

A rectangle has a corner point and a dimension.

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.

makeLayout Source

Arguments

:: 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:

Constructors

Stretchy

Stretchy with a minimum size in pixels

Fields

minSize :: Int
 
Fixed

Fixed with a size measured in pixels

Fields

fixedSize :: Int
 

nullLayout :: Layout Source

The null layout is useful for "widgets" that do not appear or take up space on the screen.

data Layout Source

More complicated layouts can be manually constructed with direct access to the Layout data type.

  1. hFill and vFill specify how much stretching space (in comparative units) in the horizontal and vertical directions should be allocated for this widget.
  2. hFixed and vFixed specify how much non-stretching space (in pixels) of width and height should be allocated for this widget.
  3. minW and minH specify minimum values (in pixels) of width and height for the widget's stretchy dimensions.

Constructors

Layout 

Fields

hFill :: Int
 
vFill :: Int
 
hFixed :: Int
 
vFixed :: Int
 
minW :: Int
 
minH :: Int
 

Instances

Context and Layout Functions

divideCTX :: CTX -> Layout -> Layout -> (CTX, CTX) Source

Divides the CTX among the two given layouts.

mergeLayout :: Flow -> Layout -> Layout -> Layout Source

Merge two layouts into one.

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 DirtyBit = Bool Source

The dirty bit is a bit to indicate if the widget needs to be redrawn.

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.

type WidgetID = Int Source

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.

data FocusInfo Source

The FocusInfo means one of the following:

Constructors

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.