pub struct FloatConfig {
pub anchor: FloatAnchor,
pub anchor_point: (Align, Align),
pub self_point: (Align, Align),
pub offset: Vec2Offset,
pub fit: bool,
pub clip: bool,
}Expand description
Takes a node out of flex flow: it does not consume space in its parent,
sizes Grow/Percent against its anchor, is positioned by attach points,
and escapes ancestor clips unless FloatConfig::clip keeps it in its
parent’s. It paints as a layer of its own, above the in-flow tree and
every float that opened before it and under every one that opened
after, and takes input in the same order.
use kui_core::{Align, FloatConfig, NodeSpec};
let tooltip = NodeSpec::column().float(FloatConfig::below().fit());
let toast = NodeSpec::row().float(FloatConfig::viewport().inside(Align::End, Align::End).offset(-16.0, -16.0));
assert!(tooltip.layout.float.unwrap().fit);
assert_eq!(toast.layout.float.unwrap().offset.x, -16.0);Fields§
§anchor: FloatAnchor§anchor_point: (Align, Align)Attach point on the anchor rect (horizontal, vertical).
self_point: (Align, Align)Attach point on the floating node itself.
offset: Vec2OffsetExtra offset applied after attaching, logical px.
fit: boolKeep the float on screen: if the attached placement leaves the viewport on an axis, mirror the attachment across the anchor on that axis (below ↔ above, after ↔ before) when that fits better, then clamp whatever still overflows. Tooltips/menus want this.
This is the in-window approximation of an OS popup: a float costs one tree, one hit list and one draw call. What it cannot do is leave the window, so a dropdown taller than the viewport, or a menu with nowhere in-window to go, is clamped rather than placed.
clip: boolTake the parent’s clip, as a child does, instead of escaping every
ancestor’s: a node on a clip canvas panned past the canvas’s edge
is cut there, and its hit region with it, rather than drawn over
and clicked through the toolbar beside it. Only a
FloatAnchor::Parent float reads it; a viewport or node anchor is
placed against something other than the parent, and escapes with it
set or not. A declared float’s paint order is unchanged: it is a
layer of its own still. A line, polygon or path anchored in
its parent’s box has it set by the core, and with it paints in the
parent’s layer at its place in the tree, as a child does — it opens
no layer (backlog F123; Tree::opens_layer).
Implementations§
Source§impl FloatConfig
impl FloatConfig
Sourcepub fn inside(self, x: Align, y: Align) -> Self
pub fn inside(self, x: Align, y: Align) -> Self
Self::at and Self::self_at at the same point: the float sits
inside the anchor against that edge or corner — (End, End) is a
toast in the viewport’s bottom-right, (Center, Center) a dialog.
Sourcepub fn fit(self) -> Self
pub fn fit(self) -> Self
Flip across the anchor / clamp as needed to stay in the viewport;
see FloatConfig::fit for where that stops being enough.
Sourcepub fn clipped(self) -> Self
pub fn clipped(self) -> Self
Cut by the parent’s clip instead of escaping it; see
FloatConfig::clip for which anchors read it.
Sourcepub fn clipped_by_parent(&self) -> bool
pub fn clipped_by_parent(&self) -> bool
Whether this float takes its parent’s clip: FloatConfig::clip
declared on a parent-anchored float. The one reading both paint
passes and the hit regions share.
Sourcepub fn preset_at(i: usize) -> Option<Self>
pub fn preset_at(i: usize) -> Option<Self>
A preset by its wire index — its position in FLOAT_PRESETS, which
is what the binary protocol carries and what KUI_FLOAT_* counts
from. None for an index no preset claims.
Sourcepub fn preset(name: &str) -> Option<Self>
pub fn preset(name: &str) -> Option<Self>
A preset by name. Every binding that spells a float as a word —
float="below", float = "above", kui_spec_float_preset — resolves
it here, so “below” cannot mean one thing in JS and another in Lua.
Sourcepub fn build(
base: FloatConfig,
anchor_at: Option<(Align, Align)>,
self_at: Option<(Align, Align)>,
dx: Option<f32>,
dy: Option<f32>,
fit: bool,
clip: bool,
) -> Self
pub fn build( base: FloatConfig, anchor_at: Option<(Align, Align)>, self_at: Option<(Align, Align)>, dx: Option<f32>, dy: Option<f32>, fit: bool, clip: bool, ) -> Self
One config from the pieces a binding can extract without deciding
anything: a base preset (from FloatConfig::preset or
FloatConfig::preset_at) and the overrides that were actually
declared. None leaves the base’s own value — that is what lets
float="below" keep its 6px gap while { anchor: "below", dx: 2 }
moves it sideways without flattening the gap to zero. fit and
clip are ORed in: no preset sets either.