Copyright | (c) Daniel Winograd-Cort 2015 |
---|---|
License | see the LICENSE file in the distribution |
Maintainer | dwc@cs.yale.edu |
Stability | experimental |
Safe Haskell | None |
Language | Haskell98 |
This module provides functions and utilities that help in the construction of new widgets. They are used by FRP.UISF.Widget, and can be used for any custom widgets as well.
- padding :: Int
- bg :: Color
- (//) :: Graphic -> Graphic -> Graphic
- whenG :: Bool -> Graphic -> Graphic
- inside :: Point -> Rect -> Bool
- mkWidget :: s -> Layout -> (a -> s -> Rect -> UIEvent -> (b, s, DirtyBit)) -> (Rect -> Bool -> s -> Graphic) -> UISF a b
- mkBasicWidget :: Layout -> (Rect -> Graphic) -> UISF a a
- toggle :: Eq s => s -> Layout -> (Rect -> Bool -> s -> Graphic) -> UISF s Bool
- mkSlider :: Eq a => Bool -> (a -> Int -> Int) -> (Int -> Int -> a) -> (Int -> Int -> a -> a) -> a -> UISF (SEvent a) a
- cyclebox :: Layout -> [(Rect -> Bool -> Graphic, b)] -> Int -> UISF () b
- cycleboxS :: Layout -> [(Rect -> Bool -> Graphic, b)] -> Int -> UISF (SEvent Int) b
- focusable :: UISF a b -> UISF a b
- isInFocus :: UISF () Bool
- shadowBox :: (Color, Color, Color, Color) -> Rect -> Graphic
- pushed :: (Color, Color, Color, Color)
- marked :: (Color, Color, Color, Color)
- popped :: (Color, Color, Color, Color)
Documentation
whenG :: Bool -> Graphic -> Graphic Source
A nice way to make a graphic under only certain conditions.
Widget Builders
:: s | initial state |
-> Layout | layout |
-> (a -> s -> Rect -> UIEvent -> (b, s, DirtyBit)) | computation |
-> (Rect -> Bool -> s -> Graphic) | drawing routine |
-> UISF a b |
mkWidget is a helper function to make stateful widgets easier to write. In essence, it breaks down the idea of a widget into 4 constituent components: state, layout, computation, and drawing.
As mkWidget
allows for making stateful widgets, the first parameter is
simply the initial state.
The layout is the static layout that this widget will use. It
cannot be dependent on any streaming arguments, but a layout can have
"stretchy" sides so that it can expand/shrink to fit an area. Learn
more about making layouts in UIType
s UI Layout section -- specifically,
check out the makeLayout
function and the LayoutType
data type.
The computation is where the logic of the widget is held. This
function takes as input the streaming argument a, the widget's state,
a Rect of coordinates indicating the area that has been allotted for
this widget, and the UIEvent
that is triggering this widget's activation
(see the definition of UIEvent
in SOE). The output consists of the
streaming output, the new state, and the dirty bit, which represents
whether the widget needs to be redrawn.
Lastly, the drawing routine takes the same Rect as the computation, a Bool that is true when this widget is in focus and false otherwise, and the current state of the widget (technically, this state is the one freshly returned from the computation). Its output is the Graphic that this widget should display.
Occasionally, one may want to display a non-interactive graphic in
the UI. mkBasicWidget
facilitates this. It takes a layout and a
simple drawing routine and produces a non-interacting widget.
:: Eq s | |
=> s | Initial state value |
-> Layout | The layout for the toggle |
-> (Rect -> Bool -> s -> Graphic) | The drawing routine |
-> UISF s Bool |
The toggle is useful in the creation of both checkbox
es and radio
buttons. It displays on/off according to its input, and when the mouse
is clicked on it, it will output True (otherwise it outputs False).
The UISF returned from a call to toggle accepts the state stream and returns whether the toggle is being clicked.
:: Eq a | |
=> Bool | True for horizontal, False for vertical |
-> (a -> Int -> Int) | A function for converting a value to a position |
-> (Int -> Int -> a) | A function for converting a position to a value |
-> (Int -> Int -> a -> a) | A function for determining how much to jump when a click is on the slider but not the target |
-> a | The initial value for the slider |
-> UISF (SEvent a) a |
The mkSlider widget builder is useful in the creation of all sliders.
cyclebox :: Layout -> [(Rect -> Bool -> Graphic, b)] -> Int -> UISF () b Source
cyclebox is a clickable widget that cycles through a predefined set set of appearances/output values.
cycleboxS :: Layout -> [(Rect -> Bool -> Graphic, b)] -> Int -> UISF (SEvent Int) b Source
cycleboxS is a cyclebox that additionally accepts input events that can set it to a particular appearance/output.
Focus
Any widget that wants to accept mouse button clicks or keystrokes must be focusable. The focusable function below achieves this.
focusable :: UISF a b -> UISF a b Source
Making a widget focusable makes it accessible to tabbing and allows it to see any mouse button clicks and keystrokes when it is actually in focus.
isInFocus :: UISF () Bool Source
Although mouse button clicks and keystrokes will be available once a widget marks itself as focusable, the widget may also simply want to know whether it is currently in focus to change its appearance. This can be achieved with the following signal function.