Commit Graph

17 Commits (d987225ac80144d4788ea5e1960ea9a245bbfad1)

Author SHA1 Message Date
Florian Dehau 6cb57f5d2a feat: add stateful widgets
Most widgets can be drawn directly based on the input parameters. However, some
features may require some kind of associated state to be implemented.

For example, the `List` widget can highlight the item currently selected. This
can be translated in an offset, which is the number of elements to skip in
order to have the selected item within the viewport currently allocated to this
widget. The widget can therefore only provide the following behavior: whenever
the selected item is out of the viewport scroll to a predefined position (make
the selected item the last viewable item or the one in the middle).
Nonetheless, if the widget has access to the last computed offset then it can
implement a natural scrolling experience where the last offset is reused until
the selected item is out of the viewport.

To allow such behavior within the widgets, this commit introduces the following
changes:
- Add a `StatefulWidget` trait with an associated `State` type. Widgets that
can take advantage of having a "memory" between two draw calls needs to
implement this trait.
- Add a `render_stateful_widget` method on `Frame` where the associated
state is given as a parameter.

The chosen approach is thus to let the developers manage their widgets' states
themselves as they are already responsible for the lifecycle of the wigets
(given that the crate exposes an immediate mode api).

The following changes were also introduced:

- `Widget::render` has been deleted. Developers should use `Frame::render_widget`
instead.
- `Widget::background` has been deleted. Developers should use `Buffer::set_background`
instead.
- `SelectableList` has been deleted. Developers can directly use `List` where
`SelectableList` features have been back-ported.
5 years ago
Florian Dehau d16db5ed90 style: fix clippy warnings 5 years ago
Florian Dehau 6e24f9d47b style: run cargo fmt 5 years ago
Florian Dehau 816bc9b5c8 style: fix formatting and clippy issues 5 years ago
Jeffas 94877f4e7e Use constraints for table column widths
This allows table column widths to be adapted more and scale with the
UI.

The constraints are solved using the Cassowary solver. An added
constraint for fitting them all in the width is added.
5 years ago
Florian Dehau abd552fde6 Run cargo fmt 5 years ago
Jeremy Day 47c68e40a2 fix for canvas rendering edge cases causing overflow errors 5 years ago
Florian Dehau 6d594143ed Format 6 years ago
Sven-Hendrik Haase 144bfb71cf Upgrade to 2018 edition 6 years ago
Karoline Pauls 3fd9e23851 Buffer: correct diffing of buffers with multi-width characters
Resolves #104
6 years ago
Karoline Pauls 10642d0e04 Paragraph: word wrapping 6 years ago
Karoline Pauls 1802cf8dbc Improve wrapping of double-width characters 6 years ago
Karoline Pauls 090975481b Update tests and docs to take size from the Frame 6 years ago
Karoline Pauls 8522e028f1 Run `cargo fmt` with the new Rust stable toolchain (1.31.0) 6 years ago
Karoline Pauls cc95c8cfb0 Gauge: use f64 internally and allow to set any f64 between 0 and 1 6 years ago
Karoline Pauls 5cee2afc6d Limit Rect size to prevent u16 overflow 6 years ago
Florian Dehau 22e8fade7e feat: add experimental test backend 6 years ago