Skip to main content

Grid

Struct Grid 

Source
pub struct Grid { /* private fields */ }
Expand description

Places its children row by row into equal-width columns, each row as tall as its tallest child. A child takes several cells with Style::span, and places itself in its cell with Style::align_self and Style::justify_self; it fills the cell by default.

columns, gap, row_gap, column_gap and padding change the layout. Each takes a value or a closure.

use crabshell_ui::{Grid, Style, Text};

let days = (1..=31).fold(Grid::new().columns(7).gap(4), |grid, day| {
    grid.child(Text::new(day.to_string()))
});
let wide = Grid::new()
    .columns(2)
    .child(Text::new("title").style(Style::new().span(2, 1)));

Implementations§

Source§

impl Grid

Source

pub fn new() -> Grid

An empty grid of one column.

Source

pub fn columns(self, columns: impl IntoProp<u32>) -> Grid

Sets the number of columns, all as wide. 1 by default, and 0 counts as 1.

Source

pub fn gap(self, gap: impl IntoProp<u32>) -> Grid

Sets the space between rows and between columns in logical pixels. row_gap and column_gap win over it.

Source

pub fn row_gap(self, gap: impl IntoProp<u32>) -> Grid

Sets the space between rows in logical pixels.

Source

pub fn column_gap(self, gap: impl IntoProp<u32>) -> Grid

Sets the space between columns in logical pixels.

Source

pub fn padding( self, vertical: impl IntoProp<u32>, horizontal: impl IntoProp<u32>, ) -> Grid

Sets the padding: vertical above and below, horizontal left and right, in logical pixels. It wins over the padding of the grid’s Style, as a Row’s does.

Source

pub fn child(self, child: impl Widget) -> Self

Adds child after the children added so far.

Source

pub fn children_keyed<T, K, W>( self, items: impl FnMut() -> Vec<T> + 'static, key: impl FnMut(&T) -> K + 'static, view: impl FnMut(&Cx, Memo<T>) -> W + 'static, ) -> Self
where T: Clone + PartialEq + 'static, K: Eq + Hash + 'static, W: Widget,

Adds one child per item, after the children added so far.

items runs in an effect, so the list updates when a signal it read changes. key names each item. view builds the child for a key the first time it appears, and that child is kept while its key stays in the list, even if it moves. view receives the item’s Cx and a Memo that updates when that item’s value changes. When a key leaves the list, its child and everything created in view are freed, at once or after an exit. If two items share a key, only the first is shown and the duplicate is logged.

Source

pub fn exit(self, exit: impl IntoProp<Duration>) -> Self

Lets the children of the last children_keyed list added leave over exit instead of at once. A child whose key leaves stays mounted and painted right after the child that was before it, and its context’s leaving turns true, so its own cx.animate can fade or shrink it out. After exit it is freed. If its key comes back first, the same child, with its state, takes the key’s new place. A closure is read as each key leaves, and an exit of 0 removes at once. Leaving children still take pointer and keyboard input; a handler can check cx.leaving() to ignore clicks during the exit.

Source

pub fn displaced(self, transition: impl IntoProp<Transition>) -> Self

Slides the children that a change of the last children_keyed list moves, instead of jumping: when its keys are added, leave (once their exit ends) or move, each child of this container whose place changes goes from where it was drawn to its new place over transition. It moves where it is drawn and hit, as Style::translate does, so a slide never lays the window out again. A child moved again mid-slide starts from where it is drawn. Other layout changes, such as a resize or text growing, still move children at once, and a new child shows in its place. A closure is read at each change of the list, and a transition of 0 jumps.

Source

pub fn style(self, style: impl IntoProp<Style>) -> Self

Sets the widget’s Style.

Source

pub fn visible(self, visible: impl IntoProp<bool>) -> Self

Shows or hides the widget. Hidden, it is taken out of the layout, so its space goes to the others, and it isn’t drawn, hit or reached by Tab; it drops the keyboard focus and the pointer. Its bindings and state stay, so it shows again as it was. Shown by default.

Source

pub fn geometry(self, geometry: Signal<Rect>) -> Self

Shares where the widget is: after each layout that moves or resizes it, its laid-out rectangle in the window’s logical pixels, scrolled with any scroll view around it but not moved by a style’s translate, scale or rotate, is written to geometry. A hidden widget writes nothing. An effect that reads it may change the layout: the window is laid out again at once, until nothing moves.

Trait Implementations§

Source§

impl Default for Grid

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Widget for Grid

Source§

fn into_element(self: Box<Self>) -> Element

Turns the description, and everything inside it, into the element the window builds nodes from. It runs when the window is created or a list item first appears, before the window’s tree is touched and without recording what it reads, so it only describes.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Grid

§

impl !Send for Grid

§

impl !Sync for Grid

§

impl !UnwindSafe for Grid

§

impl Forget for Grid

§

impl Freeze for Grid

§

impl Move for Grid

§

impl Unpin for Grid

§

impl UnsafeUnpin 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.

Source§

impl<T> Instrument for T

Source§

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

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

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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