pub struct Widget {Show 13 fields
pub kind: WidgetKind,
pub id: Option<String>,
pub style: Style,
pub flex_dir: FlexDir,
pub children: Vec<Widget>,
pub on_click: Option<String>,
pub enabled: bool,
pub focused: bool,
pub action: Option<Action>,
pub visible: bool,
pub state: StateFlags,
pub states: Option<Box<StateStyles>>,
pub tooltip: Option<String>,
}Expand description
A single widget in the UI tree.
Fields§
§kind: WidgetKind§id: Option<String>§style: Style§flex_dir: FlexDir§children: Vec<Widget>§on_click: Option<String>§enabled: bool§focused: bool§action: Option<Action>Typed click target set by generated code (yog-kit) — like
Self::on_click, but no string to parse. See Action.
visible: boolfalse = collapsed: takes no space, isn’t drawn and can’t be hit
(its layout node is a zero rect without children).
state: StateFlagsInteraction state (hover, pressed, selected, …) the host sets each
frame — picks the Self::states patches applied when drawing.
states: Option<Box<StateStyles>>Paint-only style overrides per state (hover:bg="..." in .yui).
tooltip: Option<String>Text shown in a tooltip while the cursor rests on it (\n breaks
lines) — see crate::UiRoot::tooltip_at.
Implementations§
Source§impl Widget
impl Widget
Sourcepub fn set_tooltip(&mut self, text: impl Into<String>)
pub fn set_tooltip(&mut self, text: impl Into<String>)
Sets (empty: clears) Self::tooltip.
Sourcepub fn visible(self, v: bool) -> Widget
pub fn visible(self, v: bool) -> Widget
false = collapsed — see Widget::visible.
Sourcepub fn state_style(self, when: StateFlags, patch: StylePatch) -> Widget
pub fn state_style(self, when: StateFlags, patch: StylePatch) -> Widget
Adds a paint-only override applied while the state contains when
(later calls win over earlier ones).
Sourcepub fn get_path(&self, path: &[u16]) -> Option<&Widget>
pub fn get_path(&self, path: &[u16]) -> Option<&Widget>
The descendant at child-index path (&[] = self); None past the
tree.
Sourcepub fn get_path_mut(&mut self, path: &[u16]) -> Option<&mut Widget>
pub fn get_path_mut(&mut self, path: &[u16]) -> Option<&mut Widget>
Self::get_path, mutably.
Sourcepub fn is_interactive(&self) -> bool
pub fn is_interactive(&self) -> bool
Whether clicking it does something (an Action or on_click).
Sourcepub fn set_state_inherited(&mut self, mask: StateFlags, on: bool)
pub fn set_state_inherited(&mut self, mask: StateFlags, on: bool)
Sets (or clears) mask on this widget and its descendants, stopping
at descendants that are interactive themselves (a button in a row
keeps its own hover) — so a row’s labels follow the row’s state.
Sourcepub fn clear_state_deep(&mut self, mask: StateFlags)
pub fn clear_state_deep(&mut self, mask: StateFlags)
Clears mask on the whole subtree (interactive descendants too).
Sourcepub fn effective_style(&self) -> Cow<'_, Style>
pub fn effective_style(&self) -> Cow<'_, Style>
The style drawn: Self::style plus the Self::states patches
matching Self::state (with DISABLED while enabled is false).
Sourcepub fn effective_style_in(&self, state: StateFlags) -> Cow<'_, Style>
pub fn effective_style_in(&self, state: StateFlags) -> Cow<'_, Style>
Self::effective_style for an explicit state.
pub fn id(self, id: impl Into<String>) -> Widget
pub fn on_click(self, ev: impl Into<String>) -> Widget
pub fn child(self, w: Widget) -> Widget
Sourcepub fn w(self, w: impl Into<Units>) -> Widget
pub fn w(self, w: impl Into<Units>) -> Widget
Accepts a plain px value (0.0 = auto) or a Units directly —
e.g. .w(18.0) or .w(Units::Percent(60.0)).
pub fn h(self, h: impl Into<Units>) -> Widget
pub fn min_w(self, v: f32) -> Widget
pub fn min_h(self, v: f32) -> Widget
pub fn flex(self, v: f32) -> Widget
pub fn flex_dir(self, v: FlexDir) -> Widget
pub fn gap(self, v: f32) -> Widget
pub fn bg(self, v: Color) -> Widget
pub fn color(self, v: Color) -> Widget
pub fn align(self, v: Align) -> Widget
pub fn font_scale(self, v: f32) -> Widget
pub fn shadow(self, v: bool) -> Widget
pub fn no_wrap(self) -> Widget
pub fn focus_style(self, v: FocusStyle) -> Widget
pub fn focus_color(self, v: Color) -> Widget
pub fn dock(self, v: Dock) -> Widget
pub fn enabled(self, v: bool) -> Widget
pub fn focused(self, v: bool) -> Widget
Sourcepub fn at(self, x: f32, y: f32) -> Widget
pub fn at(self, x: f32, y: f32) -> Widget
Position absolutely at (x, y) inside the parent’s content box — see Style::pos.
Sourcepub fn ellipsis(self) -> Widget
pub fn ellipsis(self) -> Widget
Single line, cut with ... when too wide — see Style::ellipsis.
Sourcepub fn clip(self, v: bool) -> Widget
pub fn clip(self, v: bool) -> Widget
Clip children to this widget’s rect — see Style::clip.
Sourcepub fn scroll_y(self, v: f32) -> Widget
pub fn scroll_y(self, v: f32) -> Widget
Vertical scroll offset of the children — see Style::scroll_y.
Sourcepub fn scrollbar(self, v: bool) -> Widget
pub fn scrollbar(self, v: bool) -> Widget
Draw a vertical scrollbar on overflow — see Style::scrollbar.
Sourcepub fn font(self, font: impl Into<String>) -> Widget
pub fn font(self, font: impl Into<String>) -> Widget
Font for this widget’s text — see Style::font.
Sourcepub fn placeholder(self, text: impl Into<String>) -> Widget
pub fn placeholder(self, text: impl Into<String>) -> Widget
Text box: greyed text shown while it’s empty.
Sourcepub fn max_length(self, n: usize) -> Widget
pub fn max_length(self, n: usize) -> Widget
Text box: longest text allowed, in characters (0 = unlimited).
Sourcepub fn on_change(self, ev: impl Into<String>) -> Widget
pub fn on_change(self, ev: impl Into<String>) -> Widget
Text box: event name raised when the text changes.
Sourcepub fn stretch(self, stretch: Stretch) -> Widget
pub fn stretch(self, stretch: Stretch) -> Widget
Image: how it fills the widget (WPF’s Stretch).
Sourcepub fn children(self, children: impl IntoIterator<Item = Widget>) -> Widget
pub fn children(self, children: impl IntoIterator<Item = Widget>) -> Widget
Adds every widget in children, in order.
Sourcepub fn find_mut(&mut self, id: &str) -> Option<&mut Widget>
pub fn find_mut(&mut self, id: &str) -> Option<&mut Widget>
The first widget in this subtree (depth-first, self included) whose
Widget::id is id — for changing a built tree before laying it
out (dynamic text, enabled state, …).
Sourcepub fn set_text(&mut self, text: impl Into<String>) -> bool
pub fn set_text(&mut self, text: impl Into<String>) -> bool
Replaces the text of a label, button or text box; false for any
other kind.
Sourcepub fn with_source(self, source: impl Into<String>) -> Widget
pub fn with_source(self, source: impl Into<String>) -> Widget
Replaces an image’s source or a slot’s item id (other kinds: no-op).
Sourcepub fn with_count(self, n: u32) -> Widget
pub fn with_count(self, n: u32) -> Widget
Replaces an inventory slot’s stack count (other kinds: no-op).
pub fn padding(self, top: f32, right: f32, bottom: f32, left: f32) -> Widget
pub fn margin(self, top: f32, right: f32, bottom: f32, left: f32) -> Widget
Sourcepub fn cell(self, row: u16, col: u16) -> Widget
pub fn cell(self, row: u16, col: u16) -> Widget
Puts it in grid cell (row, col) (spanning one row and column) —
WPF’s Grid.Row / Grid.Column. See Self::span.
Sourcepub fn span(self, rows: u16, cols: u16) -> Widget
pub fn span(self, rows: u16, cols: u16) -> Widget
Spans rows × cols grid cells from its Self::cell — WPF’s
Grid.RowSpan / Grid.ColumnSpan (0 counts as 1).
Sourcepub fn rows(self, rows: impl IntoIterator<Item = impl Into<Track>>) -> Widget
pub fn rows(self, rows: impl IntoIterator<Item = impl Into<Track>>) -> Widget
Grid: its rows (no rows = one * row).
Sourcepub fn cols(self, cols: impl IntoIterator<Item = impl Into<Track>>) -> Widget
pub fn cols(self, cols: impl IntoIterator<Item = impl Into<Track>>) -> Widget
Grid: its columns (no columns = one * column).
Sourcepub fn row_spacing(self, v: f32) -> Widget
pub fn row_spacing(self, v: f32) -> Widget
Grid: space between rows.
Sourcepub fn col_spacing(self, v: f32) -> Widget
pub fn col_spacing(self, v: f32) -> Widget
Grid: space between columns.