[−][src]Module cursive::view
Base elements required to build views.
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::required_size()
on them.
Contracts
When building new Views, you should respect these contracts:
-
By default,
View::layout()
should be called before any call toView::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()
returnsfalse
In this case, it is safe to omit the call to
View::layout()
. - The available size has not changed since the last call to
-
The value returned by
required_size
should be an actually viable size, no matter what the request is. This means callingView::layout()
with a size returned byrequired_size
is never an error.
Structs
Margins | Four values representing each direction. |
ScrollBase | Provide scrolling functionalities to a view. |
SizeCache | Cache around a one-dimensional layout result. |
ViewPath | Represents a path to a single view in the layout. |
Enums
Offset | Single-dimensional offset policy. |
ScrollStrategy | Defines the scrolling behaviour on content or size change |
Selector | Selects a single view (if any) in the tree. |
SizeConstraint | Single-dimensional constraint on a view size. |
Traits
AnyView | A view that can be downcasted to its concrete type. |
Boxable | Makes a view wrappable in a |
Finder | Provides |
Identifiable | Makes a view wrappable in an |
IntoBoxedView | Represents a type that can be made into a |
Scrollable | Makes a view wrappable in a |
View | Main trait defining a view behaviour. |
ViewWrapper | Generic wrapper around a view. |
Type Definitions
Position | Location of the view on screen |