pub struct ElementRef<T> { /* private fields */ }Implementations§
Source§impl<T> ElementRef<T>
impl<T> ElementRef<T>
Sourcepub fn new() -> ElementRef<T>
pub fn new() -> ElementRef<T>
Create a new empty ElementRef
Sourcepub fn with_dirty_flag(dirty_flag: Arc<AtomicBool>) -> ElementRef<T>
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.
Sourcepub fn dirty_flag(&self) -> Arc<AtomicBool>
pub fn dirty_flag(&self) -> Arc<AtomicBool>
Get the dirty flag handle (for sharing with other refs)
Sourcepub fn take_dirty(&self) -> bool
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.
Sourcepub fn mark_dirty(&self)
pub fn mark_dirty(&self)
Mark the element as dirty (needs rebuild)
Sourcepub fn storage(&self) -> Arc<Mutex<Option<T>>>
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.
Sourcepub fn with_mut<F, R>(&self, f: F) -> Option<R>
pub fn with_mut<F, R>(&self, f: F) -> Option<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.
Sourcepub fn replace(&self, new_elem: T) -> Option<T>
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.
Sourcepub fn borrow(&self) -> ElementRefGuard<'_, T>
pub fn borrow(&self) -> ElementRefGuard<'_, T>
Sourcepub fn borrow_mut(&self) -> ElementRefGuardMut<'_, T>
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.
Sourcepub fn get_layout_bounds(&self) -> Option<ElementBounds>
pub fn get_layout_bounds(&self) -> Option<ElementBounds>
Sourcepub fn set_layout_bounds(&self, bounds: ElementBounds)
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.
Sourcepub fn clear_layout_bounds(&self)
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.
Sourcepub fn layout_bounds_storage(&self) -> Arc<Mutex<Option<ElementBounds>>>
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>
impl<T> Clone for ElementRef<T>
Source§fn clone(&self) -> ElementRef<T>
fn clone(&self) -> ElementRef<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T> Default for ElementRef<T>
impl<T> Default for ElementRef<T>
Source§fn default() -> ElementRef<T>
fn default() -> ElementRef<T>
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> 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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.