Commit Graph

63 Commits (853d9047b0f83e50dabbfc0359692e44bbbb5f1a)

Author SHA1 Message Date
theogilbert 853d9047b0
feat(widgets/chart): add option to control alignment of axis labels (#568)
* feat(chart): allow custom alignment of first X-Axis label

* refactor(chart): rename ambiguous function parameter

* feat(chart): allow custom alignment of Y-Axis labels

* refactor(chart): refactor axis test cases

* refactor(chart): rename minor variable

* fix(chart): force centered x-axis label near Y-Axis

* fix(chart): fix subtract overflow on small rendering area

* refactor(chart): rename alignment property

* refactor(chart): merge two nested conditions

* refactor(chart): decompose x labels rendering loop
2 years ago
Florian Dehau 6069d89dee chore: fix all clippy warnings 2 years ago
Florian Dehau 34a2be6458 fix(widgets/chart): remove panics with long axis labels 3 years ago
Florian Dehau eb1e3be722 fix(widgets/block): make Block::inner return more accurate results on small areas 3 years ago
Florian Dehau c4cd0a5f31 fix(widgets/chart): use the correct style to draw legend and axis titles
Before this change, the style of the points drawn in the graph area could reused to draw the
title of the axis and the legend. Now the style of these components put on top of the graph area
is solely based on the widget style.
4 years ago
Brooks Rady 0abaa20de9
refactor: clean up some folds (#362) 4 years ago
Florian Dehau 0ffea495b1 refactor: implement cascading styles
- merge `Style` and `StyleDiff` together. `Style` now is used to activate or deactivate certain
style rules not to overidden all of them.
- update all impacted widgets, examples and tests.
4 years ago
Florian Dehau 88c4b191fb feat(text): add new text primitives 4 years ago
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
4 years ago
Florian Dehau bc2a512101 feat: add missing `Clone` and `Copy` on types 4 years ago
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.
4 years ago
Florian Dehau 140db9b2e2 refactor(canvas): update shape drawing strategy
* Update the `Shape` trait. Instead of returning an iterator of point, all
shapes are now aware of the surface they will be drawn to through a `Painter`.
In order to draw themselves, they paint points of the "braille grid".
* Rewrite how lines are drawn using a common line drawing algorithm (Bresenham).
4 years ago
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.
4 years ago
Florian Dehau d16db5ed90 style: fix clippy warnings 4 years ago
Florian Dehau 28017f97ea feat(widgets/chart): add more control on the visibility of the legend 4 years ago
Florian Dehau ea43413507 fix: remove clippy warnings 4 years ago
Caleb Bassi 829b7b6b70 Change linechart to draw the points also 4 years ago
Caleb Bassi 262bf441ce Add linechart support
Closes #73

This commit only adds support for linecharts for the braille marker.
4 years ago
Sebastian Woetzel bbd4363fa9 Bugfix: title_style was not used to style the axis title 4 years ago
David Flemström b7664a4108 Support several modifiers and indexed colors at once 5 years ago
Florian Dehau b669cf9ce7 style: fix clippy warnings 5 years ago
Sven-Hendrik Haase 144bfb71cf Upgrade to 2018 edition 5 years ago
Karoline Pauls 8522e028f1 Run `cargo fmt` with the new Rust stable toolchain (1.31.0) 6 years ago
Florian Dehau d8e5f57d53 style: fmt 6 years ago
Florian Dehau 6c69160d6b feat: remove unecessary borrows of Style 6 years ago
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
6 years ago
Florian Dehau d6016788ef refactor: clippy + rustfmt 6 years ago
Florian Dehau 7181970a32 feat: split layout from rendering
* remove layout logic from Terminal
* replace Group with Layout
* add Frame intermediate object
6 years ago
Jeremy Day cfc90ab7f6 fix(widgets): Prevent chart legend from rendering when no dataset has a name 6 years ago
Florian Dehau 36a5eb2110 Format code 6 years ago
Florian Dehau 6a3b9fb130 [src][chart] fmt 6 years ago
Florian Dehau 151d7e8a1c [src] Update dependencies
* Update all dependencies to their latest versions
* Change border to Borders to match v1.0 of bitflags
6 years ago
Florian Dehau af16518650 [src] Run rustfmt 6 years ago
Florian Dehau 5dd03d91ad [widgets] Fix a bug in chart layout 6 years ago
Florian Dehau 3cc3585e48 [widgets][chart] Use generic type for labels 7 years ago
talha 3045ac4124 Minor codestyle fixes 7 years ago
Florian Dehau 71545a0aa8 Run cargo fmt 7 years ago
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.
7 years ago
Florian Dehau b2bb24b9d2 Fix rustfmt and clippy errors 7 years ago
Florian Dehau 662e2dd102 Fix examples 8 years ago
Florian Dehau 224eb2d8e0 Add support for text styling 8 years ago
Florian Dehau 652ff12380 More documentation 8 years ago
Florian Dehau fcac19d6c5 Documentation 8 years ago
Florian Dehau 93cc237007 Documentation 8 years ago
Florian Dehau 9e5195096a More work on the widgets API
* Change slice to vecs in table and canvas to ease the interaction with data
constructed on the fly
* Add a legend to charts based on datasets' names and colors
* Update demo to reflect previous updates
8 years ago
Florian Dehau 20465f2159 Change dot symbol for line chart 8 years ago
Florian Dehau a5b632aeb0 Cleanup API 8 years ago
Florian Dehau a36e20f217 Add background_color support for all existing wigets 8 years ago
Florian Dehau d038b283db Fix chart and canvas widgets 8 years ago
Florian Dehau 654be037be Redefine canvas widget and add shapes
* Give the canvas widget a proper modules and define a standard way to
draw to it (Shape trait)
* Add Points, Line, Rectangle and Map shapes
8 years ago