Commit Graph

55 Commits (master)

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 ca68bae4ed feat!(widgets/canvas): use spans for text of labels 3 years ago
Florian Dehau 8c1f58079f chore: fix build 3 years ago
Antoine Büsch 4845c03eec
feat(widgets/list): repeat highlight symbol on multi-line items (#533)
When this option is true, the hightlight symbol is repeated for each
line of the selected item, instead of just the first line.
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 34a2be6458 fix(widgets/chart): remove panics with long axis labels 3 years ago
Florian Dehau 38dcddb126 fix(widgets/gauge): apply label style and avoid overflow on large labels 3 years ago
Oleks (オレクス) a346704cdc
feat(block): add option to center and right align the title (#462)
* Added ability to set title alignment, added tests, modified blocks example to show the feature

* Added test for inner with title in block

* Updated block example to show center alignment

* Formatting fixed

* Updated tests to use lamdas and be more concise. Updated title alignmnet code to be more straightforward and have correct behavior when placing title in the center without left border
3 years ago
Florian Dehau 853f3d9200 feat(terminal): add a read-only view of the terminal state after the draw call 3 years ago
Florian Dehau eb1e3be722 fix(widgets/block): make Block::inner return more accurate results on small areas 3 years ago
Vadim Chekan 74243394d9
fix(widgets/table): draw table header and border even if rows are empty (#426) 3 years ago
Florian Dehau efdd6bfb19 feat(tests): add tests covering new table features 3 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.
3 years ago
Florian Dehau 79e27b1778 refactor(widgets/gauge): stop using unicode blocks by default 3 years ago
DashEightMate 0a05579a1c
feat(widgets/gauge): allow gauge to use unicode block for more descriptive progress (#377)
* gauge now uses unicode blocks for more descriptive progress

* removed unnecessary if

* changed function name to better reflect unicode

* standardized block symbols, added no unicode option, added tests

* formatting

* improved readability

* gauge tests now check color

* formatted
3 years ago
Tom Forbes 0030eb4a13
fix(tests): remove clippy warnings about single char push (#424) 3 years ago
pm100 5bf40343eb
fix(widgets/paragraph): handle trailing nbsp in wrapped text (#405) 4 years ago
Florian Dehau 8a27036a54 fix(widgets/block): allow Block to render on small areas 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 5050f1ce1c feat(widgets/gauge): add `LineGauge` variant of `Gauge` 4 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
Kemyt 62495c3bd1
fix(widgets/barchart): fix chart filled more than actual (#383)
* Fix barchart incorrectly showing chart filled more than actual

Determination of how filled the bar should be was incorrectly taking the
entire chart height into account, when in fact it should take height-1, because
of extra line with label. Because of that the chart appeared fuller than it
should and was full before reaching maximum value.

* Add a test case for checking if barchart fills correctly up to max value

Co-authored-by: Kemyt <kemyt4@gmail.com>
4 years ago
Florian Dehau ecb482f297 fix(backend): move the cursor when first diff is on second cell
Both termion and crossterm backends were not moving the cursor if the first diff to draw was on the
second cell. The condition triggering the cursor move has been updated to fix this. In addition, two
tests have been added to avoid future regressions.
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
Brooks Rady 112d2a65f6
feat(widgets/paragraph): add option to preserve indentation when the text is wrapped (#327) 4 years ago
Xiaopeng Li d999c1b434
feat(widgets/paragraph): Add horizontal scroll (#329)
* `Paragraph:scroll` takes a tuple of offsets instead of a single vertical offset.
* `LineTruncator` takes this new horizontal offset into account to let the paragraph scroll horizontally.
4 years ago
Florian Dehau fdbea9e2ee fix(widgets/canvas): avoid panic on zero-width bounds 4 years ago
Alexander Batischev 8c2ee0ed85
feat(terminal): Add after-draw() cursor control to Frame (#91) (#309) 4 years ago
Florian Dehau 4fe647df0a refactor(tests): rename integration tests to be able to call group of tests 4 years ago
Florian Dehau a00350ab54 refactor(tests): rename test files and use the new `TestBackend::assert_buffer` method 4 years ago
Florian Dehau 5a590bca74 chore: enable clippy on all targets and all features
- Remove deny warnings in lib.rs. This allows easier iteration when developing
new features. The warnings will make the CI fails anyway on the clippy CI
stage.
- Run clippy on all targets (including tests and examples) and all features.
- Fail CI on clippy warnings.
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
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
4 years ago
Florian Dehau da4d4e1672 test: assert items are correctly truncated in the `List` widget 4 years ago
Florian Dehau 4f728d363f fix(widgets/list): stop highlighting blank placeholders 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 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 6e24f9d47b style: run cargo fmt 4 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 5 years ago
Sven-Hendrik Haase 144bfb71cf Upgrade to 2018 edition 5 years ago
Karoline Pauls 3fd9e23851 Buffer: correct diffing of buffers with multi-width characters
Resolves #104
5 years ago
Karoline Pauls 10642d0e04 Paragraph: word wrapping 5 years ago
Karoline Pauls 1802cf8dbc Improve wrapping of double-width characters 5 years ago