pub struct Grid(/* private fields */);Expand description
W Grid layout with cells of variable sizes.
Implementations§
Source§impl Grid
impl Grid
Sourcepub fn widget_new() -> Self
pub fn widget_new() -> Self
Start building a new instance.
Sourcepub fn widget_type() -> WidgetType
pub fn widget_type() -> WidgetType
Gets the widget type info.
Source§impl Grid
impl Grid
Sourcepub fn cells(&self, cells: impl IntoUiNode)
pub fn cells(&self, cells: impl IntoUiNode)
B Cell widget items.
Cells can select their own column, row, column-span and row-span using the properties in the Cell! widget.
Note that you don’t need to use that widget, only the cell properties.
If the column or row index is set to usize::MAX the widget is positioned using the
logical index i, the column i % columns and the row i / columns.
Source§impl Grid
impl Grid
Sourcepub fn columns(&self, columns: impl IntoUiNode)
pub fn columns(&self, columns: impl IntoUiNode)
B Column definitions.
Columns are defined by widgets, the column widget width defines the width of cells assigned to the column,
the Column! widget is recommended, but you can use any widget to define a column. The column widget is rendered
as the background of the column region, behind cells and row backgrounds.
§Layout Modes
The grid uses the WIDGET_SIZE value to select one of three layout modes for columns:
- Default, used for columns that do not set width or set it to
Length::Default. - Exact, used for columns that set the width to an unit that is exact or only depends on the grid context.
- Leftover, used for columns that set width to a
lftvalue.
The column (and row) measure follows these steps:
1 - All Exact column widgets are measured, their final width defines the column width.
2 - All Default sized column widgets are measured twice to find its min and max widths.
3 - All cell widgets with span 1 in Default columns are measured to find the widest cell width. That defines the column width.
4 - All Leftover columns receive the proportional leftover grid width for each.
So given the columns 200 | 1.lft() | 1.lft() and grid width of 1000 with spacing 5 the final widths are 200 | 395 | 395,
for 200 + 5 + 395 + 5 + 395 = 1000.
§Overflow Recovery
In case the columns width overflows and all rows are Default height and some columns are Default width these recovery steps are taken:
1 - All cell widgets with span 1 in Default columns are measured to find the minimum width they can wrap down too.
2 - All Default columns are sized to the minimum width plus the extra space now available, proportionally divided.
3 - All cells widgets affected are measured again to define the row heights.
The proportion of each Default is the difference between the previous measured width with the new minimum, this is very similar to the CSS table layout, except the previous measured width is used instead of another measure pass to find the cells maximum width.
§Notes
Note that the column widget is not the parent of the cells that match it.
Properties like padding and align only affect the column visual, not the cells, similarly contextual properties like text_color
don’t affect the cells.
Note that the Default layout mode scales with the cell count, the other modes scale with the column count. This is fine for small grids (<100 cells) or for simple cell widgets, but for larger grids you should really consider using an Exact width or Leftover proportion, specially if the grid width is bounded.
Source§impl Grid
impl Grid
Sourcepub fn rows(&self, rows: impl IntoUiNode)
pub fn rows(&self, rows: impl IntoUiNode)
B Row definitions.
Rows are defined by widgets, the row widget height defines the height of cells assigned to the row, the Row! widget is recommended,
but you can use any widget to define a row. The row widget is rendered as the background of the row region, behind cells and in front
of column backgrounds.
§Layout Modes
The grid uses the WIDGET_SIZE value to select one of three layout modes for rows:
- Default, used for rows that do not set height or set it to
Length::Default. - Exact, used for rows that set the height to an unit that is exact or only depends on the grid context.
- Leftover, used for rows that set height to a
lftvalue.
The row measure follows the same steps as columns, the only difference is that there is no
overflow recovery for row heights exceeding the available height.
§Notes
Note that the row widget is not the parent of the cells that match it.
Properties like padding and align only affect the row visual, not the cells, similarly contextual properties like text_color
don’t affect the cells.
Note that the Default layout mode scales with the cell count, the other modes scale with the row count. This has less impact
for rows, but you should consider setting a fixed row height for larger grids. Also note that you can define the auto_grow_fn
instead of manually adding rows. With fixed heights a data table of up to 1000 rows with simple text cells should have good performance.
For massive data tables consider a paginating layout with a separate grid instance per page, the page grids don’t need to be actually presented as pages, you can use lazy loading and a simple stack layout to seamless virtualize data loading and presentation.
Source§impl Grid
impl Grid
Sourcepub fn auto_grow_fn(&self, auto_grow: impl IntoVar<WidgetFn<AutoGrowFnArgs>>)
pub fn auto_grow_fn(&self, auto_grow: impl IntoVar<WidgetFn<AutoGrowFnArgs>>)
B Widget function used when new rows or columns are needed to cover a cell placement.
The function is used according to the auto_grow_mode. Note that imaginary rows or columns are used if
the function is WidgetFn::nil.
Source§impl Grid
impl Grid
Sourcepub fn auto_grow_mode(&self, mode: impl IntoVar<AutoGrowMode>)
pub fn auto_grow_mode(&self, mode: impl IntoVar<AutoGrowMode>)
B Defines the direction the grid auto-grows and the maximum inclusive index that can be covered by auto-generated columns or rows.
If a cell is outside this index and is not covered by predefined columns or rows a new one is auto generated for it, but if the
cell is also outside this max it is collapsed.
Is `AutoGrowMode::rows() by default.
Methods from Deref<Target = WidgetBase>§
Sourcepub fn widget_builder(&mut self) -> &mut WidgetBuilder
pub fn widget_builder(&mut self) -> &mut WidgetBuilder
Returns a mutable reference to the widget builder.
Sourcepub fn widget_when(&mut self) -> Option<&mut WhenInfo>
pub fn widget_when(&mut self) -> Option<&mut WhenInfo>
Returns a mutable reference to the when block if called inside a when block.
Sourcepub fn widget_take(&mut self) -> WidgetBuilder
pub fn widget_take(&mut self) -> WidgetBuilder
Takes the widget builder, finishing the widget macro build.
After this call trying to set a property using self will panic,
the returned builder can still be manipulated directly.
Sourcepub fn widget_build(&mut self) -> UiNode
pub fn widget_build(&mut self) -> UiNode
Build the widget.
After this call trying to set a property will panic.
Sourcepub fn widget_importance(&mut self) -> &mut Importance
pub fn widget_importance(&mut self) -> &mut Importance
Returns a mutable reference to the importance of the next property assigns, unsets or when blocks.
Note that during the widget_intrinsic call this is Importance::WIDGET and after it is Importance::INSTANCE.
Sourcepub fn start_when_block(
&mut self,
inputs: Box<[WhenInput]>,
state: Var<bool>,
expr: &'static str,
location: SourceLocation,
)
pub fn start_when_block( &mut self, inputs: Box<[WhenInput]>, state: Var<bool>, expr: &'static str, location: SourceLocation, )
Start building a when block, all properties set after this call are pushed in the when block.
Sourcepub fn end_when_block(&mut self)
pub fn end_when_block(&mut self)
End the current when block, all properties set after this call are pushed in the widget.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Grid
impl !RefUnwindSafe for Grid
impl Send for Grid
impl !Sync for Grid
impl !Unpin for Grid
impl !UnwindSafe for Grid
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more