pub struct GridLayout {
pub titles: HeaderTitles,
pub cols: u32,
pub sections: Vec<(u32, &'static str)>,
pub widgets: Vec<GridWidget>,
pub cell_size: f32,
pub width: u32,
pub height: u32,
/* private fields */
}Expand description
Grid-based layout for a plugin UI.
Fields§
§titles: HeaderTitlesHeader band titles. Both slots default to None, in which
case no header is drawn and the grid starts at y = 0
(plus padding).
cols: u32Number of columns in the grid.
sections: Vec<(u32, &'static str)>Section labels positioned above specific rows: (row_index, label).
widgets: Vec<GridWidget>All widgets placed in the grid.
cell_size: f32Cell size in logical points (width and height of one grid cell).
width: u32Computed width in logical points.
height: u32Computed height in logical points.
Implementations§
Source§impl GridLayout
impl GridLayout
Sourcepub fn build(entries: Vec<Section>) -> Self
pub fn build(entries: Vec<Section>) -> Self
Build a grid layout from sections containing widgets. No
header is drawn, cols defaults to the widest section’s
widget count (extended to fit any explicitly-positioned
widget), and cell_size defaults to
GRID_DEFAULT_CELL_SIZE. Override any of those via
Self::with_titles / Self::with_cols /
Self::with_cell_size.
Each entry is either a Section (created with section("LABEL", vec![...]))
or a bare GridWidget (auto-wrapped via From). Example:
GridLayout::build(vec![
section("LOW", vec![
GridWidget::knob(P::Freq, "Freq"),
GridWidget::knob(P::Gain, "Gain"),
]),
GridWidget::knob(P::Output, "Output").into(),
])Sourcepub fn with_cols(self, cols: u32) -> Self
pub fn with_cols(self, cols: u32) -> Self
Override the default column count (which is the widest
section’s widget count, or whatever explicit positions
require - whichever is larger). Use to force wrapping:
.with_cols(2) on a 4-widget section produces a 2×2 grid.
Recomputes auto-flow placement and window size.
Sourcepub fn with_cell_size(self, cell_size: f32) -> Self
pub fn with_cell_size(self, cell_size: f32) -> Self
Override the default cell size (GRID_DEFAULT_CELL_SIZE).
The cell is square - this is both the width and height of
one grid cell in logical points.
Sourcepub fn with_grid(self, cols: u32, cell_size: f32) -> Self
pub fn with_grid(self, cols: u32, cell_size: f32) -> Self
Like Self::with_cols but accepts the cell size in the
same call - useful when both are non-default. Equivalent to
.with_cell_size(s).with_cols(c).
Sourcepub fn with_titles(self, titles: HeaderTitles) -> Self
pub fn with_titles(self, titles: HeaderTitles) -> Self
Set both header slots at once. Replaces any previously configured titles. Recomputes the height to account for the extra band - width stays the same since the header spans the full grid width.
use truce_gui_types::layout::{GridLayout, HeaderTitles};
GridLayout::build(sections).with_titles(HeaderTitles::pair("EQ", "v0.1"))Sourcepub fn with_title(self, title: &'static str) -> Self
pub fn with_title(self, title: &'static str) -> Self
Set the title slot (left, larger / brighter), preserving any previously configured subtitle.
GridLayout::build(sections).with_title("EQ")Sourcepub fn with_subtitle(self, subtitle: &'static str) -> Self
pub fn with_subtitle(self, subtitle: &'static str) -> Self
Set the subtitle slot (right, smaller / dimmer), preserving any previously configured title.
GridLayout::build(sections).with_subtitle("v0.1")Sourcepub fn compute_size(&self) -> (u32, u32)
pub fn compute_size(&self) -> (u32, u32)
Compute the window size from the grid.
Trait Implementations§
Source§impl Clone for GridLayout
impl Clone for GridLayout
Source§fn clone(&self) -> GridLayout
fn clone(&self) -> GridLayout
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more