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 parent() -> FloatConfig
pub fn parent() -> FloatConfig
Anchored to the parent’s top-left corner.
Sourcepub fn viewport() -> FloatConfig
pub fn viewport() -> FloatConfig
Anchored to the viewport’s top-left corner.
Sourcepub fn below() -> FloatConfig
pub fn below() -> FloatConfig
Tooltip-style: hang below the parent, centered.
Sourcepub fn above() -> FloatConfig
pub fn above() -> FloatConfig
Tooltip-style: hover above the parent, centered.
Sourcepub fn at(self, x: Align, y: Align) -> FloatConfig
pub fn at(self, x: Align, y: Align) -> FloatConfig
The attach point on the anchor.
Sourcepub fn self_at(self, x: Align, y: Align) -> FloatConfig
pub fn self_at(self, x: Align, y: Align) -> FloatConfig
The attach point on the float itself.
Sourcepub fn inside(self, x: Align, y: Align) -> FloatConfig
pub fn inside(self, x: Align, y: Align) -> FloatConfig
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 offset(self, x: f32, y: f32) -> FloatConfig
pub fn offset(self, x: f32, y: f32) -> FloatConfig
An extra offset after attaching, logical px.
Sourcepub fn fit(self) -> FloatConfig
pub fn fit(self) -> FloatConfig
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) -> FloatConfig
pub fn clipped(self) -> FloatConfig
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<FloatConfig>
pub fn preset_at(i: usize) -> Option<FloatConfig>
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<FloatConfig>
pub fn preset(name: &str) -> Option<FloatConfig>
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,
) -> FloatConfig
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, ) -> FloatConfig
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.
Trait Implementations§
Source§impl Clone for FloatConfig
impl Clone for FloatConfig
Source§fn clone(&self) -> FloatConfig
fn clone(&self) -> FloatConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for FloatConfig
Source§impl Debug for FloatConfig
impl Debug for FloatConfig
Source§impl Default for FloatConfig
impl Default for FloatConfig
Source§fn default() -> FloatConfig
fn default() -> FloatConfig
Source§impl PartialEq for FloatConfig
impl PartialEq for FloatConfig
impl StructuralPartialEq for FloatConfig
Auto Trait Implementations§
impl Freeze for FloatConfig
impl RefUnwindSafe for FloatConfig
impl Send for FloatConfig
impl Sync for FloatConfig
impl Unpin for FloatConfig
impl UnsafeUnpin for FloatConfig
impl UnwindSafe for FloatConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.