Expand description
Placement of a floating element (popover, menu, tooltip) next to an anchor, inside bounds: on the preferred side if it fits, else flipped to the opposite side, else on the side with more room; then shifted along the side to stay inside, and shrunk only when larger than the bounds.
egui’s own RectAlign::find_best_align flips among candidate
alignments but neither shifts nor shrinks; this is the small part of
floating-ui’s model egui-pop needs, pure geometry, tested by
properties.
use egui::{Rect, pos2, vec2};
use egui_pop_core::placement::{Align, Placement, Side, place};
let bounds = Rect::from_min_size(pos2(0.0, 0.0), vec2(400.0, 300.0));
// A button near the bottom: a menu asked below it opens above.
let anchor = Rect::from_min_size(pos2(20.0, 270.0), vec2(80.0, 24.0));
let p = place(&Placement::new(anchor, vec2(160.0, 120.0), bounds).side(Side::Bottom));
assert_eq!(p.side, Side::Top);
assert!(p.flipped);
assert!(bounds.contains_rect(p.rect));Structs§
Enums§
- Align
- How the element lines up with the anchor along the side.
- Side
- Which side of the anchor. Start and end are left and right in a left-to-right layout.
Functions§
- place
- Places the element.