forked from Blendman974/faceclaw
Add partial rows and a bounce effect to menus
This commit is contained in:
1 parent
c801bd5185
commit
f66e0b025f
14 files changed
+259
-85
No files matched your search
@@ -68,8 +68,11 @@ exclude the changing elapsed duration. Without a timeline, raw `time()` expressi
|
||||
start at each PRESENT. Native compilation strips the bridge-only elapsed opcode.
|
||||
|
||||
`menu-selection-list.ts` authors both the rounded highlight and the transparent row
|
||||
image using this API. `menu-scroll-list.ts` authors a menu scroll: a viewport-sized
|
||||
copy from a strip resource whose source y animates, then the highlight. Navigation eligibility, duration, and easing remain in
|
||||
image using this API. `menu-scroll-list.ts` authors a menu scroll or bounce: a
|
||||
viewport-sized copy from a strip resource whose source y animates, then the
|
||||
highlight. The bounce curve (`app/ui/menu-scroll-motion.ts`) needs no branches:
|
||||
the easing ops clamp their input to 0..1, so `ease(t / p)` holds at 1 after the
|
||||
peak and `ease((t - p) / (1 - p))` holds at 0 before it. Navigation eligibility, duration, and easing remain in
|
||||
TypeScript. There is no animated-menu tag or menu animation policy in Kotlin.
|
||||
|
||||
## Bridge framing
|
||||
|
||||
@@ -61,9 +61,12 @@ export class DrawExpression<T extends 'i32' | 'f32'> {
|
||||
static elapsed(): DrawExpression<'i32'> { return new DrawExpression('i32', [ExprOp.ELAPSED]); }
|
||||
/**
|
||||
* A 0..1 timeline fraction that survives subsequent PRESENT clock resets.
|
||||
* With a delay, it stays 0 for the first delayMs of the timeline.
|
||||
* With a delay, it stays 0 for the first delayMs of the timeline; a
|
||||
* negative delay continues a motion that started before the timeline.
|
||||
*/
|
||||
static progress(durationMs: number, delayMs = 0): DrawExpression<'f32'> {
|
||||
integer(delayMs, -2147483647, 2147483647);
|
||||
if (delayMs + durationMs <= 0) return DrawExpression.f32(1);
|
||||
const duration = DrawExpression.i32(integer(durationMs, 1, 2147483647));
|
||||
const end = DrawExpression.i32(integer(delayMs + durationMs, 1, 2147483647));
|
||||
const elapsed = DrawExpression.elapsed().min(end);
|
||||
|
||||
@@ -1,46 +1,45 @@
|
||||
import type { MenuHighlightAnimation } from '../ui/menu-highlight-motion';
|
||||
import type { MenuScrollAnimation } from '../ui/menu-scroll-motion';
|
||||
import { DrawExpression as E, type DrawValue } from './draw-expression';
|
||||
import { DrawOp, type DisplayList, type ListCall, type ListImage } from './display-list';
|
||||
|
||||
export type MenuScrollHighlight = {
|
||||
/** Final row top within the viewport. */
|
||||
y: number;
|
||||
/** Row top within the viewport; clamped inside it. */
|
||||
y: DrawValue;
|
||||
width: number;
|
||||
height: number;
|
||||
radius: number;
|
||||
/** Gray8, like drawMenuSelection. */
|
||||
background: number;
|
||||
border: number;
|
||||
animation?: MenuHighlightAnimation;
|
||||
};
|
||||
|
||||
/**
|
||||
* A menu viewport scrolling over a pre-rendered strip. `strip` holds every
|
||||
* row that is visible at any point of the scroll, starting at content offset
|
||||
* `stripTop` and `stripX` pixels into the viewport. The copy's source row is
|
||||
* the animated value; the highlight is max-blended over the copied rows,
|
||||
* sliding on the same timeline and clamped inside the viewport.
|
||||
* A highlight sliding by (0, dy) to rest at `y`, on a list timeline that
|
||||
* started at `timelineStart` (the slide may have started before or after it).
|
||||
*/
|
||||
export function menuScrollList(strip: ListImage, stripX: number, stripTop: number, viewportHeight: number,
|
||||
scroll: MenuScrollAnimation, highlight?: MenuScrollHighlight): DisplayList {
|
||||
const eased = (durationMs: number, delayMs = 0) => E.progress(durationMs, delayMs).ease();
|
||||
const sourceY: DrawValue = eased(scroll.durationMs)
|
||||
.lerp(E.i32(scroll.from - stripTop).toFloat(), E.i32(scroll.to - stripTop).toFloat()).toInt();
|
||||
export function slidingHighlightY(y: number, motion: MenuHighlightAnimation | undefined, timelineStart: number): E<'i32'> {
|
||||
if (!motion?.dy) return E.i32(y);
|
||||
return E.progress(motion.durationMs, motion.startedAt - timelineStart).ease()
|
||||
.lerp(E.i32(y + motion.dy).toFloat(), E.i32(y).toFloat()).toInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* A menu viewport moving over a pre-rendered strip. `strip` holds every row
|
||||
* visible at any point of the motion, and sits `stripX` pixels into the
|
||||
* viewport; `sourceY` is the strip row at the viewport's top, animated on
|
||||
* `timeline`. The highlight is max-blended over the copied rows.
|
||||
*/
|
||||
export function menuScrollList(strip: ListImage, stripX: number, viewportHeight: number,
|
||||
timeline: { token: number; startedAt: number }, sourceY: DrawValue, highlight?: MenuScrollHighlight): DisplayList {
|
||||
const calls: ListCall[] = [
|
||||
{ op: DrawOp.RECT_COPY, resource: 0, x: 0, y: sourceY, width: strip.width, height: viewportHeight, dx: stripX, dy: 0 },
|
||||
];
|
||||
if (highlight) {
|
||||
const q = (n: number) => Math.min(15, (n + 8) >> 4);
|
||||
const motion = highlight.animation;
|
||||
let y: DrawValue = highlight.y;
|
||||
if (motion?.dy) {
|
||||
const delay = Math.max(0, motion.startedAt - scroll.startedAt);
|
||||
y = eased(motion.durationMs, delay).lerp(E.i32(highlight.y + motion.dy).toFloat(), E.i32(highlight.y).toFloat()).toInt()
|
||||
.max(E.i32(0)).min(E.i32(viewportHeight - highlight.height));
|
||||
}
|
||||
const y = typeof highlight.y === 'number' ? highlight.y
|
||||
: highlight.y.max(E.i32(0)).min(E.i32(viewportHeight - highlight.height));
|
||||
calls.push({ op: DrawOp.ROUNDED_RECT, x: 0, y, width: highlight.width, height: highlight.height, radius: highlight.radius,
|
||||
background: q(highlight.background), border: q(highlight.border) });
|
||||
}
|
||||
return { resources: [strip], timeline: scroll, calls };
|
||||
return { resources: [strip], timeline: { token: timeline.token, startedAt: timeline.startedAt }, calls };
|
||||
}
|
||||
Reference in new issue
Block a user