Skip to main content

ElementRef

Struct ElementRef 

Source
pub struct ElementRef<T> { /* private fields */ }

Implementations§

Source§

impl<T> ElementRef<T>

Source

pub fn new() -> ElementRef<T>

Create a new empty ElementRef

Source

pub fn with_dirty_flag(dirty_flag: Arc<AtomicBool>) -> ElementRef<T>

Create an ElementRef with a shared dirty flag

This is used internally to share the same dirty flag across multiple refs, allowing the windowed app to check for changes.

Source

pub fn dirty_flag(&self) -> Arc<AtomicBool>

Get the dirty flag handle (for sharing with other refs)

Source

pub fn take_dirty(&self) -> bool

Check if the element was modified and clear the flag

Returns true if the element was modified since the last check.

Source

pub fn is_dirty(&self) -> bool

Check if the element was modified (without clearing)

Source

pub fn mark_dirty(&self)

Mark the element as dirty (needs rebuild)

Source

pub fn is_bound(&self) -> bool

Check if an element is bound to this reference

Source

pub fn storage(&self) -> Arc<Mutex<Option<T>>>

Get the internal storage handle for shared access

This is used by .bind() implementations to share storage between the bound element wrapper and this ref.

Source

pub fn set(&self, elem: T)

Set the element in storage (used by bind implementations)

Source

pub fn with<F, R>(&self, f: F) -> Option<R>
where F: FnOnce(&T) -> R,

Access the bound element immutably with a callback

Returns Some(result) if an element is bound, None otherwise.

§Example
let state = button_ref.with(|btn| *btn.state());
Source

pub fn with_mut<F, R>(&self, f: F) -> Option<R>
where F: FnOnce(&mut T) -> R,

Access the bound element mutably with a callback

Returns Some(result) if an element is bound, None otherwise. This is the primary way to call methods on the bound element.

§Example
// Dispatch state changes
button_ref.with_mut(|btn| {
    btn.dispatch_state(ButtonState::Pressed);
});

// Modify element styling
div_ref.with_mut(|div| {
    *div = div.swap().bg(Color::RED).rounded(8.0);
});

Note: This automatically marks the element as dirty after the callback, triggering a UI rebuild.

Source

pub fn get(&self) -> Option<T>
where T: Clone,

Get a clone of the bound element, if any

Source

pub fn replace(&self, new_elem: T) -> Option<T>

Replace the bound element with a new one, returning the old value

Note: This automatically marks the element as dirty, triggering a UI rebuild.

Source

pub fn take(&self) -> Option<T>

Take the bound element out of the reference, leaving None

Source

pub fn borrow(&self) -> ElementRefGuard<'_, T>

Borrow the bound element immutably

Returns a guard that dereferences to &T. Panics if not bound. For fallible access, use with() instead.

§Example
let state = button_ref.borrow().state();
§Panics

Panics if no element is bound to this reference.

Source

pub fn borrow_mut(&self) -> ElementRefGuardMut<'_, T>

Borrow the bound element mutably

Returns a guard that dereferences to &mut T. Panics if not bound. When the guard is dropped, the element is automatically marked dirty, triggering a UI rebuild.

For fallible access, use with_mut() instead.

§Example
// This automatically triggers a rebuild when the guard is dropped
button_ref.borrow_mut().dispatch_state(ButtonState::Hovered);
§Panics

Panics if no element is bound to this reference.

Source

pub fn get_layout_bounds(&self) -> Option<ElementBounds>

Get the computed layout bounds for this element

Returns None if layout hasn’t been computed yet or if the element is not part of the layout tree.

§Example
if let Some(bounds) = input_ref.get_layout_bounds() {
    println!("Width: {}, Height: {}", bounds.width, bounds.height);
}
Source

pub fn set_layout_bounds(&self, bounds: ElementBounds)

Set the computed layout bounds for this element

This is called internally after layout is computed to store the element’s position and dimensions.

Source

pub fn clear_layout_bounds(&self)

Clear the stored layout bounds

Called when the element is removed from the layout tree or when layout needs to be recomputed.

Source

pub fn layout_bounds_storage(&self) -> Arc<Mutex<Option<ElementBounds>>>

Get the layout bounds storage handle for sharing

This allows other parts of the system to update the layout bounds when layout is computed.

Trait Implementations§

Source§

impl<T> Clone for ElementRef<T>

Source§

fn clone(&self) -> ElementRef<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T> Default for ElementRef<T>

Source§

fn default() -> ElementRef<T>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for ElementRef<T>

§

impl<T> RefUnwindSafe for ElementRef<T>

§

impl<T> Send for ElementRef<T>
where T: Send,

§

impl<T> Sync for ElementRef<T>
where T: Send,

§

impl<T> Unpin for ElementRef<T>

§

impl<T> UnsafeUnpin for ElementRef<T>

§

impl<T> UnwindSafe for ElementRef<T>

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

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> NodeState for T
where T: Send + 'static,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Get self as Any for downcasting
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Get self as mutable Any for downcasting
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 = 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>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,