pub trait UiCtx {
Show 23 methods
// Required methods
fn heading(&mut self, text: &str);
fn label(&mut self, text: &str);
fn button(&mut self, label: &str) -> ButtonResponse;
// Provided methods
fn text_input(&mut self, _text: &str) -> TextInputResponse { ... }
fn checkbox(&mut self, _label: &str, _checked: bool) -> CheckboxResponse { ... }
fn slider(
&mut self,
_value: f64,
_range: RangeInclusive<f64>,
) -> SliderResponse { ... }
fn dropdown(
&mut self,
_options: &[&str],
_selected: usize,
) -> DropdownResponse { ... }
fn image(&mut self, _uri: &str, _size: Option<Size>) -> WidgetResponse { ... }
fn separator(&mut self) -> WidgetResponse { ... }
fn spacer(&mut self, _size: f32) -> WidgetResponse { ... }
fn scroll_area(
&mut self,
_content: &mut dyn FnMut(&mut dyn UiCtx),
) -> WidgetResponse { ... }
fn tooltip(&mut self, _text: &str) -> WidgetResponse { ... }
fn popup(
&mut self,
_content: &mut dyn FnMut(&mut dyn UiCtx),
) -> WidgetResponse { ... }
fn modal(
&mut self,
_title: &str,
_content: &mut dyn FnMut(&mut dyn UiCtx),
) -> WidgetResponse { ... }
fn horizontal(
&mut self,
_content: &mut dyn FnMut(&mut dyn UiCtx),
) -> WidgetResponse { ... }
fn vertical(
&mut self,
_content: &mut dyn FnMut(&mut dyn UiCtx),
) -> WidgetResponse { ... }
fn grid(
&mut self,
_cols: usize,
_content: &mut dyn FnMut(&mut dyn UiCtx),
) -> WidgetResponse { ... }
fn menu_bar(
&mut self,
_content: &mut dyn FnMut(&mut dyn UiCtx),
) -> WidgetResponse { ... }
fn rich_text(&mut self, _spans: &[RichTextSpan]) -> WidgetResponse { ... }
fn label_styled(&mut self, text: &str, _style: TextStyle) -> WidgetResponse { ... }
fn heading_styled(
&mut self,
text: &str,
_style: TextStyle,
) -> WidgetResponse { ... }
fn drag_source(
&mut self,
_id: u64,
_content: &mut dyn FnMut(&mut dyn UiCtx),
) -> WidgetResponse { ... }
fn drop_target(
&mut self,
_accept_ids: &[u64],
_content: &mut dyn FnMut(&mut dyn UiCtx),
) -> WidgetResponse { ... }
}Expand description
Rendering context passed to every Widget::render call.
The three core methods (heading, label,
button) are required: every adapter implements them.
The remaining widget methods are provided with default implementations
that return a *Response whose supported field is false (see
response). This is a deliberate design choice: an adapter that has not
overridden, say, slider reports supported == false to
the caller rather than silently rendering nothing and pretending it worked.
Adapters override the subset of extended widgets they actually support; the
rest degrade visibly. Callers branch on the supported flag to fall back.
Required Methods§
Render a button and return the interaction state.
Provided Methods§
Sourcefn text_input(&mut self, _text: &str) -> TextInputResponse
fn text_input(&mut self, _text: &str) -> TextInputResponse
Render a single-line text-input field seeded with text.
Default: unsupported (supported = false, empty text).
Sourcefn checkbox(&mut self, _label: &str, _checked: bool) -> CheckboxResponse
fn checkbox(&mut self, _label: &str, _checked: bool) -> CheckboxResponse
Render a checkbox labelled label in state checked.
Default: unsupported (supported = false).
Sourcefn slider(&mut self, _value: f64, _range: RangeInclusive<f64>) -> SliderResponse
fn slider(&mut self, _value: f64, _range: RangeInclusive<f64>) -> SliderResponse
Render a slider over range at value.
Default: unsupported (supported = false, value 0.0).
Sourcefn dropdown(&mut self, _options: &[&str], _selected: usize) -> DropdownResponse
fn dropdown(&mut self, _options: &[&str], _selected: usize) -> DropdownResponse
Render a dropdown of options with selected chosen.
Default: unsupported (supported = false, selection 0).
Sourcefn image(&mut self, _uri: &str, _size: Option<Size>) -> WidgetResponse
fn image(&mut self, _uri: &str, _size: Option<Size>) -> WidgetResponse
Render an image identified by uri at an optional size.
Default: unsupported (supported = false).
Sourcefn separator(&mut self) -> WidgetResponse
fn separator(&mut self) -> WidgetResponse
Render a separator (horizontal/vertical rule).
Default: unsupported (supported = false).
Sourcefn spacer(&mut self, _size: f32) -> WidgetResponse
fn spacer(&mut self, _size: f32) -> WidgetResponse
Render empty space of size logical pixels along the layout axis.
Default: unsupported (supported = false).
Sourcefn scroll_area(
&mut self,
_content: &mut dyn FnMut(&mut dyn UiCtx),
) -> WidgetResponse
fn scroll_area( &mut self, _content: &mut dyn FnMut(&mut dyn UiCtx), ) -> WidgetResponse
Render content inside a scrollable region.
Default: unsupported (supported = false); the closure is not
invoked, so a caller can detect non-support before side effects run.
Sourcefn tooltip(&mut self, _text: &str) -> WidgetResponse
fn tooltip(&mut self, _text: &str) -> WidgetResponse
Attach a tooltip with text to the most recently rendered widget.
Default: unsupported (supported = false).
Sourcefn popup(&mut self, _content: &mut dyn FnMut(&mut dyn UiCtx)) -> WidgetResponse
fn popup(&mut self, _content: &mut dyn FnMut(&mut dyn UiCtx)) -> WidgetResponse
Render a popup containing content.
Default: unsupported (supported = false); the closure is not invoked.
Sourcefn modal(
&mut self,
_title: &str,
_content: &mut dyn FnMut(&mut dyn UiCtx),
) -> WidgetResponse
fn modal( &mut self, _title: &str, _content: &mut dyn FnMut(&mut dyn UiCtx), ) -> WidgetResponse
Render a modal dialog titled title containing content.
Default: unsupported (supported = false); the closure is not invoked.
Sourcefn horizontal(
&mut self,
_content: &mut dyn FnMut(&mut dyn UiCtx),
) -> WidgetResponse
fn horizontal( &mut self, _content: &mut dyn FnMut(&mut dyn UiCtx), ) -> WidgetResponse
Lay out content in a horizontal row.
Default: unsupported; the closure is not invoked.
Sourcefn vertical(
&mut self,
_content: &mut dyn FnMut(&mut dyn UiCtx),
) -> WidgetResponse
fn vertical( &mut self, _content: &mut dyn FnMut(&mut dyn UiCtx), ) -> WidgetResponse
Lay out content in a vertical column.
Default: unsupported; the closure is not invoked.
Sourcefn grid(
&mut self,
_cols: usize,
_content: &mut dyn FnMut(&mut dyn UiCtx),
) -> WidgetResponse
fn grid( &mut self, _cols: usize, _content: &mut dyn FnMut(&mut dyn UiCtx), ) -> WidgetResponse
Lay out content in a grid with cols columns.
Default: unsupported; the closure is not invoked.
Render a menu bar containing content.
Default: unsupported; the closure is not invoked.
Sourcefn rich_text(&mut self, _spans: &[RichTextSpan]) -> WidgetResponse
fn rich_text(&mut self, _spans: &[RichTextSpan]) -> WidgetResponse
Render multi-styled text from a slice of RichTextSpans.
Default: unsupported (supported = false).
Sourcefn label_styled(&mut self, text: &str, _style: TextStyle) -> WidgetResponse
fn label_styled(&mut self, text: &str, _style: TextStyle) -> WidgetResponse
Render a body-text label with an explicit TextStyle.
The default implementation delegates to UiCtx::label (text is
always rendered) and ignores _style. Adapters that can honour rich
typography should override this method.
Returns WidgetResponse::supported because label is a required
method — the text is guaranteed to appear even if the style is ignored.
Sourcefn heading_styled(&mut self, text: &str, _style: TextStyle) -> WidgetResponse
fn heading_styled(&mut self, text: &str, _style: TextStyle) -> WidgetResponse
Render a heading with an explicit TextStyle.
The default implementation delegates to UiCtx::heading (text is
always rendered) and ignores _style. Adapters that can honour rich
typography should override this method.
Returns WidgetResponse::supported because heading is a required
method — the text is guaranteed to appear even if the style is ignored.
Sourcefn drag_source(
&mut self,
_id: u64,
_content: &mut dyn FnMut(&mut dyn UiCtx),
) -> WidgetResponse
fn drag_source( &mut self, _id: u64, _content: &mut dyn FnMut(&mut dyn UiCtx), ) -> WidgetResponse
Mark content as a drag source with the given id.
Default: unsupported; the closure is not invoked.
Sourcefn drop_target(
&mut self,
_accept_ids: &[u64],
_content: &mut dyn FnMut(&mut dyn UiCtx),
) -> WidgetResponse
fn drop_target( &mut self, _accept_ids: &[u64], _content: &mut dyn FnMut(&mut dyn UiCtx), ) -> WidgetResponse
Mark content as a drop target that accepts drags with any of the given accept_ids.
Default: unsupported; the closure is not invoked.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".