pub struct FocusGrid<T = WidgetId> {
pub columns: usize,
pub rows: usize,
pub cells: Vec<Option<FocusCandidate<T>>>,
pub wrap_mode: GridWrapMode,
pub accelerator: Option<GridAccelerator>,
}Expand description
A structured 2D multi-column container for deterministic grid navigation, boundary wrapping, and accelerated directional stepping.
Fields§
§columns: usizeNumber of columns in the grid.
rows: usizeNumber of rows in the grid.
cells: Vec<Option<FocusCandidate<T>>>Cells arranged in row-major order (index = row * columns + col).
wrap_mode: GridWrapModeBoundary wrapping policy when reaching edges.
accelerator: Option<GridAccelerator>Optional navigation accelerator.
Implementations§
Source§impl<T: Clone + PartialEq> FocusGrid<T>
impl<T: Clone + PartialEq> FocusGrid<T>
Sourcepub fn new(columns: usize, rows: usize) -> Self
pub fn new(columns: usize, rows: usize) -> Self
Creates a new empty focus grid with the specified dimensions.
Sourcepub fn from_candidates(
columns: usize,
candidates: Vec<FocusCandidate<T>>,
) -> Self
pub fn from_candidates( columns: usize, candidates: Vec<FocusCandidate<T>>, ) -> Self
Populates a grid from a list of candidates in row-major order.
Sourcepub fn with_wrap_mode(self, wrap_mode: GridWrapMode) -> Self
pub fn with_wrap_mode(self, wrap_mode: GridWrapMode) -> Self
Configures the grid boundary wrap mode.
Sourcepub fn with_accelerator(self, accelerator: GridAccelerator) -> Self
pub fn with_accelerator(self, accelerator: GridAccelerator) -> Self
Enables navigation acceleration with the provided accelerator.
Sourcepub fn reset_accelerator(&mut self)
pub fn reset_accelerator(&mut self)
Resets the internal accelerator if present.
Sourcepub fn set_cell(
&mut self,
col: usize,
row: usize,
candidate: Option<FocusCandidate<T>>,
)
pub fn set_cell( &mut self, col: usize, row: usize, candidate: Option<FocusCandidate<T>>, )
Sets the candidate at cell coordinate (col, row).
Sourcepub fn get_cell(&self, col: usize, row: usize) -> Option<&FocusCandidate<T>>
pub fn get_cell(&self, col: usize, row: usize) -> Option<&FocusCandidate<T>>
Retrieves the candidate at cell coordinate (col, row).
Sourcepub fn is_cell_focusable(&self, col: usize, row: usize) -> bool
pub fn is_cell_focusable(&self, col: usize, row: usize) -> bool
Returns true if the cell at (col, row) exists and is focusable.
Sourcepub fn find_position(&self, id: &T) -> Option<(usize, usize)>
pub fn find_position(&self, id: &T) -> Option<(usize, usize)>
Finds the (col, row) coordinates of a candidate by its ID.
Navigates from current_id in direction using a specified step distance and grid wrap mode.
Skips empty or non-focusable cells along the path to find the next valid focusable candidate.
Navigates from current_id in direction applying the internal accelerator if configured.
Navigates from (start_col, start_row) in direction by step units.