RenderContext

Struct RenderContext 

Source
pub struct RenderContext<'a> {
    pub buffer: &'a mut Buffer,
    pub area: Rect,
    pub style: Option<&'a Style>,
    pub state: Option<&'a NodeState>,
    /* private fields */
}
Expand description

Render context passed to widgets

Fields§

§buffer: &'a mut Buffer

Buffer to render into

§area: Rect

Available area for rendering

§style: Option<&'a Style>

Computed style from CSS cascade

§state: Option<&'a NodeState>

Current widget state

Implementations§

Source§

impl<'a> RenderContext<'a>

Source

pub fn new(buffer: &'a mut Buffer, area: Rect) -> Self

Create a basic render context (without style/state)

Source

pub fn with_style(buffer: &'a mut Buffer, area: Rect, style: &'a Style) -> Self

Create a render context with style

Source

pub fn full( buffer: &'a mut Buffer, area: Rect, style: &'a Style, state: &'a NodeState, ) -> Self

Create a full render context

Source

pub fn with_transitions(self, transitions: &'a HashMap<String, f32>) -> Self

Set transition values for this render context

Source

pub fn transition(&self, property: &str) -> Option<f32>

Get current transition value for a property

Returns the interpolated value during animation, or None if no transition is active. Use this to animate properties like opacity, position offsets, etc.

§Example
let opacity = ctx.transition("opacity").unwrap_or(1.0);
Source

pub fn transition_or(&self, property: &str, default: f32) -> f32

Get transition value with a default fallback

Source

pub fn is_focused(&self) -> bool

Check if focused

Source

pub fn is_hovered(&self) -> bool

Check if hovered

Source

pub fn is_disabled(&self) -> bool

Check if disabled

Source

pub fn draw_char(&mut self, x: u16, y: u16, ch: char, fg: Color)

Draw a single character at position

Source

pub fn draw_char_bg(&mut self, x: u16, y: u16, ch: char, fg: Color, bg: Color)

Draw a character with background color

Source

pub fn draw_char_bold(&mut self, x: u16, y: u16, ch: char, fg: Color)

Draw a bold character

Source

pub fn draw_text(&mut self, x: u16, y: u16, text: &str, fg: Color)

Draw text at position

Source

pub fn draw_text_bg(&mut self, x: u16, y: u16, text: &str, fg: Color, bg: Color)

Draw text with background color

Source

pub fn draw_text_bold(&mut self, x: u16, y: u16, text: &str, fg: Color)

Draw bold text

Source

pub fn draw_hline(&mut self, x: u16, y: u16, len: u16, ch: char, fg: Color)

Draw a horizontal line

Source

pub fn draw_vline(&mut self, x: u16, y: u16, len: u16, ch: char, fg: Color)

Draw a vertical line

Source

pub fn draw_box_rounded(&mut self, x: u16, y: u16, w: u16, h: u16, fg: Color)

Draw a box with rounded corners

Source

pub fn draw_box_no_top(&mut self, x: u16, y: u16, w: u16, h: u16, fg: Color)

Draw a box without top border (for custom multi-color headers)

Use this when you want to draw your own header line with multiple colors. The caller should draw the complete top line including corners.

Source

pub fn draw_header_line( &mut self, x: u16, y: u16, width: u16, parts: &[(&str, Color)], border_color: Color, )

Draw a complete header line with corners for use with draw_box_no_top

Draws: ╭─ [content parts with colors] ─────╮

§Arguments
  • x, y - Position of header line
  • width - Total width including corners
  • parts - Content parts as (text, color) pairs
  • border_color - Color for corners and fill dashes
§Example
ctx.draw_box_no_top(x, y, width, height, BLUE);
ctx.draw_header_line(x, y, width, &[
    (" 5 jobs ", BLUE),
    ("│", FG_DIM),
    (" ✓ 3 ", GREEN),
], BLUE);
Source

pub fn draw_box_single(&mut self, x: u16, y: u16, w: u16, h: u16, fg: Color)

Draw a box with single border

Source

pub fn draw_box_double(&mut self, x: u16, y: u16, w: u16, h: u16, fg: Color)

Draw a box with double border

Source

pub fn fill(&mut self, x: u16, y: u16, w: u16, h: u16, ch: char, fg: Color)

Fill a rectangular area with a character

Source

pub fn fill_bg(&mut self, x: u16, y: u16, w: u16, h: u16, bg: Color)

Fill with background color

Source

pub fn clear(&mut self, x: u16, y: u16, w: u16, h: u16)

Clear area (fill with spaces)

Source

pub fn draw_text_clipped( &mut self, x: u16, y: u16, text: &str, fg: Color, max_width: u16, )

Draw text clipped to max_width (stops drawing at boundary)

Source

pub fn draw_text_clipped_bold( &mut self, x: u16, y: u16, text: &str, fg: Color, max_width: u16, )

Draw bold text clipped to max_width

Source

pub fn draw_text_dim(&mut self, x: u16, y: u16, text: &str, fg: Color)

Draw dimmed text

Source

pub fn draw_text_italic(&mut self, x: u16, y: u16, text: &str, fg: Color)

Draw italic text

Source

pub fn draw_text_underline(&mut self, x: u16, y: u16, text: &str, fg: Color)

Draw underlined text

Source

pub fn draw_text_centered( &mut self, x: u16, y: u16, width: u16, text: &str, fg: Color, )

Draw text centered within a given width

Source

pub fn draw_text_right( &mut self, x: u16, y: u16, width: u16, text: &str, fg: Color, )

Draw text right-aligned within a given width

Source

pub fn draw_box_titled( &mut self, x: u16, y: u16, w: u16, h: u16, title: &str, fg: Color, )

Draw a rounded box with a title on the top border

Source

pub fn draw_box_titled_single( &mut self, x: u16, y: u16, w: u16, h: u16, title: &str, fg: Color, )

Draw a single-line box with a title

Source

pub fn draw_box_titled_double( &mut self, x: u16, y: u16, w: u16, h: u16, title: &str, fg: Color, )

Draw a double-line box with a title

Source

pub fn draw_progress_bar(&mut self, config: &ProgressBarConfig)

Draw a horizontal progress bar

Draw a progress bar with custom characters

Source

pub fn draw_progress_bar_labeled( &mut self, x: u16, y: u16, bar_width: u16, progress: f32, fg: Color, )

Draw a progress bar with percentage label

Source

pub fn draw_segments( &mut self, x: u16, y: u16, segments: &[(&str, Color)], ) -> u16

Draw multiple text segments with different colors on one line

Returns the ending x position for chaining.

§Example
ctx.draw_segments(x, y, &[
    ("●", Color::GREEN),
    (" 3/5 ", Color::WHITE),
    ("mounted", Color::CYAN),
]);
Source

pub fn draw_segments_sep( &mut self, x: u16, y: u16, segments: &[(&str, Color)], sep: &str, sep_color: Color, ) -> u16

Draw segments with a separator between them

Source

pub fn draw_key_hints( &mut self, x: u16, y: u16, hints: &[(&str, &str)], key_color: Color, action_color: Color, ) -> u16

Draw key hints (key in bold color, action in dim)

§Example
ctx.draw_key_hints(x, y, &[("j/k", "Move"), ("m", "Mount")], Color::CYAN, Color::GRAY);
Source

pub fn draw_text_selectable( &mut self, x: u16, y: u16, text: &str, selected: bool, normal_color: Color, selected_color: Color, )

Draw text with selection styling (bold + highlight color when selected)

Source

pub fn metric_color( value: u8, mid: u8, high: u8, low_color: Color, mid_color: Color, high_color: Color, ) -> Color

Get color based on value thresholds (for metrics)

Returns low_color if value < mid, mid_color if value < high, else high_color

Source

pub fn css_color(&self, default: Color) -> Color

Get foreground color from CSS style or use default

This is the primary method for widgets to get their foreground color when CSS styling is enabled. It checks the computed CSS style first, falling back to the provided default.

§Example
let fg = ctx.css_color(Color::WHITE);
Source

pub fn css_background(&self, default: Color) -> Color

Get background color from CSS style or use default

Source

pub fn css_border_color(&self, default: Color) -> Color

Get border color from CSS style or use default

Source

pub fn css_opacity(&self) -> f32

Get opacity from CSS style (1.0 = fully opaque)

Source

pub fn css_visible(&self) -> bool

Check if visible according to CSS

Source

pub fn css_padding(&self) -> Spacing

Get padding from CSS style

Source

pub fn css_margin(&self) -> Spacing

Get margin from CSS style

Source

pub fn css_width(&self) -> Size

Get width from CSS style

Source

pub fn css_height(&self) -> Size

Get height from CSS style

Source

pub fn css_border_style(&self) -> BorderStyle

Get border style from CSS

Source

pub fn css_gap(&self) -> u16

Get gap from CSS style (for flex/grid layouts)

Source

pub fn resolve_fg( &self, widget_override: Option<Color>, default: Color, ) -> Color

Resolve effective foreground color considering CSS, widget state, and disabled state

Priority order:

  1. Disabled state (returns DISABLED_FG)
  2. Widget state override (if provided)
  3. CSS computed style
  4. Default fallback
§Example
let fg = ctx.resolve_fg(widget.state.effective_fg_opt(), Color::WHITE);
Source

pub fn resolve_bg( &self, widget_override: Option<Color>, default: Color, ) -> Color

Resolve effective background color considering CSS, widget state, and disabled state

Source

pub fn draw_focus_ring( &mut self, x: u16, y: u16, w: u16, h: u16, color: Color, style: FocusStyle, )

Draw a focus ring around an area

This draws a visible focus indicator around the given bounds. Use this when the widget has focus to provide visual feedback.

§Arguments
  • x, y - Top-left corner of the focused area
  • w, h - Width and height of the focused area
  • color - Color of the focus ring
  • style - Style of the focus ring
§Example
if ctx.is_focused() {
    ctx.draw_focus_ring(x, y, w, h, Color::CYAN, FocusStyle::Dotted);
}
Source

pub fn draw_focus_ring_auto( &mut self, x: u16, y: u16, w: u16, h: u16, color: Color, )

Draw a focus ring with automatic style based on context

Uses bold style for high-contrast mode, rounded for normal mode.

Source

pub fn draw_focus_underline(&mut self, x: u16, y: u16, w: u16, color: Color)

Draw a focus underline (for inline elements)

Draws an underline under the focused element.

Source

pub fn draw_focus_marker(&mut self, x: u16, y: u16, color: Color)

Draw a focus indicator at a specific position

Draws a small marker (like ▶) to indicate focus.

Source

pub fn draw_focus_marker_left(&mut self, y: u16, color: Color)

Draw a focus indicator on the left side of an item

Common pattern for list items - shows a marker when focused.

Source

pub fn invert_colors(&mut self, x: u16, y: u16, w: u16, h: u16)

Invert colors in a region (for high contrast focus indication)

Swaps foreground and background colors in the specified area.

Source

pub fn draw_focus_reverse(&mut self, x: u16, y: u16, w: u16, h: u16)

Add reverse video effect to indicate focus

Applies reverse video (swapped fg/bg colors) to the area.

Auto Trait Implementations§

§

impl<'a> Freeze for RenderContext<'a>

§

impl<'a> RefUnwindSafe for RenderContext<'a>

§

impl<'a> Send for RenderContext<'a>

§

impl<'a> Sync for RenderContext<'a>

§

impl<'a> Unpin for RenderContext<'a>

§

impl<'a> !UnwindSafe for RenderContext<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more