tawasuyu

tawasuyu/llimphi

Sovereign retained-mode GPU UI framework in Rust (wgpu+vello+taffy+parley), Elm loop, 40+ widgets.

Rust 614Markdown 274TOML 149RON 310606 Sutichaykuna

⎇ main widgets/wrap/src/lib.rs Rust · 68 siq'ikuna · 2.0 KB Ñawpa willay Pi imata llamkarqan ch'uya

chore: refresco desde el monorepo — vello 0.9 / wgpu 29, 120 miembros d251eb32b · Sergio ·

1//! `llimphi-widget-wrap` — contenedor con `flex-wrap: wrap` y gap.
2//!
3//! Lo que en Flutter es `Wrap` y en Compose `FlowRow`: items que fluyen
4//! horizontalmente y saltan a la siguiente línea cuando se acaba el
5//! ancho. Úsalo para chips, tags, galerías fluidas, toolbars que
6//! respiran. taffy ya soporta `flex-wrap`; este crate es el azúcar
7//! mínima para no repetir el `Style` boilerplate.
8
9#![forbid(unsafe_code)]
10
11
12// Sin `std`: este widget no usa nada del sistema —sólo `alloc` para
13// `String`/`Vec`—, y declararlo es lo que le permite cruzar a una jaula
14// WASM o al kernel. Antes enlazaba `std` por omisión (W4.6).
15#![no_std]
16
17extern crate alloc;
18
19use alloc::vec::Vec;
20use llimphi_compositor::llimphi_layout::taffy::{
21    prelude::{length, percent, FlexDirection, FlexWrap, Size, Style},
22    AlignItems,
23};
24use llimphi_compositor::View;
25
26/// Eje principal del wrap.
27#[derive(Debug, Clone, Copy)]
28pub enum WrapAxis {
29    Row,
30    Column,
31}
32
33/// Wrap container.
34///
35/// - `axis` decide eje principal (row = horizontal, column = vertical).
36/// - `h_gap` es el gap **entre items en la misma línea**.
37/// - `v_gap` es el gap **entre líneas**.
38pub fn wrap_view<Msg: Clone + 'static>(
39    children: Vec<View<Msg>>,
40    axis: WrapAxis,
41    h_gap: f32,
42    v_gap: f32,
43) -> View<Msg> {
44    let dir = match axis {
45        WrapAxis::Row => FlexDirection::Row,
46        WrapAxis::Column => FlexDirection::Column,
47    };
48    View::new(Style {
49        flex_direction: dir,
50        flex_wrap: FlexWrap::Wrap,
51        size: Size {
52            width: percent(1.0_f32),
53            height: llimphi_compositor::llimphi_layout::taffy::prelude::Dimension::auto(),
54        },
55        gap: Size {
56            width: length(h_gap),
57            height: length(v_gap),
58        },
59        align_items: Some(AlignItems::FLEX_START),
60        ..Default::default()
61    })
62    .children(children)
63}
64
65/// Atajo: row de chips con gap parejo 6px.
66pub fn chip_row<Msg: Clone + 'static>(children: Vec<View<Msg>>) -> View<Msg> {
67    wrap_view(children, WrapAxis::Row, 6.0, 6.0)
68}