pub trait FrameExt {
// Required methods
fn render_widget_ref<W: WidgetRef>(&mut self, widget: W, area: Rect);
fn render_stateful_widget_ref<W>(
&mut self,
widget: W,
area: Rect,
state: &mut W::State,
)
where W: StatefulWidgetRef;
}unstable-widget-ref only.Expand description
Extension trait for [Frame] that provides methods to render WidgetRef and
StatefulWidgetRef to the current buffer.
§Stability
This API is marked as unstable and is only available when the unstable-widget-ref
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Required Methods§
Sourcefn render_widget_ref<W: WidgetRef>(&mut self, widget: W, area: Rect)
fn render_widget_ref<W: WidgetRef>(&mut self, widget: W, area: Rect)
Render a WidgetRef to the current buffer using WidgetRef::render_ref.
Usually the area argument is the size of the current frame or a sub-area of the current
frame (which can be obtained using Layout to split the total area).
§Example
use ratatui::layout::Rect;
use ratatui::widgets::{Block, FrameExt};
let block = Block::new();
let area = Rect::new(0, 0, 5, 5);
frame.render_widget_ref(&block, area);Sourcefn render_stateful_widget_ref<W>(
&mut self,
widget: W,
area: Rect,
state: &mut W::State,
)where
W: StatefulWidgetRef,
fn render_stateful_widget_ref<W>(
&mut self,
widget: W,
area: Rect,
state: &mut W::State,
)where
W: StatefulWidgetRef,
Render a StatefulWidgetRef to the current buffer using
StatefulWidgetRef::render_ref.
Usually the area argument is the size of the current frame or a sub-area of the current
frame (which can be obtained using Layout to split the total area).
The last argument should be an instance of the StatefulWidgetRef::State associated to
the given StatefulWidgetRef.
§Example
use ratatui::layout::Rect;
use ratatui::widgets::{FrameExt, List, ListItem, ListState};
let mut state = ListState::default().with_selected(Some(1));
let list = List::new(vec![ListItem::new("Item 1"), ListItem::new("Item 2")]);
let area = Rect::new(0, 0, 5, 5);
frame.render_stateful_widget_ref(&list, area, &mut state);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.