Skip to main content

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 RenderContext<'_>

Source

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

Get foreground color from CSS style or use default

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§

impl RenderContext<'_>

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

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

Source

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

Draw a focus underline (for inline elements)

Source

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

Draw a focus indicator at a specific position

Source

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

Draw a focus indicator on the left side of an item

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)

Source

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

Add reverse video effect to indicate focus

Source§

impl RenderContext<'_>

Source

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

Draw a horizontal progress bar

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§

impl RenderContext<'_>

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

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)

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)

Source§

impl RenderContext<'_>

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)

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

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

impl RenderContext<'_>

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_text_bg_bold( &mut self, x: u16, y: u16, text: &str, fg: Color, bg: Color, )

Draw bold text with background color

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§

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

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

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> UnsafeUnpin 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, 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, 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.