Expand description
§Widget System
A comprehensive collection of UI components for building terminal interfaces. The widget system provides both individual components that can be positioned manually, and a powerful container system for automatic layout management and responsive design.
§Core Concepts
§Widgets
All UI elements implement the Widget trait, providing consistent drawing, sizing,
and positioning behavior. Widgets handle their own content and styling, while containers
manage layout and positioning.
§Layout System
The container system automatically arranges widgets using:
- Flexible layouts: Horizontal and vertical arrangements with automatic sizing
- Padding and borders: Configurable spacing and decorative elements
- Content alignment: Center, left, right, and justified text alignment
- Responsive design: Widgets adapt to available terminal space
§Available Components
§Text Widgets
Label- Single-line text with color and alignmentText- Multi-line text blocks with wrappingTextBlock- Advanced text formatting with multiple styles
§Container Widgets
Container- Layout management with padding, borders, and alignment- [
Panel] - Bordered containers with titles and content areas
§Scroll Widgets
Viewport- Clipping + scroll offsets for content larger than its visible areawidgets::scroll- Shared scrolling primitives (ScrollState, sizes, offsets)
§Controls Widgets
Slider- Draggable value control (horizontal/vertical)ScrollBar- Scrollbar bound to a sharedScrollState
§Helper Functions
Pre-built styled components for common UI patterns:
- [
title_text], [subtitle_text] - Hierarchical headings - [
error_panel], [success_panel], [warning_panel] - Status indicators - [
progress_bar], [status_bar] - Progress and status displays - [
sidebar], [main_content_area] - Layout helpers
§Quick Examples
§Simple Text Display
use minui::prelude::*;
let label = Label::new("Hello, MinUI!")
.with_color_pair(ColorPair::new(Color::Yellow, Color::Blue));
label.draw(window)?;§Container Layout
use minui::prelude::*;
let container = Container::new(LayoutDirection::Vertical)
.with_border_style(BorderStyle::Single)
.with_padding(Padding::uniform(1));
let title = title_text("My Application");
let content = Text::new("Welcome to the main content area.");
container
.add_child(title)
.add_child(content)
.draw(window)?;§Status Dashboard
use minui::prelude::*;
// Create a dashboard with status panels
let main_container = Container::new(LayoutDirection::Vertical);
let header = header_section("System Status");
let success_msg = success_panel("All systems operational");
let warning_msg = warning_panel("High memory usage detected");
let info_card = info_card("Connected Users", "42");
main_container
.add_child(header)
.add_child(success_msg)
.add_child(warning_msg)
.add_child(info_card)
.draw(window)?;§Advanced Features
§Text Wrapping and Alignment
use minui::prelude::*;
let text = TextBlock::new("Long text that will be wrapped automatically...")
.with_wrap_mode(TextWrapMode::WordWrap)
.with_alignment(Alignment::Center)
.with_vertical_alignment(VerticalAlignment::Middle);§Custom Borders and Styling
use minui::prelude::*;
let custom_border = BorderChars {
top_left: '╭',
top_right: '╮',
bottom_left: '╰',
bottom_right: '╯',
horizontal: '─',
vertical: '│',
};
let panel = Panel::new("Custom Panel")
.with_custom_border(custom_border)
.with_color_pair(ColorPair::new(Color::Cyan, Color::Black));§Performance Tips
- Use containers for automatic layout instead of manual positioning
- Reuse widget instances when possible rather than creating new ones each frame
- Prefer helper functions for common patterns - they’re optimized and consistent
- Use appropriate text wrapping modes for your content length and update frequency
Re-exports§
pub use controls::ArrowButton;pub use controls::ArrowDirection;pub use controls::ScrollBar;pub use controls::ScrollBarOptions;pub use controls::ScrollUnit;pub use controls::Slider;pub use controls::SliderOptions;pub use controls::SliderOrientation;pub use scroll::state::ScrollOffset;pub use scroll::state::ScrollOrientation;pub use scroll::state::ScrollSize;pub use scroll::state::ScrollState;
Modules§
- controls
- Controls widgets (interactive UI primitives).
- scroll
- Scroll-related primitives for MinUI widgets.
Structs§
- Border
Chars - Character sets for drawing borders, boxes, and frames.
- Container
- A unified layout-managed container widget
- Container
Padding - Padding configuration for the box
- Focus
Style - Styling configuration for widget focus states.
- Hover
Tracker - Tracks hover state for widgets.
- Label
- A simple label widget for titles, captions, and labeling other widgets.
- Linear
Scroll Accel - Linear constant-speed scroll acceleration
- MacOS
Scroll Accel - macOS-style momentum scroll with friction
- Scroll
Box - A scrollable box widget with viewport management
- Spinner
- Animated loading spinner widget.
- Status
Bar - A status bar widget with three sections: left, center, and right.
- Table
- Non-interactive table widget.
- Table
Column - Column specification for
Table. - Text
- A standalone text widget for single-line content.
- Text
Block - A multi-line text widget with wrapping support.
- Text
Input - A single-line text input widget.
- Text
Input State - Persistent state for a
TextInput. - Tooltip
- A tooltip that displays text on hover.
- Viewport
- A scrollable viewport widget that displays content larger than its visible area.
- Widget
Area - Represents a rectangular area that a widget occupies in terminal coordinates.
- Window
View - A constrained view of a window that provides bounded drawing operations.
Enums§
- Alignment
- How to align text horizontally
- Border
Side - Border side for selective border rendering
- Container
Content Alignment - Content alignment within the box
- Gap
- Gap size between children
- Layout
Direction - Layout direction for arranging children
- Status
BarPosition - Vertical position setting for status bar.
- Sticky
Edge - Edge for sticky scrolling behavior
- Text
Wrap Mode - How TextBlock should wrap long lines
- Title
Alignment - Title alignment within the box
- Vertical
Alignment - How to align text vertically
Traits§
- Scroll
Acceleration - Scroll acceleration strategy
- Widget
- The core trait that all widgets implement.