Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Wrap

Wrap preview

Wrap — a horizontal flow layout that wraps children to the next line when they exceed the available width.

Public functions

Wrap

Detailed description

Children are placed left-to-right (or right-to-left under RTL layout) and wrapped to the next line when the next item would exceed the container width. Each line's height is the tallest child on that line. Use spacing for the horizontal gap between items and line_spacing for the vertical gap between lines.

Wrap is the right choice for chip rows, badge lists, and any collection whose items vary in width and should reflow as the container resizes. For a fixed grid use crate::primitives::Grid instead.

#![allow(unused)]
fn main() {
use teksilo_widgets::primitives::{Wrap, TextWidget};
use teksilo_i18n::lit;
let _chips = Wrap::new()
    .spacing(8.0)
    .line_spacing(6.0)
    .child(TextWidget::new(lit!("Rust")))
    .child(TextWidget::new(lit!("GUI")))
    .child(TextWidget::new(lit!("Desktop")));
}

Density

The picture above is the widget at TargetDensity::Compact, the mouse-and-keyboard ladder. Below is the same subject on the same canvas with only the ladder changed, so what moves is the density and nothing else — where the subject no longer fits, that is what the denser targets cost it at that size. See docs/density-and-targets.md.

Touch

Wrap at Touch density

API reference

📖 Full rustdoc API for this module

pub struct Wrap

Import: use teksilo::widgets::Wrap;

A horizontal flow layout that wraps children to the next line.

#![allow(unused)]
fn main() {
pub struct Wrap { /* fields */ }
}

Methods

pub fn new() -> Self

Create an empty Wrap container with zero spacing.

pub fn spacing(mut self, spacing: impl Into<Prop<f32>>) -> Self (default: 0.0)

Horizontal spacing between items on the same line. Accepts a static f32 or a reactive Signal<f32>.

pub fn line_spacing(mut self, spacing: impl Into<Prop<f32>>) -> Self (default: 0.0)

Vertical spacing between lines. Accepts a static f32 or a reactive Signal<f32>.

pub fn child(mut self, widget: impl teksilo_core::IntoTeksiChild) -> Self

Add an inline child widget (deferred insertion).

pub fn children( mut self, iter: impl IntoIterator<Item = impl teksilo_core::IntoTeksiChild>, ) -> Self

Add multiple inline children from an iterator.

pub fn child_opt(mut self, widget: Option<impl teksilo_core::IntoTeksiChild>) -> Self

Conditionally add a child. No-op if None.