pub struct Checkbox<'a> { /* private fields */ }Expand description
A widget that displays a checkbox with a label.
A Checkbox can be in a checked or unchecked state. The checkbox is rendered with a symbol
(default ☐ for unchecked and ☑ for checked) followed by a label.
The widget can be styled using Checkbox::style which affects both the checkbox symbol and
the label. You can also style just the checkbox symbol using Checkbox::checkbox_style or
the label using Checkbox::label_style.
You can create a Checkbox using Checkbox::new or Checkbox::default.
§Examples
use ratatui::style::{Color, Style, Stylize};
use tui_checkbox::Checkbox;
Checkbox::new("Enable feature", true)
.style(Style::default().fg(Color::White))
.checkbox_style(Style::default().fg(Color::Green))
.label_style(Style::default().fg(Color::Gray));With a block:
use ratatui::widgets::Block;
use tui_checkbox::Checkbox;
Checkbox::new("Accept terms", false).block(Block::bordered().title("Settings"));Implementations§
Source§impl<'a> Checkbox<'a>
impl<'a> Checkbox<'a>
Sourcepub fn new<T>(label: T, checked: bool) -> Self
pub fn new<T>(label: T, checked: bool) -> Self
Creates a new Checkbox with the given label and checked state.
§Examples
use tui_checkbox::Checkbox;
let checkbox = Checkbox::new("Enable feature", true);With styled label:
use ratatui::style::Stylize;
use tui_checkbox::Checkbox;
let checkbox = Checkbox::new("Enable feature".blue(), false);Sourcepub const fn checked(self, checked: bool) -> Self
pub const fn checked(self, checked: bool) -> Self
Sets the checked state of the checkbox.
§Examples
use tui_checkbox::Checkbox;
let checkbox = Checkbox::default().checked(true);Sourcepub fn block(self, block: Block<'a>) -> Self
pub fn block(self, block: Block<'a>) -> Self
Wraps the checkbox with the given block.
§Examples
use ratatui::widgets::Block;
use tui_checkbox::Checkbox;
let checkbox = Checkbox::new("Option", false).block(Block::bordered().title("Settings"));Sourcepub fn style<S: Into<Style>>(self, style: S) -> Self
pub fn style<S: Into<Style>>(self, style: S) -> Self
Sets the base style of the widget.
style accepts any type that is convertible to Style (e.g. Style, Color, or
your own type that implements Into<Style>).
This style will be applied to both the checkbox symbol and the label unless overridden by more specific styles.
§Examples
use ratatui::style::{Color, Style};
use tui_checkbox::Checkbox;
let checkbox = Checkbox::new("Option", false).style(Style::default().fg(Color::White));Sourcepub fn checkbox_style<S: Into<Style>>(self, style: S) -> Self
pub fn checkbox_style<S: Into<Style>>(self, style: S) -> Self
Sets the style of the checkbox symbol.
style accepts any type that is convertible to Style (e.g. Style, Color, or
your own type that implements Into<Style>).
This style will be combined with the base style set by Checkbox::style.
§Examples
use ratatui::style::{Color, Style};
use tui_checkbox::Checkbox;
let checkbox = Checkbox::new("Option", true).checkbox_style(Style::default().fg(Color::Green));Sourcepub fn label_style<S: Into<Style>>(self, style: S) -> Self
pub fn label_style<S: Into<Style>>(self, style: S) -> Self
Sets the style of the label text.
style accepts any type that is convertible to Style (e.g. Style, Color, or
your own type that implements Into<Style>).
This style will be combined with the base style set by Checkbox::style.
§Examples
use ratatui::style::{Color, Style};
use tui_checkbox::Checkbox;
let checkbox = Checkbox::new("Option", false).label_style(Style::default().fg(Color::Gray));Sourcepub fn checked_symbol<T>(self, symbol: T) -> Self
pub fn checked_symbol<T>(self, symbol: T) -> Self
Sets the symbol to use when the checkbox is checked.
The default is ☑ (U+2611).
§Examples
use tui_checkbox::Checkbox;
let checkbox = Checkbox::new("Option", true).checked_symbol("[X]");Trait Implementations§
impl<'a> Eq for Checkbox<'a>
impl<'a> StructuralPartialEq for Checkbox<'a>
Auto Trait Implementations§
impl<'a> Freeze for Checkbox<'a>
impl<'a> RefUnwindSafe for Checkbox<'a>
impl<'a> Send for Checkbox<'a>
impl<'a> Sync for Checkbox<'a>
impl<'a> Unpin for Checkbox<'a>
impl<'a> UnwindSafe for Checkbox<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<'a, T, U> Stylize<'a, T> for Uwhere
U: Styled<Item = T>,
impl<'a, T, U> Stylize<'a, T> for Uwhere
U: Styled<Item = T>,
fn bg<C>(self, color: C) -> T
fn fg<C>(self, color: C) -> T
fn add_modifier(self, modifier: Modifier) -> T
fn remove_modifier(self, modifier: Modifier) -> T
fn reset(self) -> T
Source§fn on_magenta(self) -> T
fn on_magenta(self) -> T
magenta.Source§fn on_dark_gray(self) -> T
fn on_dark_gray(self) -> T
dark_gray.Source§fn on_light_red(self) -> T
fn on_light_red(self) -> T
light_red.Source§fn light_green(self) -> T
fn light_green(self) -> T
light_green.Source§fn on_light_green(self) -> T
fn on_light_green(self) -> T
light_green.Source§fn light_yellow(self) -> T
fn light_yellow(self) -> T
light_yellow.Source§fn on_light_yellow(self) -> T
fn on_light_yellow(self) -> T
light_yellow.Source§fn light_blue(self) -> T
fn light_blue(self) -> T
light_blue.Source§fn on_light_blue(self) -> T
fn on_light_blue(self) -> T
light_blue.Source§fn light_magenta(self) -> T
fn light_magenta(self) -> T
light_magenta.Source§fn on_light_magenta(self) -> T
fn on_light_magenta(self) -> T
light_magenta.Source§fn light_cyan(self) -> T
fn light_cyan(self) -> T
light_cyan.Source§fn on_light_cyan(self) -> T
fn on_light_cyan(self) -> T
light_cyan.Source§fn not_italic(self) -> T
fn not_italic(self) -> T
ITALIC modifier.Source§fn underlined(self) -> T
fn underlined(self) -> T
UNDERLINED modifier.Source§fn not_underlined(self) -> T
fn not_underlined(self) -> T
UNDERLINED modifier.Source§fn slow_blink(self) -> T
fn slow_blink(self) -> T
SLOW_BLINK modifier.Source§fn not_slow_blink(self) -> T
fn not_slow_blink(self) -> T
SLOW_BLINK modifier.Source§fn rapid_blink(self) -> T
fn rapid_blink(self) -> T
RAPID_BLINK modifier.Source§fn not_rapid_blink(self) -> T
fn not_rapid_blink(self) -> T
RAPID_BLINK modifier.Source§fn not_reversed(self) -> T
fn not_reversed(self) -> T
REVERSED modifier.HIDDEN modifier.HIDDEN modifier.Source§fn crossed_out(self) -> T
fn crossed_out(self) -> T
CROSSED_OUT modifier.Source§fn not_crossed_out(self) -> T
fn not_crossed_out(self) -> T
CROSSED_OUT modifier.