pub struct Widget {
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>>,
}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).
Implementations§
Source§impl Widget
impl Widget
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 at_path(&self, path: &[u16]) -> &Widget
pub fn at_path(&self, path: &[u16]) -> &Widget
The descendant at path. Panics on a bad path — for generated code,
whose paths are fixed when it’s generated.
Sourcepub fn at_path_mut(&mut self, path: &[u16]) -> &mut Widget
pub fn at_path_mut(&mut self, path: &[u16]) -> &mut Widget
Self::at_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: u32) -> Widget
pub fn color(self, v: u32) -> 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: u32) -> 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 region(self, region: [f32; 4]) -> Widget
pub fn region(self, region: [f32; 4]) -> Widget
Image: draw only [u, v, w, h] of it (texture pixels).
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
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Widget
impl RefUnwindSafe for Widget
impl Send for Widget
impl Sync for Widget
impl Unpin for Widget
impl UnsafeUnpin for Widget
impl UnwindSafe for Widget
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.