Commit Graph

33 Commits

Author SHA1 Message Date
Florian Dehau
cee65ed283 feat: allow BarChart and Sparkline to use a more portable set of symbols
Add `BarChart::bar_set` and `Sparkline::bar_set` methods to customize
the set of symbols used to display the data. The new set should give
a better looking output on terminal that do not support a wide 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
ea43413507 fix: remove clippy warnings 2020-01-19 23:11:12 +01:00
Joseph Knight
e183d63a5e typo in barcharg.rs 2019-08-11 14:03:58 +02:00
Florian Dehau
4756801fd9 Format 2019-06-16 22:21:55 +02:00
Russ
f0e0b515ad avoid divide by zero 2019-06-16 20:29:14 +02:00
David Flemström
b7664a4108 Support several modifiers and indexed colors at once 2019-03-10 15:56:56 +01:00
Florian Dehau
b669cf9ce7 style: fix clippy warnings 2019-02-03 22:42:09 +01:00
Sven-Hendrik Haase
144bfb71cf Upgrade to 2018 edition 2019-01-13 14:35:51 +00:00
Karoline Pauls
8522e028f1 Run cargo fmt with the new Rust stable toolchain (1.31.0) 2018-12-07 19:54:13 +01:00
Florian Dehau
d8e5f57d53 style: fmt 2018-09-23 21:00:36 +02:00
Florian Dehau
6c69160d6b feat: remove unecessary borrows of Style 2018-09-07 22:24:52 +02:00
Florian Dehau
13e194cd26 refactor: update widgets
* all widgets use the consumable builder pattern
* `draw` on terminal expect a closure that take a frame as only arg
2018-09-04 22:23:44 +02:00
Florian Dehau
d6016788ef refactor: clippy + rustfmt 2018-09-04 22:23:44 +02:00
Florian Dehau
7181970a32 feat: split layout from rendering
* remove layout logic from Terminal
* replace Group with Layout
* add Frame intermediate object
2018-09-04 22:23:44 +02:00
Florian Dehau
36a5eb2110 Format code 2018-05-06 15:54:47 +02:00
Florian Dehau
151d7e8a1c [src] Update dependencies
* Update all dependencies to their latest versions
* Change border to Borders to match v1.0 of bitflags
2017-12-26 21:45:46 +01:00
Florian Dehau
1f285fbac0 [src] Run cargo fmt 2017-10-30 23:14:57 +01:00
talha
3045ac4124 Minor codestyle fixes 2017-10-30 17:15:28 +01:00
Florian Dehau
71545a0aa8 Run cargo fmt 2017-09-11 08:15:39 +02:00
Florian Dehau
b1737ce667 Update Widget Trait
The draw function now take a &mut reference to the widget, allowing the
widget to modify itself when drawn. This change the semantic of the draw
call since the widget should now be considered "consumed" after it.
2017-09-10 21:38:17 +02:00
Florian Dehau
b2bb24b9d2 Fix rustfmt and clippy errors 2017-05-21 12:49:12 +02:00
Florian Dehau
662e2dd102 Fix examples 2016-11-06 21:41:32 +01:00
Florian Dehau
224eb2d8e0 Add support for text styling 2016-11-06 18:49:57 +01:00
Florian Dehau
652ff12380 More documentation 2016-11-04 19:27:19 +01:00
Florian Dehau
a5b632aeb0 Cleanup API 2016-11-02 19:16:53 +01:00
Florian Dehau
a36e20f217 Add background_color support for all existing wigets 2016-11-02 17:08:52 +01:00
Florian Dehau
107d7297af Fix some layout problems 2016-10-31 18:04:10 +01:00
Florian Dehau
b0b1645010 Rename set_characters method in buffer interface 2016-10-27 19:33:32 +02:00
Florian Dehau
bcb3d751bf Rename buffer methods 2016-10-27 12:35:26 +02:00
Florian Dehau
c91436baee Change rendering method and adapt widget trait accordingly 2016-10-26 14:32:45 +02:00
Florian Dehau
017eaa4122 Fix clippy warnings 2016-10-22 19:24:35 +02:00
Florian Dehau
063bde8764 Add bar chart prototype 2016-10-22 12:51:41 +02:00