Skip to main content

FocusTrap

Struct FocusTrap 

Source
pub struct FocusTrap<T = WidgetId> {
    pub container_id: Option<T>,
    pub bounds: Option<FocusRect>,
    pub members: Vec<T>,
    pub boundary_policy: FocusTrapBoundaryPolicy,
    pub exit_directions: Vec<FocusDirection>,
    pub active: bool,
}
Expand description

Directional focus trap primitive that confines keyboard and spatial focus navigation to an enclosed container, dialog, or subset of widgets.

Fields§

§container_id: Option<T>

Optional container identifier associated with this trap.

§bounds: Option<FocusRect>

Optional spatial bounding rectangle of the trap in logical coordinates.

§members: Vec<T>

List of widget IDs belonging to the trapped scope.

§boundary_policy: FocusTrapBoundaryPolicy

Boundary policy applied when navigating at the trap’s edge.

§exit_directions: Vec<FocusDirection>

Directions that are permitted to escape the trap (e.g. Tab out or Down out).

§active: bool

Whether the trap is currently active.

Implementations§

Source§

impl<T: Clone + PartialEq> FocusTrap<T>

Source

pub fn new(members: Vec<T>) -> Self

Creates an active focus trap with the specified member IDs and default Wrap policy.

Source

pub fn with_container_id(self, container_id: T) -> Self

Associates a container ID with this trap.

Source

pub fn with_bounds(self, bounds: FocusRect) -> Self

Sets the spatial bounding box enclosing the trap.

Source

pub fn with_boundary_policy(self, policy: FocusTrapBoundaryPolicy) -> Self

Configures the boundary policy (Wrap, Clamp, Stop).

Source

pub fn with_exit_direction(self, direction: FocusDirection) -> Self

Adds an allowed exit direction to allow directional escape.

Source

pub fn with_active(self, active: bool) -> Self

Sets whether the trap is active.

Source

pub fn activate(&mut self)

Activates the focus trap.

Source

pub fn deactivate(&mut self)

Deactivates the focus trap.

Source

pub fn contains_candidate(&self, candidate: &FocusCandidate<T>) -> bool

Returns true if id is a member of this trap or lies within its spatial bounds.

Source

pub fn contains_id(&self, id: &T) -> bool

Returns true if id is explicitly in self.members.

Source

pub fn is_direction_trapped(&self, direction: FocusDirection) -> bool

Returns true if navigation in direction is trapped (not in exit_directions).

Source

pub fn navigate<'a>( &self, current_id: &T, current_rect: &FocusRect, candidates: &'a [FocusCandidate<T>], direction: FocusDirection, ) -> FocusTrapOutcome<'a, T>

Navigates within or out of the focus trap according to directional policies.

Trait Implementations§

Source§

impl<T: Clone> Clone for FocusTrap<T>

Source§

fn clone(&self) -> Self

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<T: Debug> Debug for FocusTrap<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T: PartialEq> PartialEq for FocusTrap<T>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T: PartialEq> StructuralPartialEq for FocusTrap<T>

Auto Trait Implementations§

§

impl<T> Forget for FocusTrap<T>

§

impl<T> Freeze for FocusTrap<T>

§

impl<T> Move for FocusTrap<T>

§

impl<T> RefUnwindSafe for FocusTrap<T>
where T: RefUnwindSafe,

§

impl<T> Send for FocusTrap<T>
where T: Send, RawVecInner: Send,

§

impl<T> Sync for FocusTrap<T>
where T: Sync, RawVecInner: Sync,

§

impl<T> Unpin for FocusTrap<T>
where T: Unpin, *const u8 is !null: Unpin,

§

impl<T> UnsafeUnpin for FocusTrap<T>

§

impl<T> UnwindSafe for FocusTrap<T>
where T: UnwindSafe, RawVecInner: UnwindSafe,

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