pub struct GridStyle { /* private fields */ }Expand description
A grid’s geometry: an optional Length per column and the padding its
cells take.
A GridStyle is an immutable value, like BlockStyle.
It holds no box geometry or line presentation: a grid that needs a border,
margin, or stated size is placed inside a
View::Block, while a presentation that needs an
internal line network owns it in a Canvas.
use urushi::{GridStyle, Length, TextStyle, View, measure};
let style = GridStyle::new()
.cell_padding((0, 1))
.columns([None, Some(Length::fill(1))]);
let grid = View::grid(
style,
[
[View::text("id", TextStyle::new()), View::text("name", TextStyle::new())],
[View::text("1", TextStyle::new()), View::text("urushi", TextStyle::new())],
],
);
assert_eq!(measure(&grid).height(), 2);Implementations§
Source§impl GridStyle
impl GridStyle
pub fn new() -> Self
Sourcepub fn columns(self, columns: impl IntoIterator<Item = Option<Length>>) -> Self
pub fn columns(self, columns: impl IntoIterator<Item = Option<Length>>) -> Self
States the Length each column claims, left to right.
A column with no stated length — an absent entry, or one past the end of this list — is auto: it claims the intrinsic width of the cells beneath it. A stated length supplies only the kind of the claim; the demand and the floor still come from those cells.
Sourcepub fn reset_columns(self) -> Self
pub fn reset_columns(self) -> Self
Restores all column length claims to their default value.
Sourcepub fn cell_padding(self, sides: impl Into<Sides>) -> Self
pub fn cell_padding(self, sides: impl Into<Sides>) -> Self
Sets the padding every cell that states none of its own takes.
A cell that states its own padding replaces this value rather than adding to it. Columns stay aligned either way: a column is as wide as its widest cell, whatever padding that cell carries.
Sourcepub fn reset_cell_padding(self) -> Self
pub fn reset_cell_padding(self) -> Self
Restores the default cell padding.
Sourcepub fn get_column(&self, index: usize) -> Option<Length>
pub fn get_column(&self, index: usize) -> Option<Length>
Returns the stated length of column index, if it states one.
Sourcepub const fn get_cell_padding(&self) -> Sides
pub const fn get_cell_padding(&self) -> Sides
Returns the padding a cell that states none of its own takes.