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.
- class TextWidth a where
- emptyWidget :: Widget n
- raw :: Image -> Widget n
- txt :: Text -> Widget n
- str :: String -> Widget n
- fill :: Char -> Widget n
- padLeft :: Padding -> Widget n -> Widget n
- padRight :: Padding -> Widget n -> Widget n
- padTop :: Padding -> Widget n -> Widget n
- padBottom :: Padding -> Widget n -> Widget n
- padLeftRight :: Int -> Widget n -> Widget n
- padTopBottom :: Int -> Widget n -> Widget n
- padAll :: Int -> Widget n -> Widget n
- (<=>) :: Widget n -> Widget n -> Widget n
- (<+>) :: Widget n -> Widget n -> Widget n
- hBox :: [Widget n] -> Widget n
- vBox :: [Widget n] -> Widget n
- hLimit :: Int -> Widget n -> Widget n
- vLimit :: Int -> Widget n -> Widget n
- withDefAttr :: AttrName -> Widget n -> Widget n
- withAttr :: AttrName -> Widget n -> Widget n
- forceAttr :: AttrName -> Widget n -> Widget n
- overrideAttr :: AttrName -> AttrName -> Widget n -> Widget n
- updateAttrMap :: (AttrMap -> AttrMap) -> Widget n -> Widget n
- withBorderStyle :: BorderStyle -> Widget n -> Widget n
- showCursor :: n -> Location -> Widget n -> Widget n
- class Named a n where
- translateBy :: Location -> Widget n -> Widget n
- cropLeftBy :: Int -> Widget n -> Widget n
- cropRightBy :: Int -> Widget n -> Widget n
- cropTopBy :: Int -> Widget n -> Widget n
- cropBottomBy :: Int -> Widget n -> Widget n
- reportExtent :: n -> Widget n -> Widget n
- clickable :: n -> Widget n -> Widget n
- viewport :: (Ord n, Show n) => n -> ViewportType -> Widget n -> Widget n
- visible :: Widget n -> Widget n
- visibleRegion :: Location -> DisplayRegion -> Widget n -> Widget n
- unsafeLookupViewport :: Ord n => n -> RenderM n (Maybe Viewport)
- cached :: Ord n => n -> Widget n -> Widget n
- addResultOffset :: Location -> Result n -> Result n
- cropToContext :: Widget n -> Widget n
Basic rendering primitives
emptyWidget :: Widget n Source #
The empty widget.
str :: String -> Widget n Source #
Build a widget from a String
. Breaks newlines up and space-pads
short lines out to the length of the longest line.
fill :: Char -> Widget n Source #
Fill all available space with the specified character. Grows both horizontally and vertically.
Padding
padLeft :: Padding -> Widget n -> Widget n 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 n -> Widget n 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 n -> Widget n 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 n -> Widget n 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 n -> Widget n Source #
Pad a widget on the left and right. Defers to the padded widget for growth policy.
padTopBottom :: Int -> Widget n -> Widget n Source #
Pad a widget on the top and bottom. Defers to the padded widget for growth policy.
padAll :: Int -> Widget n -> Widget n 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 n] -> Widget n 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 n] -> Widget n 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 n -> Widget n 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 n -> Widget n 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 n -> Widget n 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 n -> Widget n 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 n -> Widget n 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.
overrideAttr :: AttrName -> AttrName -> Widget n -> Widget n Source #
Override the lookup of targetName
to return the attribute value
associated with fromName
when rendering the specified widget.
See also mapAttrName
.
updateAttrMap :: (AttrMap -> AttrMap) -> Widget n -> Widget n Source #
When rendering the specified widget, update the attribute map with the specified transformation.
Border style management
withBorderStyle :: BorderStyle -> Widget n -> Widget n Source #
When rendering the specified widget, use the specified border style for any border rendering.
Cursor placement
showCursor :: n -> Location -> Widget n -> Widget n Source #
When rendering the specified widget, also register a cursor positioning request using the specified name and location.
Naming
Translation
translateBy :: Location -> Widget n -> Widget n Source #
Translate the specified widget by the specified offset amount. Defers to the translated widget for growth policy.
Cropping
cropLeftBy :: Int -> Widget n -> Widget n Source #
Crop the specified widget on the left by the specified number of columns. Defers to the cropped widget for growth policy.
cropRightBy :: Int -> Widget n -> Widget n Source #
Crop the specified widget on the right by the specified number of columns. Defers to the cropped widget for growth policy.
cropTopBy :: Int -> Widget n -> Widget n Source #
Crop the specified widget on the top by the specified number of rows. Defers to the cropped widget for growth policy.
cropBottomBy :: Int -> Widget n -> Widget n Source #
Crop the specified widget on the bottom by the specified number of rows. Defers to the cropped widget for growth policy.
Extent reporting
reportExtent :: n -> Widget n -> Widget n Source #
Render the specified widget and record its rendering extent using
the specified name (see also lookupExtent
).
Scrollable viewports
:: (Ord n, Show n) | |
=> n | The name of the viewport (must be unique and stable for reliable behavior) |
-> ViewportType | The type of viewport (indicates the permitted scrolling direction) |
-> Widget n | The widget to be rendered in the scrollable viewport |
-> Widget n |
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, then the
visibility requests are merged with the inner visibility request
taking preference. If a viewport receives more than one scrolling
request from EventM
, all are honored in the order in
which they are received.
visible :: Widget n -> Widget n 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 n -> Widget n 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 :: Ord n => n -> RenderM n (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.
cached :: Ord n => n -> Widget n -> Widget n Source #
Render the specified widget. If the widget has an entry in the rendering cache using the specified name as the cache key, use the rendered version from the cache instead. If not, render the widget and update the cache.
See also invalidateCacheEntry
.
Adding offsets to cursor positions and visibility requests
addResultOffset :: Location -> Result n -> Result n Source #
Add an offset to all cursor locations, visbility requests, and extents 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 n -> Widget n Source #
After rendering the specified widget, crop its result image to the dimensions in the rendering context.