Skip to main content

Ui

Struct Ui 

Source
pub struct Ui<S: 'static, H: 'static> { /* private fields */ }
Expand description

Used to construct a UI tree with the builder pattern.

Implementations§

Source§

impl<S, H> Ui<S, H>

Source

pub fn node(&mut self) -> &mut Self

Create a new node in the tree and make it the current node for subsequent builder calls to configure.

Panics: If called a second time at the root level (only one root node is allowed).

Source

pub fn id(&mut self, id: NodeId) -> &mut Self

Assign an id to the current node, providing a stable identity between build phases.

Panics: If the ID has already been assigned to a different node.

Source

pub fn classes<'a>(&mut self, classes: impl Into<Option<&'a str>>) -> &mut Self

Append a space-separated list of CSS classes to the current node.

You can pass in None to remove all classes from the current node.

Source

pub fn text(&mut self, text: impl Into<UIString>) -> &mut Self

Sets the text to be rendered inside this node.

Source

pub fn enabled(&mut self, enabled: impl Into<UIParam<bool>>) -> &mut Self

Sets whether the current node is enabled. Disabled nodes do not receive events and may be styled differently.

Accepts impl Into<UIParam> so you can pass a reactive Var or a constant bool directly.

Source

pub fn offset(&mut self, offset: impl Into<UIParam<Vec2>>) -> &mut Self

Provide an offset value to change the position of child nodes. Useful for scroll areas.

Accepts impl Into<UIParam> so you can pass a reactive Var or a constant Vec2 directly.

Source

pub fn style_sheet<'a>( &mut self, style_sheet: impl Into<Option<&'a Stylesheet>>, ) -> &mut Self

Apply a stylesheet to the current node and all of its children.

You can pass in None to remove a stylesheet from the current node. There can only be one stylesheet per node.

Source

pub fn event( &mut self, event_type: On, callback: impl Fn(&mut S, &mut EventCtx<'_, H>) + 'static, ) -> &mut Self

Register an event callback.

Source

pub fn on_style( &mut self, callback: impl Fn(&S, &mut Style) + 'static, ) -> &mut Self

Register a function to modify the current node’s style before the layout and draw phases. Useful for applying the results of an On::AnimationFrame event handler.

There can only be one on_style callback per node.

Source

pub fn on_measure( &mut self, callback: impl Fn(&S, &MeasureCtx<'_>) -> Size + 'static, ) -> &mut Self

Register a function to calculate the node’s preferred size based on the provided constraints. This overrides the node’s built-in text layout measurement.

There can only be one on_measure callback per node.

Source

pub fn on_canvas( &mut self, callback: impl Fn(&S, &mut CanvasCtx<'_>) + 'static, ) -> &mut Self

Register a function to draw arbitrary vector graphics inside the current node.

There can only be one on_canvas callback per node.

Source

pub fn on_accessibility( &mut self, f: impl for<'a> Fn(&S, &mut AccessibilityCtx<'a>) + Send + Sync + 'static, ) -> &mut Self

Register a function to construct the accessability information for the current node if the platform requests it.

There can only be one on_accessability callback per node.

Source

pub fn children(&mut self, func: impl FnOnce(&mut Ui<S, H>)) -> &mut Self

Add child nodes.

Trait Implementations§

Source§

impl<S: 'static, H: 'static> Debug for Ui<S, H>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S, H> !RefUnwindSafe for Ui<S, H>

§

impl<S, H> !Send for Ui<S, H>

§

impl<S, H> !Sync for Ui<S, H>

§

impl<S, H> !UnwindSafe for Ui<S, H>

§

impl<S, H> Freeze for Ui<S, H>

§

impl<S, H> Unpin for Ui<S, H>

§

impl<S, H> UnsafeUnpin for Ui<S, H>

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> 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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>