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: FocusTrapBoundaryPolicyBoundary 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: boolWhether the trap is currently active.
Implementations§
Source§impl<T: Clone + PartialEq> FocusTrap<T>
impl<T: Clone + PartialEq> FocusTrap<T>
Sourcepub fn new(members: Vec<T>) -> Self
pub fn new(members: Vec<T>) -> Self
Creates an active focus trap with the specified member IDs and default Wrap policy.
Sourcepub fn with_container_id(self, container_id: T) -> Self
pub fn with_container_id(self, container_id: T) -> Self
Associates a container ID with this trap.
Sourcepub fn with_bounds(self, bounds: FocusRect) -> Self
pub fn with_bounds(self, bounds: FocusRect) -> Self
Sets the spatial bounding box enclosing the trap.
Sourcepub fn with_boundary_policy(self, policy: FocusTrapBoundaryPolicy) -> Self
pub fn with_boundary_policy(self, policy: FocusTrapBoundaryPolicy) -> Self
Configures the boundary policy (Wrap, Clamp, Stop).
Sourcepub fn with_exit_direction(self, direction: FocusDirection) -> Self
pub fn with_exit_direction(self, direction: FocusDirection) -> Self
Adds an allowed exit direction to allow directional escape.
Sourcepub fn with_active(self, active: bool) -> Self
pub fn with_active(self, active: bool) -> Self
Sets whether the trap is active.
Sourcepub fn deactivate(&mut self)
pub fn deactivate(&mut self)
Deactivates the focus trap.
Sourcepub fn contains_candidate(&self, candidate: &FocusCandidate<T>) -> bool
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.
Sourcepub fn contains_id(&self, id: &T) -> bool
pub fn contains_id(&self, id: &T) -> bool
Returns true if id is explicitly in self.members.
Sourcepub fn is_direction_trapped(&self, direction: FocusDirection) -> bool
pub fn is_direction_trapped(&self, direction: FocusDirection) -> bool
Returns true if navigation in direction is trapped (not in exit_directions).
Navigates within or out of the focus trap according to directional policies.