This module provides functionality for rendering String
s as
Widget
s, including functionality to make structural and/or visual
changes at rendering time. To get started, turn your ordinary
String
into a Widget
with simpleText
; if you want access to
the Text
for formatting purposes, use prepareText
followed by
textWidget
.
Documentation
type Formatter = DisplayRegion -> Text -> TextSource
A formatter makes changes to text at rendering time.
It'd be nice if formatters were just ::
, but
some formatting use cases involve knowing the size of the rendering
area, which is not known until render time (e.g., text wrapping).
Thus, a formatter takes a Text
-> Text
DisplayRegion
and runs at render time.
Text Preparation
prepareText :: Attr -> String -> TextSource
Prepare a string for rendering and assign it the specified default attribute.
Constructing Widgets
simpleText :: Attr -> String -> WidgetSource
Construct a Widget directly from an attribute and a String. This
is recommended if you don't need to use a Formatter
.
textWidget :: Formatter -> Text -> WidgetSource
Construct a text widget formatted with the specified formatters. the formatters will be applied in the order given here, so be aware of how the formatters will modify the text (and affect each other).
Formatting
(&.&) :: Formatter -> Formatter -> FormatterSource
Formatter composition: a &.& b
applies a
followed by b
.