We don't anticipate removing or deprecating the type alias in the near
future, but it is recommended to update your imports to use the new
name.
Added a VerticalAlignment enum to make the API more consistent. We don't
have a specific use case for it yet, but it's better to add it now and
be able to use it in the future.
BREAKING-CHANGE: The `Alignment` enum has been renamed to
`HorizontalAlignment` to better reflect its purpose. A type alias has
been added to maintain backwards compatibility, however there are some
cases where type aliases are not enough to maintain backwards
compatibility. E.g. when using glob imports to import all the enum
variants. This should not affect most users, but it is recommended to
update your imports to use the new name.
```diff
- use ratatui::layout::Alignment;
+ use ratatui::layout::HorizontalAlignment;
- use Alignment::*;
+ use HorizontalAlignment::*;
```
I was swayed by the arguments about this made by the compiler team In
<https://github.com/rust-lang/compiler-team/issues/750> and decided to
look at how this organization affects ratatui. I found this reduces the
number of lines across the codebase by about 350 and makes the imports
more readable and definitely more greppable as you usually only have
to read a single line. I've found in the past that maintaining imports
regularly leads to merge conflicts which have to be resolved by hand
and this change should reduce the likelihood of that happening.
Main change is in rustfmt.toml, and the rest is just the result of
running `cargo xtask format`.
While implementing this, cargo machete brings up that the various
backend crates are unused by the example crates.
The re-export of each backend crate under ratatui is to make it possible
for libs that rely on a specific version of ratatui to use the same
version of the backend crate. Apps in general should use the backend
crate directly rather than through ratatui as this is less confusing.
- Removes all usages of `ratatui::{crossterm, termion, termwiz}`` in the
examples.
- Adds the backend crate to the dependencies of the examples that use
the backend crate directly.
Allow styling for `List`'s highlight symbol
This change makes it so anything that implements `Into<Line>` can be
used as a highlight symbol.
BREAKING CHANGE: `List::highlight_symbol` can no longer be used in const
context
BREAKING CHANGE: `List::highlight_symbol` accepted `&str`. Conversion
methods that rely on type inference will need to be rewritten as the
compiler cannot infer the type.
closes: https://github.com/ratatui/ratatui/issues/1443
---------
Co-authored-by: Josh McKinney <joshka@users.noreply.github.com>
AI coding assistants use the deprecation notes to automatically suggest
fixes. This commit updates the deprecation notes to push those tools to
suggest the correct replacement methods and types.
Specifically, AI tools often suggest using `Buffer::get(x, y)`, because
of their training data where this was prevalent. When fixing these
deprecations, they often incorrectly suggest using `Buffer::get(x, y)`
instead of `Buffer[(x, y)]`.
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>
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>
- 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
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());
```
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.
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.
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>
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
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>
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.
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