vty-ui-0.2: A user interface composition library for VtySource codeContentsIndex
Graphics.Vty.Widgets.Base
Description

A collection of primitive user interface widgets for composing and laying out Graphics.Vty user interfaces. This module provides basic static and box layout widgets and a type class for rendering widgets to Vty Images.

Each widget type supplied by this library is exported as a type and an associated constructor function (e.g., Text and text, Box and vBox / hBox).

Synopsis
class Widget w where
render :: DisplayRegion -> w -> Image
growHorizontal :: w -> Bool
growVertical :: w -> Bool
primaryAttribute :: w -> Attr
withAttribute :: w -> Attr -> w
mkImage :: Widget a => Vty -> a -> IO Image
data AnyWidget
data Text
data Box
data Fill
(<++>) :: (Widget a, Widget b) => a -> b -> Box
(<-->) :: (Widget a, Widget b) => a -> b -> Box
anyWidget :: Widget a => a -> AnyWidget
text :: Attr -> String -> Text
hBox :: (Widget a, Widget b) => a -> b -> Box
vBox :: (Widget a, Widget b) => a -> b -> Box
hFill :: Attr -> Char -> Int -> Fill
vFill :: Attr -> Char -> Fill
Documentation
class Widget w whereSource
The class of user interface widgets. Note that the growth properties growHorizontal and growVertical are used to control rendering order; if a widget can grow to fill available space, then neighboring fixed-size widgets will be rendered first so remaining space can be computed. Then, variable-sized (growable) widgets will be rendered last to consume that space.
Methods
render :: DisplayRegion -> w -> ImageSource
Given a widget, render it with the given dimensions. The resulting Image should not be larger than the specified dimensions, but may be smaller.
growHorizontal :: w -> BoolSource
Will this widget expand to take advantage of available horizontal space?
growVertical :: w -> BoolSource
Will this widget expand to take advantage of available vertical space?
primaryAttribute :: w -> AttrSource
The primary attribute of this widget, used when composing widgets. For example, if you want to compose a widget A with a space-filling widget B, you probably want B's text attributes to be identical to those of A.
withAttribute :: w -> Attr -> wSource
Apply the specified attribute to this widget.
show/hide Instances
mkImage :: Widget a => Vty -> a -> IO ImageSource
Given a Widget and a Vty object, render the widget using the current size of the terminal controlled by Vty. Returns the rendered Widget as an Image.
data AnyWidget Source
A wrapper for all widget types used in normalizing heterogeneous lists of widgets. See anyWidget.
show/hide Instances
data Text Source
A text widget consisting of a string rendered using an attribute. See text.
show/hide Instances
data Box Source

A box layout widget capable of containing two Widgets horizontally or vertically. See hBox and vBox. Boxes lay out their children as follows:

  • If both children are expandable in the same dimension (i.e., both vertically or both horizontally), the children are each given half of the parent container's available space
  • If one of the children is expandable and the other is static, the static child is rendered first and the remaining space is given to the expandable child
  • Otherwise, both children are rendered in top-to-bottom or left-to-right order and the resulting container uses only as much space as its children combined
show/hide Instances
data Fill Source
A fill widget for filling available vertical or horizontal space in a box layout. See vFill and hFill.
show/hide Instances
(<++>) :: (Widget a, Widget b) => a -> b -> BoxSource
An alias for hBox intended as sugar to chain widgets horizontally.
(<-->) :: (Widget a, Widget b) => a -> b -> BoxSource
An alias for vBox intended as sugar to chain widgets vertically.
anyWidget :: Widget a => a -> AnyWidgetSource
Wrap a Widget in the AnyWidget type for normalization purposes.
textSource
:: AttrThe attribute to use to render the text
-> StringThe text to display
-> Text
Create a Text widget.
hBoxSource
:: (Widget a, Widget b)
=> aThe left widget
-> bThe right widget
-> Box
Create a horizontal box layout widget containing two widgets side by side. Space consumed by the box will depend on its contents and the available space.
vBoxSource
:: (Widget a, Widget b)
=> aThe top widget
-> bThe bottom widget
-> Box
Create a vertical box layout widget containing two widgets. Space consumed by the box will depend on its contents and the available space.
hFillSource
:: AttrThe attribute to use to render the fill
-> CharThe character to fill
-> IntThe height, in rows, of the filled area; width of the fill depends on available space
-> Fill
Create an horizonal fill widget.
vFillSource
:: AttrThe attribute to use to render the fill
-> CharThe character to fill
-> Fill
Create a vertical fill widget. The dimensions of the widget will depend on available space.
Produced by Haddock version 2.4.2