Commit Graph

43 Commits (c64d754f88337f6d157326d5f7363a455f2c867e)

Author SHA1 Message Date
Florian Dehau c64d754f88 feat(layout): add support for multiple weighted constraints by chunks 3 years ago
Florian Dehau a7c21a9729 fix(widgets): avoid offset panic in `Table` and `List` when input changes 3 years ago
Florian Dehau a68e38e59e fix(table): use `Layout` in table column widths computation 3 years ago
Florian Dehau 8eb6336f5e refactor(widgets): remove iter::repeat for blank symbols 3 years ago
Andrew Chin 24396d97ed doc: Add doctests that shows how Text can be created from Cow<str> 3 years ago
Vadim Chekan 74243394d9
fix(widgets/table): draw table header and border even if rows are empty (#426) 4 years ago
Florian Dehau 5ea54792c0 refactor(widgets/table): more flexible table
- control over the style of each cell and its content using the styling capabilities of Text.
- rows with multiple lines.
- fix panics on small areas.
- less generic type parameters.
4 years ago
Kemyt 98fb5e4bbd
fix(widgets/table): take borders into account when percentage and ration constraints are used (#385)
* Fix percentage and ratio constraints for table to take borders into account

Percentage and ratio constraints don't take borders into account, which causes
the table to not be correctly aligned. This is easily seen when using 50/50
percentage split with bordered table. However fixing this causes the last column
of table to not get printed, so there is probably another problem with columns
width determination.

* Fix rounding of cassowary solved widths to eliminate imprecisions

* Fix formatting to fit convention

Co-authored-by: Kemyt <kemyt4@gmail.com>
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
Florian Dehau bc2a512101 feat: add missing `Clone` and `Copy` on types 4 years ago
Florian Dehau 278c153d31 style: remove clippy warnings 4 years ago
Florian Dehau ae677099d6 feat(widgets/table): allow one row to be selected 4 years ago
Vadim Chekan 1683e8d609
Clean redundant generics params in Table (#234)
* Clean redundant generics params in Table

It is possible to use associated types the same way as generics parameters. In fact associated types are nothing more than better organized generics params. For example, there is no need to introduce another param to constraint iterator item to be Display, you can just say `where I::Iterator, I::Item: Display`. This allows to drop type params for Table from 5 to 2.
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 ea43413507 fix: remove clippy warnings 4 years ago
Caleb Bassi 7aae9b380e Add header_gap field to Table 4 years ago
Florian Dehau 2233cdc9cc chore: add CI based on github actions 5 years ago
Florian Dehau 816bc9b5c8 style: fix formatting and clippy issues 5 years ago
Florian Dehau a82c82fcd7 fix(widgets): remove compilation warning in table widget 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 b669cf9ce7 style: fix clippy warnings 5 years ago
Sven-Hendrik Haase 144bfb71cf Upgrade to 2018 edition 5 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 36a5eb2110 Format code 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 1f285fbac0 [src] Run cargo fmt 7 years ago
Florian Dehau 3b8cc241ac [widgets] Fix table doc test 7 years ago
Florian Dehau c18885d38b [widgets] Refactor Table Widget
* Add Row enum
* Move to a generic definition of table which allow iterators to be
passed as arguments and therefore reduce allocations
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 17c95cf826 Fix table example 8 years ago
Florian Dehau ad239ef23c Update list and table to be more flexible
* Move List to SelectableList
* Create a more generic List
* Change the way to pass items to the table widget
* Update demo
8 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 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 a5b632aeb0 Cleanup API 8 years ago
Florian Dehau a36e20f217 Add background_color support for all existing wigets 8 years ago
Florian Dehau dd6cdf1f11 Add Table widget base implementation 8 years ago