Skip to main content

ButtonMatrix

Struct ButtonMatrix 

Source
pub struct ButtonMatrix {
    pub style: Style,
    pub text_color: Color,
    pub button_color: Color,
    pub pressed_color: Color,
    pub checked_color: Color,
    pub disabled_color: Color,
    /* private fields */
}
Expand description

Grid of labeled buttons arranged in rows.

Populate with set_map, adjust per-button appearance via the set_button_* family, and react to Event::PressRelease or key navigation events.

§Layout

Row height is bounds.height / row_count. Within each row, button widths are computed proportionally from their ButtonMatrixButton::width field relative to the row total.

Fields§

§style: Style

Background style for the matrix container.

§text_color: Color

Color used for button labels.

§button_color: Color

Color used for the normal button background.

§pressed_color: Color

Color used when a button is pressed.

§checked_color: Color

Color used when a button is checked.

§disabled_color: Color

Color used when a button is disabled or inactive.

Implementations§

Source§

impl ButtonMatrix

Source

pub fn new(bounds: Rect) -> Self

Create an empty button matrix occupying bounds.

Call set_map to populate buttons before drawing.

Source

pub fn set_font(&mut self, font: &'static dyn FontMetrics)

Assign the font used to render this widget (FONT-00 §5); resolves to FONT_6X10 when unset.

Source

pub fn set_map(&mut self, map: &[&str])

Populate the button grid from a flat string slice.

"\n" entries are row separators; all other entries become button labels. Existing buttons and their controls are replaced.

Source

pub fn button_text(&self, id: ButtonId) -> Option<&str>

Return the label of button id, or None if id is out of range.

Source

pub fn button_count(&self) -> usize

Return the total number of buttons (excluding row separators).

Source

pub fn buttons(&self) -> Vec<&ButtonMatrixButton>

Return a flat list of all buttons in row-major order.

Source

pub fn set_button_control(&mut self, id: ButtonId, control: ButtonMatrixControl)

OR control flags into button id.

Source

pub fn clear_button_control( &mut self, id: ButtonId, control: ButtonMatrixControl, )

Remove control flags from button id.

Source

pub fn set_all_controls(&mut self, control: ButtonMatrixControl)

Set control flags on all buttons.

Source

pub fn clear_all_controls(&mut self, control: ButtonMatrixControl)

Clear control flags on all buttons.

Source

pub fn set_control_map(&mut self, map: &[ButtonMatrixControl])

Assign controls to buttons by flat index.

Extra entries are ignored; buttons without a corresponding entry are left unchanged.

Source

pub fn control(&self, id: ButtonId) -> ButtonMatrixControl

Return the control flags of button id.

Source

pub fn set_button_width(&mut self, id: ButtonId, width: u8)

Set the relative width of button id (clamped to 1..=15).

Source

pub fn button_width(&self, id: ButtonId) -> u8

Return the relative width of button id, or 1 if not found.

Source

pub fn set_selected_button(&mut self, id: ButtonId)

Set the selected (keyboard-focused) button.

Out-of-range IDs are silently ignored.

Source

pub fn selected_button(&self) -> ButtonId

Return the currently selected button.

Source

pub fn set_one_checked(&mut self, enabled: bool)

Enable or disable the one-checked constraint.

When enabling, all checked buttons except the first (lowest ID) are unchecked.

Source

pub fn one_checked(&self) -> bool

Return true when the one-checked constraint is enabled.

Source

pub fn set_button_checked(&mut self, id: ButtonId, checked: bool)

Set the checked state of button id.

When one_checked is enabled and checked is true, all other buttons are unchecked first.

Source

pub fn button_checked(&self, id: ButtonId) -> bool

Return true when button id is in the checked state.

Source

pub fn navigate_next(&mut self)

Select the next navigable button (wraps around).

Source

pub fn navigate_prev(&mut self)

Select the previous navigable button (wraps around).

Source

pub fn activate_selected(&mut self)

Activate the currently selected button.

No-ops when nothing is selected or the selected button is not navigable.

Trait Implementations§

Source§

impl Widget for ButtonMatrix

Source§

fn bounds(&self) -> Rect

Return the area this widget occupies relative to its parent.
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
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

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.