Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module provides the core widget combinators and rendering routines. Everything this library does is in terms of these basic primitives.
- emptyWidget :: Widget
- raw :: Image -> Widget
- txt :: Text -> Widget
- str :: String -> Widget
- fill :: Char -> Widget
- padLeft :: Padding -> Widget -> Widget
- padRight :: Padding -> Widget -> Widget
- padTop :: Padding -> Widget -> Widget
- padBottom :: Padding -> Widget -> Widget
- padLeftRight :: Int -> Widget -> Widget
- padTopBottom :: Int -> Widget -> Widget
- padAll :: Int -> Widget -> Widget
- (<=>) :: Widget -> Widget -> Widget
- (<+>) :: Widget -> Widget -> Widget
- hBox :: [Widget] -> Widget
- vBox :: [Widget] -> Widget
- hLimit :: Int -> Widget -> Widget
- vLimit :: Int -> Widget -> Widget
- withDefAttr :: AttrName -> Widget -> Widget
- withAttr :: AttrName -> Widget -> Widget
- forceAttr :: AttrName -> Widget -> Widget
- updateAttrMap :: (AttrMap -> AttrMap) -> Widget -> Widget
- withBorderStyle :: BorderStyle -> Widget -> Widget
- showCursor :: Name -> Location -> Widget -> Widget
- translateBy :: Location -> Widget -> Widget
- cropLeftBy :: Int -> Widget -> Widget
- cropRightBy :: Int -> Widget -> Widget
- cropTopBy :: Int -> Widget -> Widget
- cropBottomBy :: Int -> Widget -> Widget
- viewport :: Name -> ViewportType -> Widget -> Widget
- visible :: Widget -> Widget
- visibleRegion :: Location -> DisplayRegion -> Widget -> Widget
- unsafeLookupViewport :: Name -> RenderM (Maybe Viewport)
- addResultOffset :: Location -> Result -> Result
- cropToContext :: Widget -> Widget
Basic rendering primitives
The empty widget.
str :: String -> Widget Source
Build a widget from a String
. Breaks newlines up and space-pads
short lines out to the length of the longest line.
Fill all available space with the specified character. Grows both horizontally and vertically.
Padding
padLeft :: Padding -> Widget -> Widget Source
Pad the specified widget on the left. If max padding is used, this grows greedily horizontally; otherwise it defers to the padded widget.
padRight :: Padding -> Widget -> Widget Source
Pad the specified widget on the right. If max padding is used, this grows greedily horizontally; otherwise it defers to the padded widget.
padTop :: Padding -> Widget -> Widget Source
Pad the specified widget on the top. If max padding is used, this grows greedily vertically; otherwise it defers to the padded widget.
padBottom :: Padding -> Widget -> Widget Source
Pad the specified widget on the bottom. If max padding is used, this grows greedily vertically; otherwise it defers to the padded widget.
padLeftRight :: Int -> Widget -> Widget Source
Pad a widget on the left and right. Defers to the padded widget for growth policy.
padTopBottom :: Int -> Widget -> Widget Source
Pad a widget on the top and bottom. Defers to the padded widget for growth policy.
padAll :: Int -> Widget -> Widget Source
Pad a widget on all sides. Defers to the padded widget for growth policy.
Box layout
Vertical box layout: put the specified widgets one above the other
in the specified order. Defers growth policies to the growth policies
of both widgets. This operator is a binary version of vBox
.
Horizontal box layout: put the specified widgets next to each other
in the specified order. Defers growth policies to the growth policies
of both widgets. This operator is a binary version of hBox
.
hBox :: [Widget] -> Widget Source
Horizontal box layout: put the specified widgets next to each other in the specified order (leftmost first). Defers growth policies to the growth policies of the contained widgets (if any are greedy, so is the box).
vBox :: [Widget] -> Widget Source
Vertical box layout: put the specified widgets one above the other in the specified order (uppermost first). Defers growth policies to the growth policies of the contained widgets (if any are greedy, so is the box).
Limits
hLimit :: Int -> Widget -> Widget Source
Limit the space available to the specified widget to the specified number of columns. This is important for constraining the horizontal growth of otherwise-greedy widgets. This is non-greedy horizontally and defers to the limited widget vertically.
vLimit :: Int -> Widget -> Widget Source
Limit the space available to the specified widget to the specified number of rows. This is important for constraining the vertical growth of otherwise-greedy widgets. This is non-greedy vertically and defers to the limited widget horizontally.
Attribute management
withDefAttr :: AttrName -> Widget -> Widget Source
Update the attribute map while rendering the specified widget: set its new default attribute to the one that we get by looking up the specified attribute name in the map.
withAttr :: AttrName -> Widget -> Widget Source
When drawing the specified widget, set the current attribute used
for drawing to the one with the specified name. Note that the widget
may use further calls to withAttr
to override this; if you really
want to prevent that, use forceAttr
. Attributes used this way still
get merged hierarchically and still fall back to the attribute map's
default attribute. If you want to change the default attribute, use
withDefAttr
.
forceAttr :: AttrName -> Widget -> Widget Source
When rendering the specified widget, force all attribute lookups in the attribute map to use the value currently assigned to the specified attribute name.
updateAttrMap :: (AttrMap -> AttrMap) -> Widget -> Widget Source
When rendering the specified widget, update the attribute map with the specified transformation.
Border style management
withBorderStyle :: BorderStyle -> Widget -> Widget Source
When rendering the specified widget, use the specified border style for any border rendering.
Cursor placement
showCursor :: Name -> Location -> Widget -> Widget Source
When rendering the specified widget, also register a cursor positioning request using the specified name and location.
Translation
translateBy :: Location -> Widget -> Widget Source
Translate the specified widget by the specified offset amount. Defers to the translated width for growth policy.
Cropping
cropLeftBy :: Int -> Widget -> Widget Source
Crop the specified widget on the left by the specified number of columns. Defers to the translated width for growth policy.
cropRightBy :: Int -> Widget -> Widget Source
Crop the specified widget on the right by the specified number of columns. Defers to the translated width for growth policy.
cropTopBy :: Int -> Widget -> Widget Source
Crop the specified widget on the top by the specified number of rows. Defers to the translated width for growth policy.
cropBottomBy :: Int -> Widget -> Widget Source
Crop the specified widget on the bottom by the specified number of rows. Defers to the translated width for growth policy.
Scrollable viewports
:: Name | The name of the viewport (must be unique and stable for reliable behavior) |
-> ViewportType | The type of viewport (indicates the permitted scrolling direction) |
-> Widget | The widget to be rendered in the scrollable viewport |
-> Widget |
Render the specified widget in a named viewport with the
specified type. This permits widgets to be scrolled without being
scrolling-aware. To make the most use of viewports, the specified
widget should use the visible
combinator to make a "visibility
request". This viewport combinator will then translate the resulting
rendering to make the requested region visible. In addition, the
EventM
monad provides primitives to scroll viewports
created by this function if visible
is not what you want.
If a viewport receives more than one visibility request, only the
first is honored. If a viewport receives more than one scrolling
request from EventM
, all are honored in the order in
which they are received.
visible :: Widget -> Widget Source
Request that the specified widget be made visible when it is
rendered inside a viewport. This permits widgets (whose sizes and
positions cannot be known due to being embedded in arbitrary layouts)
to make a request for a parent viewport to locate them and scroll
enough to put them in view. This, together with viewport
, is what
makes the text editor and list widgets possible without making them
deal with the details of scrolling state management.
This does nothing if not rendered in a viewport.
visibleRegion :: Location -> DisplayRegion -> Widget -> Widget Source
Similar to visible
, request that a region (with the specified
Location
as its origin and DisplayRegion
as its size) be made
visible when it is rendered inside a viewport. The Location
is
relative to the specified widget's upper-left corner of (0, 0).
This does nothing if not rendered in a viewport.
unsafeLookupViewport :: Name -> RenderM (Maybe Viewport) Source
Given a name, obtain the viewport for that name by consulting the viewport map in the rendering monad. NOTE! Some care must be taken when calling this function, since it only returns useful values after the viewport in question has been rendered. If you call this function during rendering before a viewport has been rendered, you may get nothing or you may get a stale version of the viewport. This is because viewports are updated during rendering and the one you are interested in may not have been rendered yet. So if you want to use this, be sure you know what you are doing.
Adding offsets to cursor positions and visibility requests
addResultOffset :: Location -> Result -> Result Source
Add an offset to all cursor locations and visbility requests in the specified rendering result. This function is critical for maintaining correctness in the rendering results as they are processed successively by box layouts and other wrapping combinators, since calls to this function result in converting from widget-local coordinates to (ultimately) terminal-global ones so they can be used by other combinators. You should call this any time you render something and then translate it or otherwise offset it from its original origin.
Cropping results
cropToContext :: Widget -> Widget Source
After rendering the specified widget, crop its result image to the dimensions in the rendering context.