Skip to main content

UiCtx

Trait UiCtx 

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

Source

fn heading(&mut self, text: &str)

Render a heading-sized text string.

Source

fn label(&mut self, text: &str)

Render a body-text label.

Source

fn button(&mut self, label: &str) -> ButtonResponse

Render a button and return the interaction state.

Provided Methods§

Source

fn text_input(&mut self, _text: &str) -> TextInputResponse

Render a single-line text-input field seeded with text.

Default: unsupported (supported = false, empty text).

Source

fn checkbox(&mut self, _label: &str, _checked: bool) -> CheckboxResponse

Render a checkbox labelled label in state checked.

Default: unsupported (supported = false).

Source

fn slider(&mut self, _value: f64, _range: RangeInclusive<f64>) -> SliderResponse

Render a slider over range at value.

Default: unsupported (supported = false, value 0.0).

Source

fn dropdown(&mut self, _options: &[&str], _selected: usize) -> DropdownResponse

Render a dropdown of options with selected chosen.

Default: unsupported (supported = false, selection 0).

Source

fn image(&mut self, _uri: &str, _size: Option<Size>) -> WidgetResponse

Render an image identified by uri at an optional size.

Default: unsupported (supported = false).

Source

fn separator(&mut self) -> WidgetResponse

Render a separator (horizontal/vertical rule).

Default: unsupported (supported = false).

Source

fn spacer(&mut self, _size: f32) -> WidgetResponse

Render empty space of size logical pixels along the layout axis.

Default: unsupported (supported = false).

Source

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.

Source

fn tooltip(&mut self, _text: &str) -> WidgetResponse

Attach a tooltip with text to the most recently rendered widget.

Default: unsupported (supported = false).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

fn menu_bar( &mut self, _content: &mut dyn FnMut(&mut dyn UiCtx), ) -> WidgetResponse

Render a menu bar containing content.

Default: unsupported; the closure is not invoked.

Source

fn rich_text(&mut self, _spans: &[RichTextSpan]) -> WidgetResponse

Render multi-styled text from a slice of RichTextSpans.

Default: unsupported (supported = false).

Source

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.

Source

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.

Source

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.

Source

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".

Implementors§