amenui
en·中 github ↗ v0.0.1
01docs 02components 03lab 04works
en·中github ↗
×

docs / components / layout / floating docs / components / layout /

floating

04.37
On this page ▾
  1. Installation
  2. Usage
  3. API
  4. Keyboard and accessibility

A small box floating over an area (picture in picture): drag it anywhere; let go, the throw's projected end picks the nearest corner and a spring takes it there.

Arrow keys move it between corners. Dragged, thrown and gliding, it leaves a trail in the field map (El::stirr; the preset sets how strong): decoration it passes loosens a little and drifts the way it went.

drawn by amenuiopen ↗

Installation

Components are distributed as source. Copy it and what it depends on into your project, then change it as you need:

sh
cargo run --release --bin amenui -- add floating --to ../my-app

Files copied: src/widgets/floating.rs, src/gesture.rs, src/widgets/mod.rs

Usage

rust
use amenui::widgets::{floating};

fn view() -> El<Msg> {
    let mut f = Floating::default();
    f.area = (300.0, 180.0);
    f.size = (120.0, 72.0);
    f.place(3);
    layers([floating("fl1", &f, text("00:42", 12.0, Paint::TEXT).key("fl1/t"), Msg::Float)])
        .width(300.0).height(180.0).radius(8.0).border(1.0, Paint::FAINT).clip()
}

API

Functionsfloating
Propskey, floating (Floating: size, area, corner_inset, projection_decel, spring, rubber), content, msg.
Filessrc/widgets/floating.rs, src/gesture.rs
Depends onbase
Response to frontsnudge (a control: pushed as one piece by fronts, held and condensing at most to Look::legible_cap)
Recompositionkeyed labels recompose when their text changes

Keyboard and accessibility

Statesresting in a corner, dragged (captured until release), springing to a corner; arrow keys move it to the neighbouring corner when focused.
Keys and messagesmsg(FloatMsg) for every drag step and arrow key; the application calls Floating::update with it and Floating::step on every tick while Floating::moving().

On the web every control is mirrored into the page as an element with its role and name, so screen readers and the browser's own focus see it (DESIGN.md §1.14).

Recipes: Gestures: a bottom sheet and a floating box