Expand description
§egui-pop-fit
A slot layout engine over plain boxes. It knows nothing of widgets, values or drawing: it packs ordered elements into a container in standard slot sizes, and says where each one goes.
It has no egui dependency: the egui-pop- prefix only marks it as
part of the egui-pop workspace, whose facade re-exports it as
egui_pop::fit. Results are plain rectangles, in twelfths of the unit
and in points. It was published as egui_fit (0.1) before it joined
the workspace; its API did not change.
- Base unit. One row, scaled by density, given in points by the
caller (
Container::unit). - Allowed sizes. ¼, ⅓, ½, ⅔, ¾ of the unit and whole multiples
(
Size), counted in twelfths with integer arithmetic only. - Elements. Each declares forms (form 0 is the full form, the others
smaller ones), each with a
SizePolicy; its supported orientations, preferred first; an optional pinned orientation and pinned position. - Packing. A grid as wide as the box, in twelfths, with rows going
down. Pinned elements are placed first, then the others in their order,
each at the first free position in reading order: a later element may
move up into an earlier gap (like CSS
grid-auto-flow: dense). - Groups.
layout_groupedtakesGroups: runs of consecutive elements, like afieldset’s controls, each with an optional header (its legend) on a band of its own. Packing stays dense within a group, but order is strict across groups: each starts on a new band below everything before it, and nothing later moves up into its gaps. Groups nest; pins count from the top of their band. The result gives each group’s band (GroupPlacement), for a host to frame it. - Growth. Growable elements then take the leftover room one slot step at a time, in rounds, up to their maximum.
- Hysteresis. Pass the previous
Layoutto keep its column count, forms and orientations while the box stays within half a unit of a threshold. - Regions.
layout_regionsplaces cards in namedRegions around and over aSurface(an image): corners, edges, the centre and an overlay, each with anAnchor, a gap and a priority. Each region packs its cards with the engine in the room the regions before it left, and folds its lowest-priority cards when room runs out.
use egui_pop_fit::{layout, Axis, Container, Element, Size, Size2, SizePolicy};
let half = Size2::new(Size::HALF, Size::ONE);
let row = Size2::new(Size::units(2), Size::ONE);
let elements = [
Element::new(1, SizePolicy::fixed(half)),
Element::new(2, SizePolicy::fixed(row)),
Element::new(3, SizePolicy::growable(half, half, row, Axis::Width)),
];
// Two units wide (48 points, 24-point unit), growing down. `b` does not
// fit beside `a`, so `c` moves up into the gap, then grows in slot steps
// (½, ⅔, ¾, 1): the next step, 2, would not fit, so ½ unit stays empty.
let result = layout(&Container::new(48.0, 24.0), &elements, None);
assert_eq!(
result.dump(),
"grid 24x24 twelfths, one char = 6x12\n\
acc.\n\
bbbb\n\
a key=1 form=0 horizontal at 0,0 size 6x12\n\
b key=2 form=0 horizontal at 0,12 size 24x12\n\
c key=3 form=0 horizontal at 6,0 size 12x12\n",
);Experimental: may change in any release
(docs/stability.md).
Structs§
- Aspect
Ratio - A width-to-height ratio. A ratio with a zero term is ignored.
- Card
- A card: one element of the slot engine, placed in a region.
- Card
Placement - Where a card went.
- Cell
- A grid position, in twelfths of the unit from the container’s top left.
- Container
- The box to lay elements out in, in points.
- Element
- One element of a container, in its logical order.
- Grid
Rect - A rectangle on the grid, in twelfths of the unit.
- Group
- A run of consecutive elements packed apart from the rest.
- Group
Placement - The result for one group.
- Invalid
Size - The error of converting a number of twelfths that is not an allowed size.
- Layout
- A laid-out container.
- Placement
- The result for one element.
- Point
Rect - A rectangle in points, relative to the container’s top left.
- Region
- A named place for cards on a surface.
- Region
Layout - The cards laid out in their regions.
- Region
Placement - Where a region went.
- Size
- A standard slot size along one axis: ¼, ⅓, ½, ⅔, ¾ of the base unit, or a whole number of units.
- Size2
- A size on both axes.
- Size
Policy - How an element is sized, written for its horizontal orientation (the vertical orientation swaps the axes).
- Surface
- The surface the regions sit on and around, in points.
Enums§
- Anchor
- Where a region sits on its surface. Start and end follow the
direction: start is left in a left-to-right interface, right in a
right-to-left one (
Surface::right_to_left). - Axis
- An axis of a size policy, in the policy’s own (horizontal) terms.
- Card
Status - What became of a card.
- Grow
- Whether an element keeps its size or takes leftover room.
- Orientation
- An orientation an element can be laid out in.
- Reason
- Why an element is not placed, or not where it was pinned.
- Side
- Whether a region lies over the surface or around it.
- Status
- The outcome for one element.
Constants§
- TWELFTHS_
PER_ UNIT - Twelfths in one base unit. 12 is the least common multiple of 2, 3 and 4, so every allowed size is a whole number of twelfths.
Functions§
- layout
- Lays
elementsout incontainer. - layout_
grouped - Lays
elementsout incontainer, ingroups. - layout_
regions - Lays
cardsout inregionson and aroundsurface.