* feat(layout): add vertical and horizontal constructors
This commit adds two new constructors to the `Layout` struct, which
allow the user to create a vertical or horizontal layout with default
values.
```rust
let layout = Layout::vertical([
Constraint::Length(10),
Constraint::Min(5),
Constraint::Length(10),
]);
let layout = Layout::horizontal([
Constraint::Length(10),
Constraint::Min(5),
Constraint::Length(10),
]);
```
Important note: this also fixes a wrong mapping between ratatui's gray
and termwiz's grey. `ratatui::Color::Gray` now maps to
`termwiz::color::AnsiColor::Silver`
* feat: accept Color and Modifier for all Styles
All style related methods now accept `S: Into<Style>` instead of
`Style`.
`Color` and `Modifier` implement `Into<Style>` so this is allows for
more ergonomic usage. E.g.:
```rust
Line::styled("hello", Style::new().red());
Line::styled("world", Style::new().bold());
// can now be simplified to
Line::styled("hello", Color::Red);
Line::styled("world", Modifier::BOLD);
```
Fixes https://github.com/ratatui-org/ratatui/issues/694
BREAKING CHANGE: All style related methods now accept `S: Into<Style>`
instead of `Style`. This means that if you are already passing an
ambiguous type that implements `Into<Style>` you will need to remove
the `.into()` call.
`Block` style methods can no longer be called from a const context as
trait functions cannot (yet) be const.
* feat: add tuple conversions to Style
Adds conversions for various Color and Modifier combinations
* chore: add unit tests
* feat(table): Add a Table::footer method
Signed-off-by: Antonio Yang <yanganto@gmail.com>
* feat(table): Add a Row::top_margin method
- add Row::top_margin
- update table example
Signed-off-by: Antonio Yang <yanganto@gmail.com>
---------
Signed-off-by: Antonio Yang <yanganto@gmail.com>
At close to 2000 lines of code, the table widget was getting a bit
unwieldy. This commit splits it into multiple files, one for each
struct, and one for the table itself.
Also refactors the table rendering code to be easier to maintain.
This allows us to use Line as a child of other widgets, and to use
Line::render() to render it rather than calling buffer.set_line().
```rust
frame.render_widget(Line::raw("Hello, world!"), area);
// or
Line::raw("Hello, world!").render(frame, area);
```
- The `Line` struct now stores the style of the line rather than each
`Span` storing it.
- Adds two new setters for style and spans
- Adds missing docs
BREAKING CHANGE: `Line::style` is now a field of `Line` instead of being
stored in each `Span`.
Previously, if `.widths` was not called before rendering a `Table`, no
content would render in the area of the table. This commit changes that
behaviour to default to equal widths for each column.
Fixes#510.
Co-authored-by: joshcbrown <80245312+joshcbrown@users.noreply.github.com>
This allows us to use Span as a child of other widgets, and to use
Span::render() to render it rather than calling buffer.set_span().
```rust
frame.render_widget(Span::raw("Hello, world!"), area);
// or
Span::raw("Hello, world!").render(frame, area);
// or even
"Hello, world!".green().render(frame, area);
```
The deserialize implementation for Color used to support only the enum
names (e.g. Color, LightRed, etc.) With this change, you can use any of
the strings supported by the FromStr implementation (e.g. black,
light-red, #00ff00, etc.)
Automatically detect breaking changes based on commit messages
and bump the alpha release number accordingly.
E.g. v0.23.1-alpha.1 will be bumped to v0.24.0-alpha.0 if any commit
since v0.23.0 has a breaking change.
- Refactor the `table` module for better top to bottom readability by
putting types first and arranging them in a logical order (Table, Row,
Cell, other).
- Adds new methods for:
- `Table::rows`
- `Row::cells`
- `Cell::new`
- `Cell::content`
- `TableState::new`
- `TableState::selected_mut`
- Makes `HighlightSpacing::should_add` pub(crate) since it's an internal
detail.
- Adds tests for all the new methods and simple property tests for all
the other setter methods.
Adds helper methods that convert from iterators of u16 values to the
specific Constraint type. This makes it easy to create constraints like:
```rust
// a fixed layout
let constraints = Constraint::from_lengths([10, 20, 10]);
// a centered layout
let constraints = Constraint::from_ratios([(1, 4), (1, 2), (1, 4)]);
let constraints = Constraint::from_percentages([25, 50, 25]);
// a centered layout with a minimum size
let constraints = Constraint::from_mins([0, 100, 0]);
// a sidebar / main layout with maximum sizes
let constraints = Constraint::from_maxes([30, 200]);
```
The previous name `start_corner` did not communicate clearly the intent of the method.
A new method `direction` and a new enum `ListDirection` were added.
`start_corner` is now deprecated
Structs and enums at the top of the file helps show the interaction
between the types without having to find each type in between longer
impl sections.
Also moved the try_split function into the Layout impl as an associated
function and inlined the `layout::split()` which just called try_split.
This makes the code a bit more contained.
This allows to build list like
```
List::new(["Item 1", "Item 2"])
```
BREAKING CHANGE: `List::new` parameter type changed from `Into<Vec<ListItem<'a>>>`
to `IntoIterator<Item = Into<ListItem<'a>>>`
Fixes#650
This PR corrects the "builder methods" expressing to simple `setters`
(see #650#655), and gives a clearer diagnostic notice on setters `must_use`.
`#[must_use = "method moves the value of self and returns the modified value"]`
Details:
docs: Correct wording in docs from builder methods
Add `must_use` on layout setters
chore: add `must_use` on widgets fluent methods
This commit ignored `table.rs` because it is included in other PRs.
test(gauge): fix test