pub struct LayoutContainer {
pub x: f32,
pub y: f32,
pub col_gap: f32,
pub row_gap: f32,
pub rows: Vec<LayoutRow>,
pub visible: bool,
}Expand description
Positions a set of TextLabels as a stack of rows, so a HUD does
not have to hand-place every chip. Each row lays its labels out left to
right; rows stack top to bottom. The container owns the labels’ on-screen
position: the labels keep their own styling (font, colour, background,
padding) but their x/y are overwritten each frame.
Sizing is content-driven: a label is measured at its current text, so the layout reflows as live HUD values change width. A row with a single label sits on its own line beneath the previous row, which is how a wide chip (e.g. a multi-pass timing line) ends up spanning the width of the row above.
Labels referenced by cols are matched by name; a label whose font is not
loaded, or which is hidden, is skipped and reserves no space.
LayoutContainer {
x: 10.0,
y: 10.0,
col_gap: 6.0,
row_gap: 6.0,
..Default::default()
};Fields§
§x: f32Left edge of the container in window pixels.
y: f32Top edge of the container in window pixels.
col_gap: f32Pixels between adjacent labels in a row, measured between their background boxes.
row_gap: f32Pixels between adjacent rows, measured between their background boxes.
rows: Vec<LayoutRow>Rows of labels, top to bottom.
visible: boolWhen false, the container leaves its labels where they are instead of repositioning them.
Implementations§
Source§impl LayoutContainer
impl LayoutContainer
Sourcepub fn layout(
&self,
size_of: impl Fn(AssetId) -> Option<LabelBox>,
) -> Vec<LabelPlacement>
pub fn layout( &self, size_of: impl Fn(AssetId) -> Option<LabelBox>, ) -> Vec<LabelPlacement>
Resolve the text origin for every label in the container.
size_of returns a label’s measured box, or None to drop it from the
layout (unknown label, unloaded font, hidden). The result is pure
geometry: callers measure with their font metrics, this places the
boxes. Boxes within a row are laid edge-to-edge with col_gap between
them; rows are stacked with row_gap between them.
Sourcepub fn layout_into(
&self,
size_of: impl Fn(AssetId) -> Option<LabelBox>,
out: &mut Vec<LabelPlacement>,
)
pub fn layout_into( &self, size_of: impl Fn(AssetId) -> Option<LabelBox>, out: &mut Vec<LabelPlacement>, )
LayoutContainer::layout writing into a caller-owned buffer, so a
per-frame caller reuses its capacity. Clears out first.
Trait Implementations§
Source§impl Clone for LayoutContainer
impl Clone for LayoutContainer
Source§fn clone(&self) -> LayoutContainer
fn clone(&self) -> LayoutContainer
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Component for LayoutContainer
impl Component for LayoutContainer
Source§const NAME: &'static str = "LayoutContainer"
const NAME: &'static str = "LayoutContainer"
Source§fn from_baked(bytes: &[u8]) -> Result<Self, CnResult>
fn from_baked(bytes: &[u8]) -> Result<Self, CnResult>
Source§fn inject_locator(&mut self, _locator: PayloadLocator)
fn inject_locator(&mut self, _locator: PayloadLocator)
Source§fn inject_name(&mut self, _id: AssetId)
fn inject_name(&mut self, _id: AssetId)
Source§impl ComponentSlot for LayoutContainer
impl ComponentSlot for LayoutContainer
Source§const DISCRIMINANT: u8
const DISCRIMINANT: u8
ComponentId.