HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

  • Packagebrick-2.10
  • Exports81
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceTypes.hs

The Widget type

1 declaration

Location types and lenses

6 declarations
datadata Location
#

A terminal screen location.

Constructors

Instances12Eq, Ord, Read, Show, Generic, Semigroup, …
datadata CursorLocation n
#

A cursor location. These are returned by the rendering process.

Constructors

Instances6Read, Show, Generic, NFData, TerminalLocation, Rep

Viewports

11 declarations
datadata Viewport
#

Describes the state of a viewport as it appears as its most recent rendering.

Constructors

Instances5Read, Show, Generic, NFData, Rep
datadata ViewportType
#

The type of viewports that indicates the direction(s) in which a viewport is scrollable.

Constructors

  • Vertical

    Viewports of this type are scrollable only vertically.

  • Horizontal

    Viewports of this type are scrollable only horizontally.

  • Both

    Viewports of this type are scrollable vertically and horizontally.

Instances2Eq, Show
datadata VScrollbarRenderer n
#

A vertical scroll bar renderer.

Constructors

  • VScrollbarRenderer
    • renderVScrollbar :: Widget n

      How to render the body of the scroll bar. This should provide a widget that expands in whatever direction(s) this renderer will be used for. So, for example, this widget would need to be one that expands vertically such as fill. The same goes for the trough widget.

    • renderVScrollbarTrough :: Widget n

      How to render the "trough" of the scroll bar (the area to either side of the scroll bar body). This should expand as described in the documentation for the scroll bar field.

    • renderVScrollbarHandleBefore :: Widget n

      How to render the handle that appears at the top or left of the scrollbar. The result will be allowed to be at most one row high.

    • renderVScrollbarHandleAfter :: Widget n

      How to render the handle that appears at the bottom or right of the scrollbar. The result will be allowed to be at most one row high.

    • scrollbarWidthAllocation :: Int

      The number of columns that will be allocated to the scroll bar. This determines how much space the widgets of the scroll bar elements can take up. If they use less than this amount, padding will be applied between the scroll bar and the viewport contents.

datadata HScrollbarRenderer n
#

A horizontal scroll bar renderer.

Constructors

  • HScrollbarRenderer
    • renderHScrollbar :: Widget n

      How to render the body of the scroll bar. This should provide a widget that expands in whatever direction(s) this renderer will be used for. So, for example, this widget would need to be one that expands horizontally such as fill. The same goes for the trough widget.

    • renderHScrollbarTrough :: Widget n

      How to render the "trough" of the scroll bar (the area to either side of the scroll bar body). This should expand as described in the documentation for the scroll bar field.

    • renderHScrollbarHandleBefore :: Widget n

      How to render the handle that appears at the top or left of the scrollbar. The result will be allowed to be at most one column wide.

    • renderHScrollbarHandleAfter :: Widget n

      How to render the handle that appears at the bottom or right of the scrollbar. The result will be allowed to be at most one column wide.

    • scrollbarHeightAllocation :: Int

      The number of rows that will be allocated to the scroll bar. This determines how much space the widgets of the scroll bar elements can take up. If they use less than this amount, padding will be applied between the scroll bar and the viewport contents.

Clickable elements of a scroll bar.

Constructors

Instances3Eq, Ord, Show

Event-handling types and functions

4 declarations
newtypenewtype EventM n s a
#

The monad in which event handlers run.

Instances10MonadState, Monad, Functor, Applicative, MonadIO, MonadCatch, …
datadata BrickEvent n e
#

The type of events.

Constructors

  • VtyEvent Event

    The event was a Vty event.

  • AppEvent e

    The event was an application event.

  • MouseDown n Button [Modifier] Location

    A mouse-down event on the specified region was received. The n value is the resource name of the clicked widget (see clickable).

  • MouseUp n (Maybe Button) Location

    A mouse-up event on the specified region was received. The n value is the resource name of the clicked widget (see clickable).

Instances3Eq, Ord, Show
valuenestEventM
  1. :: a

    The initial state to use in the nested action.

  2. -> EventM n a b

    The action to run.

  3. -> EventM n s (a, b)
#

Given a state value and an EventM that mutates that state, run the specified action and return both the resulting modified state and the result of the action itself.

valuenestEventM'
  1. :: a

    The initial state to use in the nested action.

  2. -> EventM n a b

    The action to run.

  3. -> EventM n s a
#

Given a state value and an EventM that mutates that state, run the specified action and return resulting modified state.

Rendering infrastructure

2 declarations
typetype RenderM n a = ReaderT (Context n) (State (RenderState n)) a
#

The type of the rendering monad. This monad is used by the library's rendering routines to manage rendering state and communicate rendering parameters to widgets' rendering functions.

The rendering context

datadata Context n
#

The rendering context. This tells widgets how to render: how much space they have in which to render, which attribute they should use to render, which bordering style should be used, and the attribute map available for rendering.

Rendering results

datadata Result n
#

The type of result returned by a widget's rendering function. The result provides the image, cursor positions, and visibility requests that resulted from the rendering process.

Constructors

Instances5Read, Show, Generic, NFData, Rep
datadata Extent n
#

An extent of a named area: its size, location, and origin.

Instances5Read, Show, Generic, NFData, Rep

Rendering result lenses

Visibility requests

