Skip to main content

Tileview

Struct Tileview 

Source
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: Style

Overall background style (Part::MAIN).

§tile_color: Color

Background color drawn for the active tile area.

Implementations§

Source§

impl Tileview

Source

pub const TILE_NONE: TileId

Sentinel TileId meaning “no tile selected / invalid”.

Source

pub fn new(bounds: Rect) -> Self

Create a tileview with no tiles.

Source

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.

Source

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.

Source

pub fn active_tile(&self) -> TileId

Return the TileId of the currently active tile, or TILE_NONE.

Source

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.

Source

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.

Source

pub fn navigate_up(&mut self)

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

Source

pub fn navigate_down(&mut self)

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

Source

pub fn navigate_left(&mut self)

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

Source

pub fn navigate_right(&mut self)

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

Source§

fn bounds(&self) -> Rect

Return the area this widget occupies relative to its parent.
Source§

fn set_bounds(&mut self, bounds: Rect)

Called by the LPAR-10 layout pass to notify this widget of its layout-computed bounds. Read more
Source§

fn draw(&self, renderer: &mut dyn Renderer)

Render the widget using the provided Renderer.
Source§

fn handle_event(&mut self, _event: &Event) -> bool

Handle an event and return true if it was consumed. Read more
Source§

fn clear_region(&mut self) -> Option<Rect>

Return a region (in draw/landscape coordinates) that should be restored from the pristine background copy, or None. Read more
Source§

fn widget_font_mut(&mut self) -> Option<&mut WidgetFont>

Expose this widget’s font slot for cascade-driven font resolution (FONT-05 §5.B). Read more

Auto Trait Implementations§

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.