#size #children #flex

flex-grow

allocate a size between children

1 unstable release

0.1.0 Aug 21, 2024

#892 in GUI

Download history 283/week @ 2025-10-13 247/week @ 2025-10-20 452/week @ 2025-10-27 407/week @ 2025-11-03 262/week @ 2025-11-10 406/week @ 2025-11-17 235/week @ 2025-11-24 425/week @ 2025-12-01 298/week @ 2025-12-08 239/week @ 2025-12-15 236/week @ 2025-12-22 160/week @ 2025-12-29 171/week @ 2026-01-05 636/week @ 2026-01-12 365/week @ 2026-01-19 250/week @ 2026-01-26

1,450 downloads per month
Used in broot

MIT license

12KB
232 lines

MIT Latest Version docs Chat on Miaou

Tiny utility computing the allocation of a size among "children".

Typical use case: decide what columns to show in an UI, and what size to give to each column.

Each child can have a min and max size, be optional with a priority, have a grow factor.

Example:

use flex_grow::{Child, Container};

let container = Container::builder_in(50)
    .with_margin_between(1)
    .with(Child::new("name").clamp(5, 10))
    .with(Child::new("price").with_size(8).optional_with_priority(7))
    .with(Child::new("quantity").with_size(8).optional())
    .with(Child::new("total").with_size(8))
    .with(Child::new("comments").with_min(10).with_grow(2.0))
    .with(Child::new("vendor").with_size(60).optional_with_priority(9))
    .build()
    .unwrap();
assert_eq!(container.sizes(), vec![7, 8, 8, 8, 15, 0]);

You can give any argument to Child::new, it's stored in the child and returned by the content() method.

No runtime deps