45 Commits

Author SHA1 Message Date
Orhun Parmaksız
bb94d1c0fa
docs(examples): move minimal example to examples folder (#1649) 2025-02-05 10:11:57 -08:00
Björn Steinbrink
f5fc8197ff
fix: avoid extra line break on whitespace only lines when wrapping paragraphs (#1636)
Currently whitespace only lines produces an extra line break when
trimming is disabled, because both the trimmed as well as the
non-trimmed line get inserted. Fix this by only inserting the
non-trimmed one.

Co-authored-by: Björn Steinbrink <b.steinbrink@demv.de>
2025-02-04 17:02:50 -08:00
Alex Pasmantier
1f41a61008
perf(paragraph): avoid unnecessary work when rendering (#1622)
Improve render times for paragraphs that are scrolled.

Currently all `LineComposer`s are considered to be state machines which
means rendering a paragraph with a given Y offset requires computing the
entire state up to Y before being able to render from Y onwards.

While this makes sense for Composers such as the `WordWrapper` (where
one needs to consider all previous lines to determine where a given line
will end up), it means it also penalizes Composers which can render a
given line "statelessely" (such as the `LineTruncator`) which actually
end up doing a lot of unnecessary work (and on the critical rendering
path) when the offset gets high.

Co-authored-by: Josh McKinney <joshka@users.noreply.github.com>
2025-01-23 13:52:52 -08:00
Jens Krause
7ad9c29eac
feat(linegauge): customized symbols (#1601)
With this PR any symbol (`&str`) can be used to render `filled` and
`unfilled` parts of `LineGauge` now. Before that change, only
[`symbols::line::Set`](https://docs.rs/ratatui/latest/ratatui/symbols/line/struct.Set.html)
was accepted.

Note: New methods are introduced to define those symbols:
`filled_symbol` and `unfilled_symbol`. The method
[`line_set`](https://docs.rs/ratatui/latest/ratatui/widgets/struct.LineGauge.html#method.line_set)
is still there, but marked as `deprecated`.

![line_gauge](https://github.com/user-attachments/assets/cae308b8-151b-461d-8af6-9a20012adf2f)
2025-01-22 19:56:22 -08:00
Théo Tchilinguirian
985cd05573
feat(symbols): add dashed borders (#1573)
Adds several new border sets:
- ratatui:🔣:border::LIGHT_DOUBLE_DASHED
- ratatui:🔣:border::HEAVY_DOUBLE_DASHED
- ratatui:🔣:border::LIGHT_TRIPLE_DASHED
- ratatui:🔣:border::HEAVY_TRIPLE_DASHED
- ratatui:🔣:border::LIGHT_QUADRUPLE_DASHED
- ratatui:🔣:border::HEAVY_QUADRUPLE_DASHED

And corresponding variants to the ratatui::widgets::BorderType enum

Fixes: https://github.com/ratatui/ratatui/issues/1355
Signed-off-by: Théo Tchilinguirian <theo.tchlx@gmail.com>
2025-01-20 00:36:19 -08:00
Josh McKinney
e7831aedd4
chore: release 0.30.0-alpha.1 (#1618)
Versions:

```
ratatui = { path = "ratatui", version = "0.30.0-alpha.1" }
ratatui-core = { path = "ratatui-core", version = "0.1.0-alpha.2" }
ratatui-crossterm = { path = "ratatui-crossterm", version = "0.1.0-alpha.1" }
ratatui-termion = { path = "ratatui-termion", version = "0.1.0-alpha.1" }
ratatui-termwiz = { path = "ratatui-termwiz", version = "0.1.0-alpha.1" }
ratatui-widgets = { path = "ratatui-widgets", version = "0.3.0-alpha.1" }
```
2025-01-15 15:31:38 -08:00
Josh McKinney
4a871f993e
ci: refactor xtask / toml formatting (#1602)
- format toml files using taplo
- add toml formatting check to CI
- use xtask consistently from bacon
- refactor xtask commands to take params instead of multiple commands
2025-01-14 14:20:05 -08:00
Josh McKinney
a692a6e371
fix(lint): apply rust 1.84 clippy suggestions (#1612)
The canvas map constants are now statics instead.
Fixes
https://rust-lang.github.io/rust-clippy/master/index.html\#large_const_arrays
2025-01-10 23:17:07 +03:00
n4n5
50ba96518f
feat: add a new RatatuiMascot widget (#1584)
Move the Mascot from Demo2 into a new widget.
Make the Rat grey and adjust the other colors.

```rust
frame.render_widget(RatatuiMascot::default(), frame.area());
```
2024-12-26 04:32:38 -08:00
dawe
03066d81bf
docs: fix punctuation in canvas.rs documentation (#1583)
Fix end of sentence punctuation in canvas.rs docs.
2024-12-21 03:49:44 -05:00
Orhun Parmaksız
dafb716f9d
docs(widgets): add example for grouped barchart (#1566)
related #1512

---------

Co-authored-by: Josh McKinney <joshka@users.noreply.github.com>
2024-12-12 20:42:41 +03:00
Orhun Parmaksız
ed5dd73084
docs(widgets): add example for tabs (#1559)
related #1512 

Also removes the tabs example from ratatui crate since it overlaps with
this new example in terms of functionality and it was not following the
general theme of other examples.
2024-12-09 15:22:03 -08:00
Orhun Parmaksız
fab532171d
docs(widgets): add example for scrollbar (#1545)
Related to: #1512
2024-12-08 02:28:18 -08:00
Orhun Parmaksız
898aef6e2f
docs(widgets): add example for list (#1542)
Related to: #1512
2024-12-08 02:27:19 -08:00
Orhun Parmaksız
452366aa9e
docs(widgets): add example for sparkline (#1556)
related #1512

Also removes the sparkline example from ratatui crate since this example
is a simplified and easier to understand version of that
2024-12-07 18:35:45 +03:00
Orhun Parmaksız
ff729b7607
feat(scrollbar): support retrieving the current position of state (#1552)
As of now it is possible to change the position of the Scrollbar but not
possible to retrieve the position for further use. e.g.

```rust
let mut state = ScrollbarState::default();
state.next();
```

This commit adds a new method "`current_position`" (since `position` is
already taken by the fluent setter) for that purpose:

```rust
let index = state.get_position(); // yay
```

See #1545 for the concrete usage of this.
2024-12-07 18:23:22 +03:00
Orhun Parmaksız
6ddde0e8a8
docs(widgets): add example for table (#1557)
related #1512
2024-12-07 18:21:01 +03:00
Orhun Parmaksız
93ad6b828c
docs(widgets): update values in chart example (#1558)
better stonks
2024-12-07 18:20:49 +03:00
Orhun Parmaksız
15f442a71e
docs(widgets): add example for paragraph (#1544)
related #1512 

Also removes the paragraph example from `ratatui` since these examples
are more or less the same.
2024-12-04 21:16:04 +03:00
Orhun Parmaksız
17bba14540
docs(widgets): move the logo example to widgets (#1543)
related #1512 

Also updates the code to make it consistent with the other examples
2024-12-03 22:30:35 +03:00
Orhun Parmaksız
ce4856a65f
feat(widgets): add the missing constructor to canvas types (#1538)
Allows constructing `Rectangle`, `Points` and `Circle` using the `new`
method instead of initializing with the public fields directly.
2024-12-03 12:04:53 +03:00
Orhun Parmaksız
f2451e7f1e
docs(widgets): add example for gauge (#1539)
related #1512
2024-12-03 12:04:29 +03:00
raylu
7c8573f575
refactor: rearrange selection_spacing code (#1540) 2024-12-03 00:11:47 -08:00
Orhun Parmaksız
4f0a8b21af
docs(widgets): add example for canvas (#1533)
related #1512
2024-12-02 17:21:53 +03:00
Orhun Parmaksız
91147c4d75
docs(widgets): add example for chart (#1536)
stonks
2024-12-01 20:34:57 +03:00
Orhun Parmaksız
6dd25a3111
docs(widgets): add example for calendar (#1532)
related #1512
2024-12-01 14:12:06 +03:00
Raffaele Cataldo
3b13240728
fix(scrollbar): check for area.is_empty() before rendering (#1529)
This adds the `area.is_empty()` back into the scrollbar render method.
Without it, the widget panics if the height is 0.

Co-authored-by: Josh McKinney <joshka@users.noreply.github.com>
2024-11-30 16:36:49 -08:00
Josh McKinney
d3f01ebf6e
chore(lint): ensure lint config is correct (#1528)
- Move lints to workspace manifest
- Add lint config to backend crates
- Fix one small lint error
2024-11-30 11:13:50 +03:00
Josh McKinney
2892bddce6
fix: rust 1.83 clippy lints (#1527)
https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
2024-11-29 10:49:12 +03:00
Josh McKinney
fbf6050c86
chore: prepare alpha modularization release (#1525)
This is the first modularization -alpha release. It captures the changes
necessary to manual publish. And ensures all the crates are properly
setup and to set a baseline for comparison in future release checks etc.

This does not update / check the git-cliff setup / changelog

Part of: #1388
2024-11-28 16:47:43 -08:00
Orhun Parmaksız
2b7ec5cb7f
chore(widgets): enable calendar widget as default (#1521)
We now expect that you disable the default features if you want less
dependencies
2024-11-27 11:06:09 +03:00
Orhun Parmaksız
d291042e69
docs(block): revise the block example (#1520)
- Moves the block example from `ratatui` to `ratatui-widgets`
- Simplifies the example (bordered, styled, custom borders)

see #1512
2024-11-26 22:38:40 +03:00
Josh McKinney
99ac005b06
docs(widgets): Add simple barchart example (#1511) 2024-11-24 01:32:54 -08:00
Josh McKinney
f132fa1715
refactor(table): small readability improvements (#1510) 2024-11-24 01:32:44 -08:00
Emirhan TALA
369b18eef2
feat(barchart): reduce barchart creation verbosity (#1453)
Adds constructor methods for BarChart, BarGroup, and Bar
2024-11-24 00:06:16 -08:00
Eric Lunderberg
2ce958e38c
fix(table): Allow display of additional table row, if row height > 1 (#1452) 2024-11-23 18:40:22 -08:00
Orhun Parmaksız
217c57cd60
refactor: modularize backends (#1508)
Backend code is now moved to `ratatui-crossterm`, `ratatui-termion` and
`ratatui-termwiz`. This should be backwards compatible with existing code.

Co-authored-by: Josh McKinney <joshka@users.noreply.github.com>
2024-11-23 15:23:40 -08:00
Josh McKinney
ec30390446
fix(canvas): round coordinates to nearest grid cell (#1507)
Previously the canvas coordinates were rounded towards zero, which
causes the rendering to be off by one pixel in some cases. It also meant
that pixels at the extreme edges of the canvas can only be drawn if the
point was exactly on the edge of the canvas. This commit rounds the
coordinates to the nearest integer instead. This may change the output
for some apps using Canvas / Charts.
2024-11-22 14:00:55 -08:00
Emirhan TALA
56d5e05762
feat(bar)!: update label and text_value to accept Into<> (#1471)
BREAKING CHANGE: label and text_value now accept `Into<>` types, which
breaks type inference.

```diff
- Bar::default().label("foo".into());
+ Bar::default().label("foo");
```

```diff
- Bar::default().text_value("bar".into());
+ Bar::default().text_value("bar");
```
2024-11-21 19:12:24 -08:00
Emirhan TALA
b76ad3b02e
feat(bar): impl Styled for Bar (#1476)
Related: https://github.com/ratatui/ratatui/issues/683
2024-11-21 17:30:08 -08:00
Ivan Smoliakov
afd1ce179b
fix(canvas): Lines that start outside the visible grid are now drawn (#1501)
Previously lines with points that were outside the canvas bounds were
not drawn at all. Now they are clipped to the bounds of the canvas so
that the portion of the line within the canvas is draw.

To facilitate this, a new `Painter::bounds()` method which returns the
bounds of the canvas is added.

Fixes: https://github.com/ratatui/ratatui/issues/1489
2024-11-21 16:16:11 -08:00
Josh McKinney
36e2d1bda1
fix: add feature(doc_cfg) when generating docs (#1506) 2024-11-20 04:17:13 -08:00
Josh McKinney
a41c97b413
chore: move unstable widget refs to ratatui (#1491)
These are less stable than the non-ref traits as we have not yet
committed to the exact API. This change moves them to ratatui from
ratatui-core.

To facilitate this:
- implementations of WidgetRef for all internal widgets are removed and
  replaced with implementations of Widget for references to those
  widgets.
- Widget is now implemented for Option<W> where W: Widget, allowing for
  rendering of optional widgets.
- The blanket implementation of Widget for WidgetRef is reversed, to be
  a blanket implementation of WidgetRef for all &W where W: Widget.

BREAKING CHANGE: implementations of WidgetRef no longer have a blanket
implementation of Widget, so Widgets should generally implement the
Widget trait on a reference to the widget rather than implementing
WidgetRef directly. This has the advantage of not requiring unstable
features to be enabled.

Part of: https://github.com/ratatui/ratatui/issues/1388

Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
2024-11-18 14:19:21 -08:00
Orhun Parmaksız
46902f5587
docs: improve docs for workspace crates (#1490)
Overall makes improvements in the documentation of the workspace crates and checking them.
2024-11-18 02:03:44 +03:00
Josh McKinney
e7085e3a3e
chore: move widgets into ratatui-widgets crate (#1474)
All the widgets now live in their own ratatui-widgets crate, but are re-exported in the main ratatui crate.
This makes it easier to use portions of the ratatui library and is part of the effort to modularize

Part of: #1388

---------

Co-authored-by: Orhun Parmaksız <orhun@archlinux.org>
Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
2024-11-15 19:42:07 -08:00