Floating and shift
Two ways to put a box somewhere the flow did not: take it out of the flow with floats(), or move it after placement with a shift.
Floating
floats() takes a box out of the flow and places it against the parent's content box. It is the only way to put one box over another. Siblings lay out as if it were not there.
Shift
lay_style::shift(x, y) moves a box and its whole subtree after placement, by units. shift_pct(fx, fy) adds a fraction of the parent's content box. Both are applied after the solve, so siblings keep the slots they were given and nothing reflows. That makes shift the right tool for hover lifts, nudges, and anything that animates position every frame.
ui::style::offset(x, y) maps to this. It sets lay.shift_x and lay.shift_y, the unit part of the shift, and works on any box, floating or not. There is no element api spelling for the fraction, so set it on style.lay with shift_pct before declaring the box.
offset(0, -14) plus shift_pct(0.00, 0), which is a fraction of the row's content width. Its dashed slot stays where the solver put it, and the other cards do not move.#include "isolenui/ui/ui.h"
// offset moves a box and everything inside it after placement, siblings
// keep the slots they were given, so a lift on hover never reflows a row.
// lift lives in the caller's state and is eased inside the card it belongs to
static void lifting_cards(ui::ctx* u, float* lift, uint32_t count)
{
ui_box(u, ui::row().gap(12.0f).pad(12.0f))
{
for (uint32_t i = 0; i < count; ++i) {
ui::key(u, uint64_t(i));
ui_box(u, ui::col().width(140.0f).height(90.0f).pad(12.0f)
.round(10.0f).bg(0xff1a1a1au).offset(0.0f, -6.0f * lift[i]))
{
// interact and ease both key to the card just opened
const ui::hit h = ui::interact(u);
lift[i] = ui::ease(u, 0u, h.hovered ? 1.0f : 0.0f, 10.0f);
ui::textf(u, ui::caption(u), "card %u", i);
}
}
}
}
// floats takes a box out of the flow and places it against the parent's
// content box, offset then nudges it by pixels
static void dismiss_corner(ui::ctx* u)
{
ui_box(u, ui::col().width(200.0f).height(120.0f).bg(0xff141414u))
{
ui_box(u, ui::col().floats().offset(-8.0f, -8.0f).width(24.0f).height(24.0f)
.centre().bg(0xffe5648au).round(12.0f))
{
ui::text(u, "x", ui::caption(u));
}
}
}
// offset only sets the pixel part, the fraction of the parent content box
// lives on lay_style, so a playhead at t of the track is built first and
// then declared, the px part centres the 2 px line on its position
static void timeline(ui::ctx* u, float t)
{
ui_box(u, ui::col().grow().height(32.0f).round(6.0f).bg(0xff161616u))
{
ui::style head = ui::col().floats().width(2.0f).height(lay_pct(1.0f)).bg(0xffe5648au);
head.lay.shift_pct(t, 0.0f).shift(-1.0f, 0.0f);
ui_box(u, head) {}
}
}