Commit graph

22 commits

Author SHA1 Message Date
Clement Tsang
b72ced4511
fix(widgets/chart): remove overflow when dataset if empty (#274)
* docs: Fix missing code block fence
* use slice::windows to deal with underflow issue
* add test for empty dataset and lines
2020-05-10 23:48:12 +02:00
Darrien Glasser
359b7feb8c
fix(widgets/canvas): Add bounds check when drawing line high/low (#283)
* Add bounds check when drawing line high/low
* Add test to ensure codepath doesn't break
2020-05-10 14:40:04 +02:00
Florian Dehau
da4d4e1672 test: assert items are correctly truncated in the List widget 2020-04-16 16:24:43 +02:00
Florian Dehau
4f728d363f fix(widgets/list): stop highlighting blank placeholders 2020-04-14 18:40:59 +02:00
Florian Dehau
584e1b0500 refactor(widgets/canvas): allow canvas to render with a simple dot character instead of braille patterns
This change allows developers to gracefully degrade the output if the targeted
terminal does not support the full range of unicode symbols.
2020-04-14 02:17:22 +02:00
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.
2020-02-23 19:23:37 +01:00
Florian Dehau
d16db5ed90 style: fix clippy warnings 2020-02-23 15:46:46 +01:00
Florian Dehau
6e24f9d47b style: run cargo fmt 2020-02-23 15:46:30 +01:00
Florian Dehau
816bc9b5c8 style: fix formatting and clippy issues 2019-11-05 08:08:14 +01:00
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.
2019-10-31 09:18:24 +01:00
Florian Dehau
abd552fde6 Run cargo fmt 2019-07-16 08:31:23 +02:00
Jeremy Day
47c68e40a2 fix for canvas rendering edge cases causing overflow errors 2019-06-23 11:12:51 +02:00
Florian Dehau
6d594143ed Format 2019-04-14 11:43:12 +02:00
Sven-Hendrik Haase
144bfb71cf Upgrade to 2018 edition 2019-01-13 14:35:51 +00:00
Karoline Pauls
3fd9e23851 Buffer: correct diffing of buffers with multi-width characters
Resolves #104
2019-01-13 13:46:39 +00:00
Karoline Pauls
10642d0e04 Paragraph: word wrapping 2018-12-22 15:38:51 +01:00
Karoline Pauls
1802cf8dbc Improve wrapping of double-width characters 2018-12-22 15:38:51 +01:00
Karoline Pauls
090975481b Update tests and docs to take size from the Frame 2018-12-07 21:32:00 +01:00
Karoline Pauls
8522e028f1 Run cargo fmt with the new Rust stable toolchain (1.31.0) 2018-12-07 19:54:13 +01:00
Karoline Pauls
cc95c8cfb0 Gauge: use f64 internally and allow to set any f64 between 0 and 1 2018-12-05 21:20:12 +01:00
Karoline Pauls
5cee2afc6d Limit Rect size to prevent u16 overflow 2018-11-25 19:59:12 +01:00
Florian Dehau
22e8fade7e feat: add experimental test backend 2018-11-04 20:16:10 +01:00