Skip to main content

Module widgets

Module widgets 

Source
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 alignment
  • Text - Multi-line text blocks with wrapping
  • TextBlock - 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 area
  • widgets::scroll - Shared scrolling primitives (ScrollState, sizes, offsets)

§Controls Widgets

§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§

BorderChars
Character sets for drawing borders, boxes, and frames.
Container
A unified layout-managed container widget
ContainerPadding
Padding configuration for the box
FocusStyle
Styling configuration for widget focus states.
HoverTracker
Tracks hover state for widgets.
Label
A simple label widget for titles, captions, and labeling other widgets.
LinearScrollAccel
Linear constant-speed scroll acceleration
MacOSScrollAccel
macOS-style momentum scroll with friction
ScrollBox
A scrollable box widget with viewport management
Spinner
Animated loading spinner widget.
StatusBar
A status bar widget with three sections: left, center, and right.
Table
Non-interactive table widget.
TableColumn
Column specification for Table.
Text
A standalone text widget for single-line content.
TextBlock
A multi-line text widget with wrapping support.
TextInput
A single-line text input widget.
TextInputState
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.
WidgetArea
Represents a rectangular area that a widget occupies in terminal coordinates.
WindowView
A constrained view of a window that provides bounded drawing operations.

Enums§

Alignment
How to align text horizontally
BorderSide
Border side for selective border rendering
ContainerContentAlignment
Content alignment within the box
Gap
Gap size between children
LayoutDirection
Layout direction for arranging children
StatusBarPosition
Vertical position setting for status bar.
StickyEdge
Edge for sticky scrolling behavior
TextWrapMode
How TextBlock should wrap long lines
TitleAlignment
Title alignment within the box
VerticalAlignment
How to align text vertically

Traits§

ScrollAcceleration
Scroll acceleration strategy
Widget
The core trait that all widgets implement.