Skip to content

BorderWidget

BorderWidget is a stateless theme-aware wrapper around Ratatui's Block. Use it for framed sections, titled panes, and simple low-level composition. It is a paint-only widget, not a focusable component.

There is no dedicated border demo. The framed areas in the component demos use BorderWidget directly.

Basic Usage

rust
use ratcn::BorderWidget;
use ratatui::layout::Alignment;

let border = BorderWidget::new()
    .themed(&theme)
    .title(" Settings ")
    .title_alignment(Alignment::Left);

let inner = border.inner(area);
frame.render_widget(border, area);
frame.render_widget(content, inner);

Call .inner(area) before rendering if you need the content rectangle. The method mirrors Ratatui Block::inner(...).

BorderWidget API

MethodDescription
BorderWidget::new()Creates a bordered widget with default Ratatui styling.
.themed(&theme)Applies the theme's border color, foreground, background, and border style.
.inner(area)Returns the area inside the border and padding.
.title(...)Adds a title using Ratatui's default title position.
.title_top(...)Adds a top title.
.title_bottom(...)Adds a bottom title.
.title_style(...)Styles titles.
.title_alignment(...)Sets title alignment.
.title_position(...)Sets title position.
.border_color(color)Convenience for setting border foreground color.
.border_style(style)Sets full border style.
.background_color(color)Convenience for setting background color.
.style(style)Sets the underlying block style.
.borders(...)Chooses which edges are drawn.
.border_type(...)Sets Ratatui BorderType.
.border_set(...)Sets an explicit border symbol set.
.padding(...)Sets Ratatui block padding.
.map_block(...)Applies a one-off transformation to the underlying Block.
.into_block()Returns the underlying Ratatui Block.

Events

BorderWidget handles no events. Render it directly with frame.render_widget(...).

When To Use map_block Or into_block

Most uses should stay on BorderWidget methods. Use .map_block(...) when a Ratatui Block option is not surfaced yet but you still want to keep the theme-derived defaults. Use .into_block() when you need to pass the configured block to an API that specifically expects Block.

Component Borders

Input and TextArea can draw their own titled borders with .title(...). Prefer that API for those components so invalid styling and inner sizing remain consistent. Use BorderWidget for surrounding panels, demos, and custom static sections.