datadata VisibilityRequest
#
Instances6Eq, Read, Show, Generic, NFData, Rep

Making lenses

2 declarations
valuesuffixLenses :: Name -> DecsQ
#

A template haskell function to build lenses for a record type. This function differs from the makeLenses function in that it does not require the record fields to be prefixed with underscores and it adds an L suffix to lens names to make it clear that they are lenses.

Dynamic borders

14 declarations
datadata DynBorder
#

Information about how to redraw a dynamic border character when it abuts another dynamic border character.

Constructors

Instances6Eq, Read, Show, Generic, NFData, Rep
datadata BorderSegment
#

A border character has four segments, one extending in each direction (horizontally and vertically) from the center of the character.

Constructors

  • BorderSegment
    • bsAccept :: Bool

      Would this segment be willing to be drawn if a neighbor wanted to connect to it?

    • bsOffer :: Bool

      Does this segment want to connect to its neighbor?

    • bsDraw :: Bool

      Should this segment be represented visually?

Instances7Eq, Ord, Read, Show, Generic, NFData, …
datadata Edges a
#

Constructors

Instances10Monad, Functor, Applicative, Eq, Ord, Read, …

Miscellaneous

2 declarations
datadata Size
#

Widget size policies. These policies communicate how a widget uses space when being rendered. These policies influence rendering order and space allocation in the box layout algorithm for hBox and vBox.

Constructors

  • Fixed

    Widgets advertising this size policy should take up the same amount of space no matter how much they are given, i.e. their size depends on their contents alone rather than on the size of the rendering area.

  • Greedy

    Widgets advertising this size policy must take up all the space they are given.

Instances3Eq, Ord, Show
  • Eq SizeDefined in brick-2.10 · Brick.Types.Internal
  • Ord SizeDefined in brick-2.10 · Brick.Types.Internal
  • Show SizeDefined in brick-2.10 · Brick.Types.Internal
datadata Direction
#

Scrolling direction.

Constructors

Instances6Eq, Read, Show, Generic, NFData, Rep

Renderer internals (for benchmarking)

1 declaration
datadata RenderState n
#
Instances5Read, Show, Generic, NFData, Rep

Re-exports for convenience

5 declarations
methodget :: m s
#

Return the state from the internals of the monad.

valuegets :: MonadState s m => (s -> a) -> m a
#

Gets specific component of the state, using a projection function supplied.

methodput :: s -> m ()
#

Replace the state inside the monad.

valuemodify :: MonadState s m => (s -> s) -> m ()
#

Monadic state transformer.

Maps an old state to a new state inside a state monad. The old state is thrown away.

     Main> :t modify ((+1) :: Int -> Int)
     modify (...) :: (MonadState Int a) => a ()

This says that modify (+1) acts over any Monad that is a member of the MonadState class, with an Int state.

methodzoom :: LensLike' (Zoomed m c) t s -> m c -> n c
#

When you're in a state monad, this function lets you operate on a part of your state. For instance, if your state was a record containing a position field, after zooming position would become your whole state (and when you modify it, the bigger structure would be modified as well).

(Your State / StateT or RWS / RWST can be anywhere in the stack, but you can't use zoom with arbitrary MonadState because it doesn't provide any methods to change the type of the state. See this issue for details.)

For the sake of the example, let's define some types first:

data Position = Position {
  _x, _y :: Int }

data Player = Player {
  _position :: Position,
  ... }

data Game = Game {
  _player :: Player,
  _obstacles :: [Position],
  ... }

concat <$> mapM makeLenses [''Position, ''Player, ''Game]

Now, here's an action that moves the player north-east:

moveNE :: State Game ()
moveNE = do
  player.position.x += 1
  player.position.y += 1

With zoom, you can use player.position to focus just on a part of the state:

moveNE :: State Game ()
moveNE = do
  zoom (player.position) $ do
    x += 1
    y += 1

You can just as well use it for retrieving things out of the state:

getCoords :: State Game (Int, Int)
getCoords = zoom (player.position) ((,) <$> use x <*> use y)

Or more explicitly:

getCoords = zoom (player.position) $ do
  x' <- use x
  y' <- use y
  return (x', y')

When you pass a traversal to zoom, it'll work as a loop. For instance, here we move all obstacles:

moveObstaclesNE :: State Game ()
moveObstaclesNE = do
  zoom (obstacles.each) $ do
    x += 1
    y += 1

If the action returns a result, all results would be combined with <> – the same way they're combined when ^. is passed a traversal. In this example, moveObstaclesNE returns a list of old coordinates of obstacles in addition to moving them:

moveObstaclesNE = do
  xys <- zoom (obstacles.each) $ do
    -- Get old coordinates.
    x' <- use x
    y' <- use y
    -- Update them.
    x .= x' + 1
    y .= y' + 1
    -- Return a single-element list with old coordinates.
    return [(x', y')]
  ...

Finally, you might need to write your own instances of Zoom if you use newtyped transformers in your monad stack. This can be done as follows:

import Lens.Micro.Mtl.Internal

type instance Zoomed (MyStateT s m) = Zoomed (StateT s m)

instance Monad m => Zoom (MyStateT s m) (MyStateT t m) s t where
    zoom l (MyStateT m) = MyStateT (zoom l m)

Orphan instances

1 instance