pub struct FocusAttachment { /* private fields */ }Expand description
An attachment point for a FocusNode.
Using a FocusAttachment is rarely needed, unless building something akin to the
Focus or FocusScope widgets from scratch.
Once created, a FocusNode must be attached to the widget tree by its host
StatefulWidget via a FocusAttachment object. FocusAttachments are owned by the
StatefulWidget that hosts a FocusNode or FocusScopeNode. There can be multiple
FocusAttachments for each FocusNode, but the node will only ever be attached to one
of them at a time.
This attachment is created by calling AnyFocusNode::attach, usually from the host
widget’s State::init_state method. If the widget is updated to have a different focus
node, then the new node needs to be attached in State::did_update_widget, after calling
detach on the previous FocusAttachment. Once detached, the attachment
is defunct and will no longer make changes to the FocusNode through
reparent.
Without these attachment points, it would be possible for a focus node to simultaneously be attached to more than one part of the widget tree during the build stage.
Implementations§
Source§impl FocusAttachment
impl FocusAttachment
Sourcepub fn is_attached(self: Handle<FocusAttachment>, app: &App) -> bool
pub fn is_attached(self: Handle<FocusAttachment>, app: &App) -> bool
Returns true if the associated node is attached to this attachment.
It is possible to be attached to the widget tree, but not be placed in the focus tree (i.e. to not have a parent yet in the focus tree).
Sourcepub fn detach(self: Handle<FocusAttachment>, app: &mut App)
pub fn detach(self: Handle<FocusAttachment>, app: &mut App)
Detaches the FocusNode this attachment point is associated with from the focus
tree, and disconnects it from this attachment point.
Calling AnyFocusNode::dispose will also automatically detach the node.
Sourcepub fn reparent(
self: Handle<FocusAttachment>,
app: &mut App,
parent: Option<AnyFocusNode>,
)
pub fn reparent( self: Handle<FocusAttachment>, app: &mut App, parent: Option<AnyFocusNode>, )
Ensures that the FocusNode attached at this attachment point has the proper parent
node, changing it if necessary.
If given, ensures that the given parent node is the parent of the node that is
attached at this attachment point, changing it if necessary. However, it is usually not
necessary to supply an explicit parent, since reparent will use
Focus::maybe_of to determine the correct parent node for the context given in
AnyFocusNode::attach.
If is_attached is false, then calling this method does nothing.
Should be called whenever the associated widget is rebuilt in order to maintain the focus hierarchy.
A StatefulWidget that hosts a FocusNode should call this method on the node it
hosts during its State::build or State::did_change_dependencies methods in case the
widget is moved from one location in the tree to another location that has a different
FocusScope or context.
The optional parent argument must be supplied when not using Focus and FocusScope
widgets to build the focus tree, or if there is a need to supply the parent explicitly
(which are both uncommon).
Auto Trait Implementations§
impl Forget for FocusAttachment
impl Freeze for FocusAttachment
impl Move for FocusAttachment
impl RefUnwindSafe for FocusAttachment
impl Send for FocusAttachment
impl Sync for FocusAttachment
impl Unpin for FocusAttachment
impl UnsafeUnpin for FocusAttachmentwhere
NonZeroU32Inner: UnsafeUnpin,
&'static FocusNodeVTable: UnsafeUnpin,
impl UnwindSafe for FocusAttachment
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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.