Grid

Struct Grid 

Source
pub struct Grid(/* private fields */);
Expand description

W Grid layout with cells of variable sizes.

Implementations§

Source§

impl Grid

Source

pub fn widget_new() -> Self

Start building a new instance.

Source

pub fn widget_type() -> WidgetType

Gets the widget type info.

Source§

impl Grid

Source

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

Source

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 lft value.

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

Source

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 lft value.

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

Source

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

Source

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.

Source§

impl Grid

Source

pub fn spacing(&self, spacing: impl IntoVar<GridSpacing>)

B Space in-between cells.

Methods from Deref<Target = WidgetBase>§

Source

pub fn widget_builder(&mut self) -> &mut WidgetBuilder

Returns a mutable reference to the widget builder.

Source

pub fn widget_when(&mut self) -> Option<&mut WhenInfo>

Returns a mutable reference to the when block if called inside a when block.

Source

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.

Source

pub fn widget_build(&mut self) -> UiNode

Build the widget.

After this call trying to set a property will panic.

Source

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.

Source

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.

Source

pub fn end_when_block(&mut self)

End the current when block, all properties set after this call are pushed in the widget.

Source

pub fn id(&self, id: impl IntoValue<WidgetId>)

B Unique ID of the widget instance.

Note that the id can convert from a &'static str unique name.

Trait Implementations§

Source§

impl Deref for Grid

Source§

type Target = WidgetBase

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for Grid

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more