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 BufferBuffer to render into
area: RectAvailable 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>
impl<'a> RenderContext<'a>
Sourcepub fn new(buffer: &'a mut Buffer, area: Rect) -> Self
pub fn new(buffer: &'a mut Buffer, area: Rect) -> Self
Create a basic render context (without style/state)
Sourcepub fn with_style(buffer: &'a mut Buffer, area: Rect, style: &'a Style) -> Self
pub fn with_style(buffer: &'a mut Buffer, area: Rect, style: &'a Style) -> Self
Create a render context with style
Sourcepub fn full(
buffer: &'a mut Buffer,
area: Rect,
style: &'a Style,
state: &'a NodeState,
) -> Self
pub fn full( buffer: &'a mut Buffer, area: Rect, style: &'a Style, state: &'a NodeState, ) -> Self
Create a full render context
Sourcepub fn with_transitions(self, transitions: &'a HashMap<String, f32>) -> Self
pub fn with_transitions(self, transitions: &'a HashMap<String, f32>) -> Self
Set transition values for this render context
Sourcepub fn transition(&self, property: &str) -> Option<f32>
pub fn transition(&self, property: &str) -> Option<f32>
Sourcepub fn transition_or(&self, property: &str, default: f32) -> f32
pub fn transition_or(&self, property: &str, default: f32) -> f32
Get transition value with a default fallback
Sourcepub fn is_focused(&self) -> bool
pub fn is_focused(&self) -> bool
Check if focused
Sourcepub fn is_hovered(&self) -> bool
pub fn is_hovered(&self) -> bool
Check if hovered
Sourcepub fn is_disabled(&self) -> bool
pub fn is_disabled(&self) -> bool
Check if disabled
Sourcepub fn draw_char(&mut self, x: u16, y: u16, ch: char, fg: Color)
pub fn draw_char(&mut self, x: u16, y: u16, ch: char, fg: Color)
Draw a single character at position
Sourcepub fn draw_char_bg(&mut self, x: u16, y: u16, ch: char, fg: Color, bg: Color)
pub fn draw_char_bg(&mut self, x: u16, y: u16, ch: char, fg: Color, bg: Color)
Draw a character with background color
Sourcepub fn draw_text_bg(&mut self, x: u16, y: u16, text: &str, fg: Color, bg: Color)
pub fn draw_text_bg(&mut self, x: u16, y: u16, text: &str, fg: Color, bg: Color)
Draw text with background color
Sourcepub fn draw_hline(&mut self, x: u16, y: u16, len: u16, ch: char, fg: Color)
pub fn draw_hline(&mut self, x: u16, y: u16, len: u16, ch: char, fg: Color)
Draw a horizontal line
Sourcepub fn draw_vline(&mut self, x: u16, y: u16, len: u16, ch: char, fg: Color)
pub fn draw_vline(&mut self, x: u16, y: u16, len: u16, ch: char, fg: Color)
Draw a vertical line
Sourcepub fn draw_box_rounded(&mut self, x: u16, y: u16, w: u16, h: u16, fg: Color)
pub fn draw_box_rounded(&mut self, x: u16, y: u16, w: u16, h: u16, fg: Color)
Draw a box with rounded corners
Sourcepub fn draw_box_no_top(&mut self, x: u16, y: u16, w: u16, h: u16, fg: Color)
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.
Sourcepub fn draw_header_line(
&mut self,
x: u16,
y: u16,
width: u16,
parts: &[(&str, Color)],
border_color: Color,
)
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 linewidth- Total width including cornersparts- Content parts as (text, color) pairsborder_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);Sourcepub fn draw_box_single(&mut self, x: u16, y: u16, w: u16, h: u16, fg: Color)
pub fn draw_box_single(&mut self, x: u16, y: u16, w: u16, h: u16, fg: Color)
Draw a box with single border
Sourcepub fn draw_box_double(&mut self, x: u16, y: u16, w: u16, h: u16, fg: Color)
pub fn draw_box_double(&mut self, x: u16, y: u16, w: u16, h: u16, fg: Color)
Draw a box with double border
Sourcepub fn fill(&mut self, x: u16, y: u16, w: u16, h: u16, ch: char, fg: Color)
pub fn fill(&mut self, x: u16, y: u16, w: u16, h: u16, ch: char, fg: Color)
Fill a rectangular area with a character
Sourcepub fn fill_bg(&mut self, x: u16, y: u16, w: u16, h: u16, bg: Color)
pub fn fill_bg(&mut self, x: u16, y: u16, w: u16, h: u16, bg: Color)
Fill with background color
Sourcepub fn draw_text_clipped(
&mut self,
x: u16,
y: u16,
text: &str,
fg: Color,
max_width: u16,
)
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)
Sourcepub fn draw_text_clipped_bold(
&mut self,
x: u16,
y: u16,
text: &str,
fg: Color,
max_width: u16,
)
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
Sourcepub fn draw_text_underline(&mut self, x: u16, y: u16, text: &str, fg: Color)
pub fn draw_text_underline(&mut self, x: u16, y: u16, text: &str, fg: Color)
Draw underlined text
Sourcepub fn draw_text_centered(
&mut self,
x: u16,
y: u16,
width: u16,
text: &str,
fg: Color,
)
pub fn draw_text_centered( &mut self, x: u16, y: u16, width: u16, text: &str, fg: Color, )
Draw text centered within a given width
Sourcepub fn draw_text_right(
&mut self,
x: u16,
y: u16,
width: u16,
text: &str,
fg: Color,
)
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
Sourcepub fn draw_box_titled(
&mut self,
x: u16,
y: u16,
w: u16,
h: u16,
title: &str,
fg: Color,
)
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
Sourcepub fn draw_box_titled_single(
&mut self,
x: u16,
y: u16,
w: u16,
h: u16,
title: &str,
fg: Color,
)
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
Sourcepub fn draw_box_titled_double(
&mut self,
x: u16,
y: u16,
w: u16,
h: u16,
title: &str,
fg: Color,
)
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
Sourcepub fn draw_progress_bar(&mut self, config: &ProgressBarConfig)
pub fn draw_progress_bar(&mut self, config: &ProgressBarConfig)
Draw a horizontal progress bar
Draw a progress bar with custom characters
Sourcepub fn draw_progress_bar_labeled(
&mut self,
x: u16,
y: u16,
bar_width: u16,
progress: f32,
fg: Color,
)
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
Sourcepub fn draw_segments_sep(
&mut self,
x: u16,
y: u16,
segments: &[(&str, Color)],
sep: &str,
sep_color: Color,
) -> u16
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
Sourcepub fn draw_key_hints(
&mut self,
x: u16,
y: u16,
hints: &[(&str, &str)],
key_color: Color,
action_color: Color,
) -> u16
pub fn draw_key_hints( &mut self, x: u16, y: u16, hints: &[(&str, &str)], key_color: Color, action_color: Color, ) -> u16
Sourcepub fn draw_text_selectable(
&mut self,
x: u16,
y: u16,
text: &str,
selected: bool,
normal_color: Color,
selected_color: Color,
)
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)
Sourcepub fn metric_color(
value: u8,
mid: u8,
high: u8,
low_color: Color,
mid_color: Color,
high_color: Color,
) -> Color
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
Sourcepub fn css_background(&self, default: Color) -> Color
pub fn css_background(&self, default: Color) -> Color
Get background color from CSS style or use default
Sourcepub fn css_border_color(&self, default: Color) -> Color
pub fn css_border_color(&self, default: Color) -> Color
Get border color from CSS style or use default
Sourcepub fn css_opacity(&self) -> f32
pub fn css_opacity(&self) -> f32
Get opacity from CSS style (1.0 = fully opaque)
Sourcepub fn css_visible(&self) -> bool
pub fn css_visible(&self) -> bool
Check if visible according to CSS
Sourcepub fn css_padding(&self) -> Spacing
pub fn css_padding(&self) -> Spacing
Get padding from CSS style
Sourcepub fn css_margin(&self) -> Spacing
pub fn css_margin(&self) -> Spacing
Get margin from CSS style
Sourcepub fn css_height(&self) -> Size
pub fn css_height(&self) -> Size
Get height from CSS style
Sourcepub fn css_border_style(&self) -> BorderStyle
pub fn css_border_style(&self) -> BorderStyle
Get border style from CSS
Sourcepub fn resolve_bg(
&self,
widget_override: Option<Color>,
default: Color,
) -> Color
pub fn resolve_bg( &self, widget_override: Option<Color>, default: Color, ) -> Color
Resolve effective background color considering CSS, widget state, and disabled state
Sourcepub fn draw_focus_ring(
&mut self,
x: u16,
y: u16,
w: u16,
h: u16,
color: Color,
style: FocusStyle,
)
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 areaw,h- Width and height of the focused areacolor- Color of the focus ringstyle- Style of the focus ring
§Example
if ctx.is_focused() {
ctx.draw_focus_ring(x, y, w, h, Color::CYAN, FocusStyle::Dotted);
}Sourcepub fn draw_focus_ring_auto(
&mut self,
x: u16,
y: u16,
w: u16,
h: u16,
color: Color,
)
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.
Sourcepub fn draw_focus_underline(&mut self, x: u16, y: u16, w: u16, color: Color)
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.
Sourcepub fn draw_focus_marker(&mut self, x: u16, y: u16, color: Color)
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.
Sourcepub fn draw_focus_marker_left(&mut self, y: u16, color: Color)
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.
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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