ratatui::style

Trait Stylize

Source
pub trait Stylize<'a, T>: Sized {
Show 55 methods // Required methods fn bg<C: Into<Color>>(self, color: C) -> T; fn fg<C: Into<Color>>(self, color: C) -> T; fn reset(self) -> T; fn add_modifier(self, modifier: Modifier) -> T; fn remove_modifier(self, modifier: Modifier) -> T; // Provided methods fn black(self) -> T { ... } fn on_black(self) -> T { ... } fn red(self) -> T { ... } fn on_red(self) -> T { ... } fn green(self) -> T { ... } fn on_green(self) -> T { ... } fn yellow(self) -> T { ... } fn on_yellow(self) -> T { ... } fn blue(self) -> T { ... } fn on_blue(self) -> T { ... } fn magenta(self) -> T { ... } fn on_magenta(self) -> T { ... } fn cyan(self) -> T { ... } fn on_cyan(self) -> T { ... } fn gray(self) -> T { ... } fn on_gray(self) -> T { ... } fn dark_gray(self) -> T { ... } fn on_dark_gray(self) -> T { ... } fn light_red(self) -> T { ... } fn on_light_red(self) -> T { ... } fn light_green(self) -> T { ... } fn on_light_green(self) -> T { ... } fn light_yellow(self) -> T { ... } fn on_light_yellow(self) -> T { ... } fn light_blue(self) -> T { ... } fn on_light_blue(self) -> T { ... } fn light_magenta(self) -> T { ... } fn on_light_magenta(self) -> T { ... } fn light_cyan(self) -> T { ... } fn on_light_cyan(self) -> T { ... } fn white(self) -> T { ... } fn on_white(self) -> T { ... } fn bold(self) -> T { ... } fn not_bold(self) -> T { ... } fn dim(self) -> T { ... } fn not_dim(self) -> T { ... } fn italic(self) -> T { ... } fn not_italic(self) -> T { ... } fn underlined(self) -> T { ... } fn not_underlined(self) -> T { ... } fn slow_blink(self) -> T { ... } fn not_slow_blink(self) -> T { ... } fn rapid_blink(self) -> T { ... } fn not_rapid_blink(self) -> T { ... } fn reversed(self) -> T { ... } fn not_reversed(self) -> T { ... } fn hidden(self) -> T { ... } fn not_hidden(self) -> T { ... } fn crossed_out(self) -> T { ... } fn not_crossed_out(self) -> T { ... }
}
Expand description

An extension trait for styling objects.

For any type that implements Stylize, the provided methods in this trait can be used to style the type further. This trait is automatically implemented for any type that implements the Styled trait which e.g.: String, &str, Span, Style and many Widget types.

This results in much more ergonomic styling of text and widgets. For example, instead of writing:

let text = Span::styled("Hello", Style::default().fg(Color::Red).bg(Color::Blue));

You can write:

let text = "Hello".red().on_blue();

This trait implements a provided method for every color as both foreground and background (prefixed by on_), and all modifiers as both an additive and subtractive modifier (prefixed by not_). The reset() method is also provided to reset the style.

§Examples

use ratatui::{
    style::{Color, Modifier, Style, Stylize},
    text::Line,
    widgets::{Block, Paragraph},
};

let span = "hello".red().on_blue().bold();
let line = Line::from(vec![
    "hello".red().on_blue().bold(),
    "world".green().on_yellow().not_bold(),
]);
let paragraph = Paragraph::new(line).italic().underlined();
let block = Block::bordered().title("Title").on_white().bold();

Required Methods§

Source

fn bg<C: Into<Color>>(self, color: C) -> T

Source

fn fg<C: Into<Color>>(self, color: C) -> T

Source

fn reset(self) -> T

Source

fn add_modifier(self, modifier: Modifier) -> T

Source

fn remove_modifier(self, modifier: Modifier) -> T

Provided Methods§

Source

fn black(self) -> T

Sets the foreground color to black.

Source

fn on_black(self) -> T

Sets the background color to black.

Source

fn red(self) -> T

Sets the foreground color to red.

Source

fn on_red(self) -> T

Sets the background color to red.

Source

fn green(self) -> T

Sets the foreground color to green.

Source

fn on_green(self) -> T

Sets the background color to green.

Source

fn yellow(self) -> T

Sets the foreground color to yellow.

Source

fn on_yellow(self) -> T

Sets the background color to yellow.

Source

fn blue(self) -> T

Sets the foreground color to blue.

Source

fn on_blue(self) -> T

Sets the background color to blue.

Source

fn magenta(self) -> T

Sets the foreground color to magenta.

Source

fn on_magenta(self) -> T

Sets the background color to magenta.

Source

fn cyan(self) -> T

Sets the foreground color to cyan.

Source

fn on_cyan(self) -> T

Sets the background color to cyan.

Source

fn gray(self) -> T

Sets the foreground color to gray.

Source

fn on_gray(self) -> T

Sets the background color to gray.

Source

fn dark_gray(self) -> T

Sets the foreground color to dark_gray.

Source

fn on_dark_gray(self) -> T

Sets the background color to dark_gray.

Source

fn light_red(self) -> T

Sets the foreground color to light_red.

Source

fn on_light_red(self) -> T

Sets the background color to light_red.

Source

fn light_green(self) -> T

Sets the foreground color to light_green.

Source

fn on_light_green(self) -> T

Sets the background color to light_green.

Source

fn light_yellow(self) -> T

Sets the foreground color to light_yellow.

Source

fn on_light_yellow(self) -> T

Sets the background color to light_yellow.

Source

fn light_blue(self) -> T

Sets the foreground color to light_blue.

Source

fn on_light_blue(self) -> T

Sets the background color to light_blue.

Source

fn light_magenta(self) -> T

Sets the foreground color to light_magenta.

Source

fn on_light_magenta(self) -> T

Sets the background color to light_magenta.

Source

fn light_cyan(self) -> T

Sets the foreground color to light_cyan.

Source

fn on_light_cyan(self) -> T

Sets the background color to light_cyan.

Source

fn white(self) -> T

Sets the foreground color to white.

Source

fn on_white(self) -> T

Sets the background color to white.

Source

fn bold(self) -> T

Adds the BOLD modifier.

Source

fn not_bold(self) -> T

Removes the BOLD modifier.

Source

fn dim(self) -> T

Adds the DIM modifier.

Source

fn not_dim(self) -> T

Removes the DIM modifier.

Source

fn italic(self) -> T

Adds the ITALIC modifier.

Source

fn not_italic(self) -> T

Removes the ITALIC modifier.

Source

fn underlined(self) -> T

Adds the UNDERLINED modifier.

Source

fn not_underlined(self) -> T

Removes the UNDERLINED modifier.

Adds the SLOW_BLINK modifier.

Removes the SLOW_BLINK modifier.

Adds the RAPID_BLINK modifier.

Removes the RAPID_BLINK modifier.

Source

fn reversed(self) -> T

Adds the REVERSED modifier.

Source

fn not_reversed(self) -> T

Removes the REVERSED modifier.

Source

fn hidden(self) -> T

Adds the HIDDEN modifier.

Source

fn not_hidden(self) -> T

Removes the HIDDEN modifier.

Source

fn crossed_out(self) -> T

Adds the CROSSED_OUT modifier.

Source

fn not_crossed_out(self) -> T

Removes the CROSSED_OUT modifier.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'a, T, U> Stylize<'a, T> for U
where U: Styled<Item = T>,