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]");Sourcepub fn unchecked_symbol<T>(self, symbol: T) -> Self
pub fn unchecked_symbol<T>(self, symbol: T) -> Self
Sets the symbol to use when the checkbox is unchecked.
The default is ☐ (U+2610).
§Examples
use tui_checkbox::Checkbox;
let checkbox = Checkbox::new("Option", false).unchecked_symbol("[ ]");Sourcepub const fn label_position(self, position: LabelPosition) -> Self
pub const fn label_position(self, position: LabelPosition) -> Self
Sets the position of the label relative to the checkbox symbol.
The default is LabelPosition::Right.
§Examples
use tui_checkbox::{Checkbox, LabelPosition};
let checkbox = Checkbox::new("Option", false).label_position(LabelPosition::Left);Sourcepub const fn horizontal_alignment(self, alignment: HorizontalAlignment) -> Self
pub const fn horizontal_alignment(self, alignment: HorizontalAlignment) -> Self
Sets the horizontal alignment of the checkbox content within its area.
The default is HorizontalAlignment::Left.
§Examples
use tui_checkbox::{Checkbox, HorizontalAlignment};
let checkbox = Checkbox::new("Option", false)
.horizontal_alignment(HorizontalAlignment::Center);Sourcepub const fn vertical_alignment(self, alignment: VerticalAlignment) -> Self
pub const fn vertical_alignment(self, alignment: VerticalAlignment) -> Self
Sets the vertical alignment of the checkbox content within its area.
The default is VerticalAlignment::Top.
§Examples
use tui_checkbox::{Checkbox, VerticalAlignment};
let checkbox = Checkbox::new("Option", false)
.vertical_alignment(VerticalAlignment::Center);Sourcepub const fn min_width(self, width: u16) -> Self
pub const fn min_width(self, width: u16) -> Self
Sets the minimum width constraint for the checkbox widget.
The default is no minimum width.
§Examples
use tui_checkbox::Checkbox;
let checkbox = Checkbox::new("Option", false).min_width(20);Sourcepub const fn max_width(self, width: u16) -> Self
pub const fn max_width(self, width: u16) -> Self
Sets the maximum width constraint for the checkbox widget.
The default is no maximum width.
§Examples
use tui_checkbox::Checkbox;
let checkbox = Checkbox::new("Option", false).max_width(40);Sourcepub const fn wrap_label(self, wrap: bool) -> Self
pub const fn wrap_label(self, wrap: bool) -> Self
Enables or disables label text wrapping.
When enabled, the label will wrap to multiple lines if it exceeds the available width.
The default is false (no wrapping).
§Examples
use tui_checkbox::Checkbox;
let checkbox = Checkbox::new("This is a very long label that should wrap", false)
.wrap_label(true)
.max_width(30);Trait Implementations§
Source§impl Default for Checkbox<'_>
impl Default for Checkbox<'_>
Source§fn default() -> Self
fn default() -> Self
Returns a default Checkbox widget.
The default widget has:
- Empty label
- Unchecked state
- No block
- Default style for all elements
- Unicode checkbox symbols (☐ and ☑)
- Label position on the right
- Left and top alignment
- No width constraints
- No label wrapping
§Examples
use tui_checkbox::Checkbox;
let checkbox = Checkbox::default();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.