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: StyleBackground style for the matrix container.
text_color: ColorColor used for button labels.
Color used for the normal button background.
pressed_color: ColorColor used when a button is pressed.
checked_color: ColorColor used when a button is checked.
disabled_color: ColorColor used when a button is disabled or inactive.
Implementations§
Source§impl ButtonMatrix
impl ButtonMatrix
Sourcepub fn new(bounds: Rect) -> Self
pub fn new(bounds: Rect) -> Self
Create an empty button matrix occupying bounds.
Call set_map to populate buttons before drawing.
Sourcepub fn set_font(&mut self, font: &'static dyn FontMetrics)
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.
Sourcepub fn set_map(&mut self, map: &[&str])
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.
Return the label of button id, or None if id is out of range.
Return the total number of buttons (excluding row separators).
Return a flat list of all buttons in row-major order.
OR control flags into button id.
Remove control flags from button id.
Sourcepub fn set_all_controls(&mut self, control: ButtonMatrixControl)
pub fn set_all_controls(&mut self, control: ButtonMatrixControl)
Set control flags on all buttons.
Sourcepub fn clear_all_controls(&mut self, control: ButtonMatrixControl)
pub fn clear_all_controls(&mut self, control: ButtonMatrixControl)
Clear control flags on all buttons.
Sourcepub fn set_control_map(&mut self, map: &[ButtonMatrixControl])
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.
Sourcepub fn control(&self, id: ButtonId) -> ButtonMatrixControl
pub fn control(&self, id: ButtonId) -> ButtonMatrixControl
Return the control flags of button id.
Set the relative width of button id (clamped to 1..=15).
Return the relative width of button id, or 1 if not found.
Set the selected (keyboard-focused) button.
Out-of-range IDs are silently ignored.
Return the currently selected button.
Sourcepub fn set_one_checked(&mut self, enabled: bool)
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.
Sourcepub fn one_checked(&self) -> bool
pub fn one_checked(&self) -> bool
Return true when the one-checked constraint is enabled.
Set the checked state of button id.
When one_checked is enabled and checked is true, all other
buttons are unchecked first.
Return true when button id is in the checked state.
Select the next navigable button (wraps around).
Select the previous navigable button (wraps around).
Sourcepub fn activate_selected(&mut self)
pub fn activate_selected(&mut self)
Activate the currently selected button.
No-ops when nothing is selected or the selected button is not navigable.