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() -> FloatConfig

Anchored to the parent’s top-left corner.

Source

pub fn viewport() -> FloatConfig

Anchored to the viewport’s top-left corner.

Source

pub fn below() -> FloatConfig

Tooltip-style: hang below the parent, centered.

Source

pub fn above() -> FloatConfig

Tooltip-style: hover above the parent, centered.

Source

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

The attach point on the anchor.

Source

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

The attach point on the float itself.

Source

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.

Source

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

An extra offset after attaching, logical px.

Source

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.

Source

pub fn clipped(self) -> FloatConfig

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<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.

Source

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.

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, ) -> 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

Source§

fn clone(&self) -> FloatConfig

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<(), Error>

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

impl Default for FloatConfig

Source§

fn default() -> FloatConfig

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

impl PartialEq for FloatConfig

Source§

fn eq(&self, other: &FloatConfig) -> 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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
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> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more