pub struct Tileview {
pub style: Style,
pub tile_color: Color,
/* private fields */
}Expand description
Two-dimensional snap-to-tile navigation grid.
Create with Tileview::new, register tiles with Tileview::add_tile,
and navigate with the direction helpers.
Fields§
§style: StyleOverall background style (Part::MAIN).
tile_color: ColorBackground color drawn for the active tile area.
Implementations§
Source§impl Tileview
impl Tileview
Sourcepub fn add_tile(&mut self, col: u8, row: u8, dir: TileDir) -> TileId
pub fn add_tile(&mut self, col: u8, row: u8, dir: TileDir) -> TileId
Register a tile at (col, row) with the given allowed navigation directions.
Returns the tile’s TileId. If this is the first tile, it becomes
the active tile automatically.
Sourcepub fn set_active(&mut self, id: TileId)
pub fn set_active(&mut self, id: TileId)
Make the tile with the given id active.
Snaps the view directly to the tile’s grid position.
No-op if the id is out of range or TILE_NONE.
Sourcepub fn active_tile(&self) -> TileId
pub fn active_tile(&self) -> TileId
Sourcepub fn set_active_by_index(&mut self, col: u8, row: u8)
pub fn set_active_by_index(&mut self, col: u8, row: u8)
Activate the tile at grid position (col, row).
If no tile is registered at that position, this is a no-op.
Sourcepub fn tile_bounds(&self, id: TileId) -> Rect
pub fn tile_bounds(&self, id: TileId) -> Rect
Return the content-space bounds of the tile with the given id.
Bounds are always (col * w, row * h, w, h) where w and h are
the widget viewport dimensions. Returns a zero-area rect for invalid ids.
Navigate to the tile above the current one, if allowed.
Requires TileDir::UP to be set on the active tile and a tile registered
at (col, row - 1). Wire to ObjectEvent::Key(Key::ArrowUp).
Navigate to the tile below the current one, if allowed.
Requires TileDir::DOWN on the active tile and a tile at (col, row + 1).
Wire to ObjectEvent::Key(Key::ArrowDown).
Navigate to the tile to the left of the current one, if allowed.
Requires TileDir::LEFT on the active tile and a tile at (col - 1, row).
Wire to ObjectEvent::Key(Key::ArrowLeft).
Navigate to the tile to the right of the current one, if allowed.
Requires TileDir::RIGHT on the active tile and a tile at (col + 1, row).
Wire to ObjectEvent::Key(Key::ArrowRight).
Trait Implementations§
Source§impl Widget for Tileview
impl Widget for Tileview
Source§fn set_bounds(&mut self, bounds: Rect)
fn set_bounds(&mut self, bounds: Rect)
Source§fn handle_event(&mut self, _event: &Event) -> bool
fn handle_event(&mut self, _event: &Event) -> bool
true if it was consumed. Read moreSource§fn clear_region(&mut self) -> Option<Rect>
fn clear_region(&mut self) -> Option<Rect>
None. Read more