tui-checkbox
A customizable checkbox widget for Ratatui TUI applications.
Preview
Features
- ☑️ Simple checkbox with label
- 🎨 Customizable styling for checkbox and label separately
- 🔤 Custom symbols (unicode, emoji, ASCII)
- 📦 Block wrapper - optional
- 📍 Label positioning (right, left, top, bottom) - optional
- ↔️ Horizontal & vertical alignment - optional
- 📏 Width constraints (min/max) - optional
- 📝 Text wrapping for long labels - optional
- ⚡ Zero-cost abstractions
Installation
Add this to your Cargo.toml:
[]
= "0.2.0"
= "0.29"
Or install with cargo:
Quick Start
use ;
use Checkbox;
// Basic checkbox
let checkbox = new;
// Styled checkbox
let checkbox = new
.style
.checkbox_style
.label_style;
// Custom symbols
let checkbox = new
.checked_symbol
.unchecked_symbol;
// With a block
use Block;
let checkbox = new
.block;
Label Positioning
Control where the label appears relative to the checkbox symbol.
Note: All layout features are optional! The checkbox works perfectly with sensible defaults. Only use these methods when you need to customize the layout.
use ;
// Simple checkbox - works great with defaults!
new;
// Label on the left (optional customization)
new
.label_position;
// Label on top (optional customization)
new
.label_position;
// Label on bottom (optional customization)
new
.label_position;
Defaults: Label on the right (standard checkbox style)
Alignment (Optional)
Align the checkbox content within its area. Only needed for specific layouts.
use ;
// Horizontal alignment (optional)
new
.horizontal_alignment;
new
.horizontal_alignment;
// Vertical alignment (optional)
new
.vertical_alignment;
new
.vertical_alignment;
Defaults: Left and top aligned
Width Constraints & Text Wrapping (Optional)
Set minimum and maximum width constraints, and enable text wrapping when needed.
// Minimum width (optional)
new
.min_width;
// Maximum width (optional)
new
.max_width;
// Text wrapping (optional - for long labels)
new
.wrap_label
.max_width;
Defaults: No width constraints, no wrapping
Layout Examples
Label Position Example
See all four label positions in action:
This demonstrates: right, left, top, and bottom label positions.

Alignment Example
See horizontal and vertical alignment:
This demonstrates:
- Horizontal alignment: left, center, right
- Vertical alignment: top, center, bottom

Width & Wrapping Example
See width constraints and text wrapping:
This demonstrates:
- Minimum and maximum width constraints
- Text wrapping (enabled vs disabled)
- Combined features

Examples
Run the included example with two modes:
Interactive Mode (Default)
Navigate and toggle checkboxes with your keyboard:
- ↑/↓ or k/j - Navigate between checkboxes
- Space - Toggle checkbox state
- Tab - Switch to API Showcase mode
- q or Esc - Quit
The interactive mode demonstrates:
- Basic checkbox with default styling
- Styled checkboxes with colors (Info, Warning, Error)
- Emoji and Unicode symbols (✅, ●, ◆)
- Custom ASCII symbols ([X], [*], [+]/[-], (X)/(O))
API Showcase Mode
Press Tab to switch to the API showcase view, which displays all available features:
- All core API methods (
new(),default(),label(),checked()) - All styling methods (
style(),checkbox_style(),label_style()) - Symbol customization (
checked_symbol(),unchecked_symbol()) - All predefined symbols from the
symbolsmodule - Advanced usage (blocks, Styled trait, method chaining)
Styling
The widget supports multiple styling options:
style(): Sets the base style for the entire widgetcheckbox_style(): Sets the style specifically for the checkbox symbollabel_style(): Sets the style specifically for the label text
Styles are applied in order: base style, then specific styles override it.
Custom Symbols
The widget comes with default Unicode checkbox symbols (☐ and ☑), but you can use any symbols:
// Emoji style
new
.checked_symbol
.unchecked_symbol;
// ASCII style
new
.checked_symbol
.unchecked_symbol;
// Circle style
new
.checked_symbol
.unchecked_symbol;
Predefined Symbols
The symbols module provides some common checkbox symbols:
symbols::CHECKED- ☑symbols::UNCHECKED- ☐symbols::CHECKED_X- [X]symbols::UNCHECKED_SPACE- [ ]symbols::CHECKED_ASTERISK- [*]symbols::CHECKED_PLUS- [+]symbols::UNCHECKED_MINUS- [-]symbols::CHECKED_PARENTHESIS_X- (X)symbols::UNCHECKED_PARENTHESIS_O- (O)
Development
Prerequisites
Install tools:
Common Tasks
# Run example
# Run tests
# Format and lint
# Check all (format, clippy, tests)
# Release check (format, clippy, test, build)
# Generate demo GIF (requires VHS)
Release Workflow
# Release to GitHub only
# Release to Gitea only (if configured)
# Release to both GitHub and Gitea
The release commands automatically:
- Bump version in Cargo.toml
- Update Cargo.lock
- Generate changelog with git-cliff
- Create git commit and tag
- Push to the selected remote(s)
Dual Hosting Commands
If you have a Gitea instance configured:
# Setup Gitea remote
# Push to both GitHub and Gitea
# Sync Gitea with GitHub
# Show configured remotes
See all available commands:
License
MIT License - see LICENSE for details.
Contributing
Contributions are welcome! Please follow these guidelines:
- Fork the repository on GitHub
- Create a feature branch from
main - Make your changes with clear commit messages
- Submit a pull request to the main repository
All contributions must be made through GitHub pull requests from your fork. Please see CONTRIBUTING.md for detailed guidelines.
Acknowledgments
This widget was created for the Ratatui ecosystem.
Special thanks to the Ratatui team for creating such an amazing TUI framework.