Module cursive::view [] [src]

Defines various views to use when creating the layout.

Views are the main building blocks of your UI.

A view can delegate part or all of its responsabilities to child views, forming a view tree. The root of this tree is a StackView handled directly by the Cursive element.

Layout

The layout phase is when the size and location of each view is computed.

Each view is given an area of the screen by the View::layout() method. With this, the view is free to plan its content, including calling View::layout() on its own children.

In order to determine how much space should be given each child, parents can use View::get_min_size() on them.

Contracts

When building new Views, you should respect these contracts:

  • By default, View::layout() should be called before any call to View::draw() with the same available size. The only exceptions is when both following conditions are met:

    • The available size has not changed since the last call to View::layout()
    • View::needs_relayout() returns false

    In this case, it is safe to omit the call to View::layout().

  • The value returned by get_min_size should be an actually viable size, no matter what the request is. This means calling View::layout() with a size returned by get_min_size is never an error.

Structs

BoxView

Wrapper around another view, with a fixed size.

Button

Simple text label with a callback when ENTER is pressed. A button shows its content in a single line and has a fixed size.

Dialog

Popup-like view with a main content, and optional buttons under it.

EditView

Input box where the user can enter and edit text.

FullView

Simple wrapper view that asks for all the space it can get.

IdView

Wrapper view that allows to select its content with a fixed string id.

KeyEventView

A simple wrapper view that catches some ignored event from its child.

LinearLayout

Arranges its children linearly according to its orientation.

MenuPopup

Popup that shows a list of items.

ScrollBase

Provide scrolling functionalities to a view.

SelectView

View to select an item among a list.

ShadowView

Wrapper view that adds a shadow.

SizeCache

Cache around a one-dimensional layout result

SizedView

Wrapper around a view that remembers its size.

StackView

Simple stack of views. Only the top-most view is active and can receive input.

TextView

A simple view showing a fixed text

TrackedView

Wrapper around a view that remembers its position.

ViewPath

Represents a path to a single view in the layout.

Enums

Offset

Single-dimensional offset policy.

Selector

Selects a single view (if any) in the tree.

Traits

View

Main trait defining a view behaviour.

ViewWrapper

Generic wrapper around a view.

Type Definitions

Position

Location of the view on screen