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§
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§
Sourcefn on_magenta(self) -> T
fn on_magenta(self) -> T
Sets the background color to magenta
.
Sourcefn on_dark_gray(self) -> T
fn on_dark_gray(self) -> T
Sets the background color to dark_gray
.
Sourcefn on_light_red(self) -> T
fn on_light_red(self) -> T
Sets the background color to light_red
.
Sourcefn light_green(self) -> T
fn light_green(self) -> T
Sets the foreground color to light_green
.
Sourcefn on_light_green(self) -> T
fn on_light_green(self) -> T
Sets the background color to light_green
.
Sourcefn light_yellow(self) -> T
fn light_yellow(self) -> T
Sets the foreground color to light_yellow
.
Sourcefn on_light_yellow(self) -> T
fn on_light_yellow(self) -> T
Sets the background color to light_yellow
.
Sourcefn light_blue(self) -> T
fn light_blue(self) -> T
Sets the foreground color to light_blue
.
Sourcefn on_light_blue(self) -> T
fn on_light_blue(self) -> T
Sets the background color to light_blue
.
Sourcefn light_magenta(self) -> T
fn light_magenta(self) -> T
Sets the foreground color to light_magenta
.
Sourcefn on_light_magenta(self) -> T
fn on_light_magenta(self) -> T
Sets the background color to light_magenta
.
Sourcefn light_cyan(self) -> T
fn light_cyan(self) -> T
Sets the foreground color to light_cyan
.
Sourcefn on_light_cyan(self) -> T
fn on_light_cyan(self) -> T
Sets the background color to light_cyan
.
Sourcefn not_italic(self) -> T
fn not_italic(self) -> T
Removes the ITALIC
modifier.
Sourcefn underlined(self) -> T
fn underlined(self) -> T
Adds the UNDERLINED
modifier.
Sourcefn not_underlined(self) -> T
fn not_underlined(self) -> T
Removes the UNDERLINED
modifier.
Sourcefn slow_blink(self) -> T
fn slow_blink(self) -> T
Adds the SLOW_BLINK
modifier.
Sourcefn not_slow_blink(self) -> T
fn not_slow_blink(self) -> T
Removes the SLOW_BLINK
modifier.
Sourcefn rapid_blink(self) -> T
fn rapid_blink(self) -> T
Adds the RAPID_BLINK
modifier.
Sourcefn not_rapid_blink(self) -> T
fn not_rapid_blink(self) -> T
Removes the RAPID_BLINK
modifier.
Sourcefn not_reversed(self) -> T
fn not_reversed(self) -> T
Removes the REVERSED
modifier.
Adds the HIDDEN
modifier.
Removes the HIDDEN
modifier.
Sourcefn crossed_out(self) -> T
fn crossed_out(self) -> T
Adds the CROSSED_OUT
modifier.
Sourcefn not_crossed_out(self) -> T
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.