egui_pop_fit/lib.rs
1//! # egui-pop-fit
2//!
3//! A slot layout engine over plain boxes. It knows nothing of widgets,
4//! values or drawing: it packs ordered elements into a container in
5//! standard slot sizes, and says where each one goes.
6//!
7//! It has no egui dependency: the `egui-pop-` prefix only marks it as
8//! part of the egui-pop workspace, whose facade re-exports it as
9//! `egui_pop::fit`. Results are plain rectangles, in twelfths of the unit
10//! and in points. It was published as `egui_fit` (0.1) before it joined
11//! the workspace; its API did not change.
12//!
13//! - **Base unit.** One row, scaled by density, given in points by the
14//! caller ([`Container::unit`]).
15//! - **Allowed sizes.** ¼, ⅓, ½, ⅔, ¾ of the unit and whole multiples
16//! ([`Size`]), counted in twelfths with integer arithmetic only.
17//! - **Elements.** Each declares forms (form 0 is the full form, the others
18//! smaller ones), each with a [`SizePolicy`]; its supported orientations,
19//! preferred first; an optional pinned orientation and pinned position.
20//! - **Packing.** A grid as wide as the box, in twelfths, with rows going
21//! down. Pinned elements are placed first, then the others in their order,
22//! each at the first free position in reading order: a later element may
23//! move up into an earlier gap (like CSS `grid-auto-flow: dense`).
24//! - **Groups.** [`layout_grouped`] takes [`Group`]s: runs of consecutive
25//! elements, like a `fieldset`'s controls, each with an optional header
26//! (its legend) on a band of its own. Packing stays dense within a group,
27//! but order is strict across groups: each starts on a new band below
28//! everything before it, and nothing later moves up into its gaps. Groups
29//! nest; pins count from the top of their band. The result gives each
30//! group's band ([`GroupPlacement`]), for a host to frame it.
31//! - **Growth.** Growable elements then take the leftover room one slot step
32//! at a time, in rounds, up to their maximum.
33//! - **Hysteresis.** Pass the previous [`Layout`] to keep its column count,
34//! forms and orientations while the box stays within half a unit of a
35//! threshold.
36//! - **Regions.** [`layout_regions`] places cards in named [`Region`]s
37//! around and over a [`Surface`] (an image): corners, edges, the centre
38//! and an overlay, each with an [`Anchor`], a gap and a priority. Each
39//! region packs its cards with the engine in the room the regions before
40//! it left, and folds its lowest-priority cards when room runs out.
41//!
42//! ```
43//! use egui_pop_fit::{layout, Axis, Container, Element, Size, Size2, SizePolicy};
44//!
45//! let half = Size2::new(Size::HALF, Size::ONE);
46//! let row = Size2::new(Size::units(2), Size::ONE);
47//! let elements = [
48//! Element::new(1, SizePolicy::fixed(half)),
49//! Element::new(2, SizePolicy::fixed(row)),
50//! Element::new(3, SizePolicy::growable(half, half, row, Axis::Width)),
51//! ];
52//! // Two units wide (48 points, 24-point unit), growing down. `b` does not
53//! // fit beside `a`, so `c` moves up into the gap, then grows in slot steps
54//! // (½, ⅔, ¾, 1): the next step, 2, would not fit, so ½ unit stays empty.
55//! let result = layout(&Container::new(48.0, 24.0), &elements, None);
56//! assert_eq!(
57//! result.dump(),
58//! "grid 24x24 twelfths, one char = 6x12\n\
59//! acc.\n\
60//! bbbb\n\
61//! a key=1 form=0 horizontal at 0,0 size 6x12\n\
62//! b key=2 form=0 horizontal at 0,12 size 24x12\n\
63//! c key=3 form=0 horizontal at 6,0 size 12x12\n",
64//! );
65//! ```
66#![doc = "\n\n<div class=\"warning\">Experimental: may change in any release\n(docs/stability.md).</div>"]
67#![deny(missing_docs)]
68#![forbid(unsafe_code)]
69
70mod dump;
71mod element;
72mod group;
73mod layout;
74mod regions;
75mod size;
76
77pub use element::{AspectRatio, Axis, Cell, Element, Grow, Orientation, Size2, SizePolicy};
78pub use group::{Group, GroupPlacement};
79pub use layout::{
80 Container, GridRect, Layout, Placement, PointRect, Reason, Status, layout, layout_grouped,
81};
82pub use regions::{
83 Anchor, Card, CardPlacement, CardStatus, Region, RegionLayout, RegionPlacement, Side, Surface,
84 layout_regions,
85};
86pub use size::{InvalidSize, Size, TWELFTHS_PER_UNIT};
87
88#[cfg(doctest)]
89#[doc = include_str!("../README.md")]
90struct ReadmeDoctests;