Skip to main content

Widget

Struct Widget 

Source
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: bool

false = collapsed: takes no space, isn’t drawn and can’t be hit (its layout node is a zero rect without children).

§state: StateFlags

Interaction 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

Source

pub fn action(self, a: Action) -> Widget

Typed click target — see Action.

Source

pub fn visible(self, v: bool) -> Widget

false = collapsed — see Widget::visible.

Source

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

Source

pub fn get_path(&self, path: &[u16]) -> Option<&Widget>

The descendant at child-index path (&[] = self); None past the tree.

Source

pub fn get_path_mut(&mut self, path: &[u16]) -> Option<&mut Widget>

Self::get_path, mutably.

Source

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.

Source

pub fn at_path_mut(&mut self, path: &[u16]) -> &mut Widget

Self::at_path, mutably.

Source

pub fn is_interactive(&self) -> bool

Whether clicking it does something (an Action or on_click).

Source

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.

Source

pub fn clear_state_deep(&mut self, mask: StateFlags)

Clears mask on the whole subtree (interactive descendants too).

Source

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

Source

pub fn effective_style_in(&self, state: StateFlags) -> Cow<'_, Style>

Self::effective_style for an explicit state.

Source

pub fn id(self, id: impl Into<String>) -> Widget

Source

pub fn on_click(self, ev: impl Into<String>) -> Widget

Source

pub fn child(self, w: Widget) -> Widget

Source

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

Source

pub fn h(self, h: impl Into<Units>) -> Widget

Source

pub fn min_w(self, v: f32) -> Widget

Source

pub fn min_h(self, v: f32) -> Widget

Source

pub fn flex(self, v: f32) -> Widget

Source

pub fn flex_dir(self, v: FlexDir) -> Widget

Source

pub fn gap(self, v: f32) -> Widget

Source

pub fn bg(self, v: u32) -> Widget

Source

pub fn color(self, v: u32) -> Widget

Source

pub fn align(self, v: Align) -> Widget

Source

pub fn font_scale(self, v: f32) -> Widget

Source

pub fn shadow(self, v: bool) -> Widget

Source

pub fn no_wrap(self) -> Widget

Source

pub fn focus_style(self, v: FocusStyle) -> Widget

Source

pub fn focus_color(self, v: u32) -> Widget

Source

pub fn dock(self, v: Dock) -> Widget

Source

pub fn enabled(self, v: bool) -> Widget

Source

pub fn focused(self, v: bool) -> Widget

Source

pub fn at(self, x: f32, y: f32) -> Widget

Position absolutely at (x, y) inside the parent’s content box — see Style::pos.

Source

pub fn ellipsis(self) -> Widget

Single line, cut with ... when too wide — see Style::ellipsis.

Source

pub fn clip(self, v: bool) -> Widget

Clip children to this widget’s rect — see Style::clip.

Source

pub fn scroll_y(self, v: f32) -> Widget

Vertical scroll offset of the children — see Style::scroll_y.

Source

pub fn scrollbar(self, v: bool) -> Widget

Draw a vertical scrollbar on overflow — see Style::scrollbar.

Source

pub fn font(self, font: impl Into<String>) -> Widget

Font for this widget’s text — see Style::font.

Source

pub fn placeholder(self, text: impl Into<String>) -> Widget

Text box: greyed text shown while it’s empty.

Source

pub fn max_length(self, n: usize) -> Widget

Text box: longest text allowed, in characters (0 = unlimited).

Source

pub fn on_change(self, ev: impl Into<String>) -> Widget

Text box: event name raised when the text changes.

Source

pub fn on_submit(self, ev: impl Into<String>) -> Widget

Text box: event name raised by Enter.

Source

pub fn stretch(self, stretch: Stretch) -> Widget

Image: how it fills the widget (WPF’s Stretch).

Source

pub fn region(self, region: [f32; 4]) -> Widget

Image: draw only [u, v, w, h] of it (texture pixels).

Source

pub fn tint(self, tint: u32) -> Widget

Image: multiply its colors by tint (0xAARRGGBB).

Source

pub fn children(self, children: impl IntoIterator<Item = Widget>) -> Widget

Adds every widget in children, in order.

Source

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, …).

Source

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.

Source

pub fn with_text(self, text: impl Into<String>) -> Widget

set_text as a builder call.

Source

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

Source

pub fn with_count(self, n: u32) -> Widget

Replaces an inventory slot’s stack count (other kinds: no-op).

Source

pub fn padding(self, top: f32, right: f32, bottom: f32, left: f32) -> Widget

Source

pub fn margin(self, top: f32, right: f32, bottom: f32, left: f32) -> Widget

Trait Implementations§

Source§

impl Clone for Widget

Source§

fn clone(&self) -> Widget

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Widget

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.