Skip to main content

FloatConfig

Struct FloatConfig 

Source
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: Vec2Offset

Extra offset applied after attaching, logical px.

§fit: bool

Keep 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: bool

Take 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

Source

pub fn parent() -> Self

Anchored to the parent’s top-left corner.

Source

pub fn viewport() -> Self

Anchored to the viewport’s top-left corner.

Source

pub fn below() -> Self

Tooltip-style: hang below the parent, centered.

Source

pub fn above() -> Self

Tooltip-style: hover above the parent, centered.

Source

pub fn at(self, x: Align, y: Align) -> Self

The attach point on the anchor.

Source

pub fn self_at(self, x: Align, y: Align) -> Self

The attach point on the float itself.

Source

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.

Source

pub fn offset(self, x: f32, y: f32) -> Self

An extra offset after attaching, logical px.

Source

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.

Source

pub fn clipped(self) -> Self

Cut by the parent’s clip instead of escaping it; see FloatConfig::clip for which anchors read it.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for FloatConfig

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for FloatConfig

Source§

impl Debug for FloatConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FloatConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for FloatConfig

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for FloatConfig

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.