|
RMGui 0.15.0
C11 retained-mode UI library: layout kernel, style schema, widget painters, fonts, software framebuffer
|
element_motion.h — one element's authored interaction motion: hover glow, press pop, drag lift, attention shake and refusal shake, as a class's resolved style record (rmgui_style_motion_resolved_t) describes them. More...
Data Structures | |
| struct | rmgui_element_motion_recipe_t |
| Immutable built-in recipe data, in order: hover glow, press pop, lift, attention sine, refusal noise, drag sway. More... | |
| struct | rmgui_element_motion_t |
| One element's motion state. More... | |
| struct | rmgui_element_sway_t |
| One element's drag sway: while the host drags it, the element leans in the direction the pointer moves, as far as its horizontal speed (up to a full lean at 1000 logical px/s), and springs back upright when the pointer rests 50 ms or the drag ends; an impulse rings it, dragged or not. More... | |
Macros | |
| #define | RMGUI_ELEMENT_MOTION_HOVER 0x1u |
| Level: the pointer is over the element (drives the hover glow). | |
| #define | RMGUI_ELEMENT_MOTION_PRESSED 0x2u |
| Level: a primary press is held on the element (drives the press pop). | |
| #define | RMGUI_ELEMENT_MOTION_LIFTED 0x4u |
| Level: the element is being dragged (drives the lift scale and shadow). | |
| #define | RMGUI_ELEMENT_MOTION_SHAKE 0x8u |
| Query channel: the attention shake's envelope (see rmgui_element_motion_progress); never a level. | |
| #define | RMGUI_ELEMENT_MOTION_REFUSAL 0x10u |
| Query channel: the refusal shake's envelope (see rmgui_element_motion_progress); never a level. | |
| #define | RMGUI_ELEMENT_MOTION_RECIPE_COUNT 6 |
| Number of read-only built-in recipes; the array has static lifetime. | |
| #define | RMGUI_ELEMENT_MOTION_VISUAL_TRANSFORM 0x1u |
| Visual flag: *t is not the identity (an offset or a scale). | |
| #define | RMGUI_ELEMENT_MOTION_VISUAL_SHADOW 0x2u |
| Visual flag: *shadow casts (its color.a > 0). | |
Functions | |
| void | rmgui_element_motion_init (rmgui_element_motion_t *m, const rmgui_style_motion_resolved_t *style) |
| Puts *m at rest: no level held, every spring at 0 with style's spring constants, no shake running. | |
| int | rmgui_element_motion_set_levels (rmgui_element_motion_t *m, unsigned levels) |
| Holds exactly levels (a bitwise OR of the RMGUI_ELEMENT_MOTION_ level flags; other bits, the SHAKE and REFUSAL query channels included, are ignored): each held level's spring heads to full progress, each released one back to 0. | |
| int | rmgui_element_motion_shake (rmgui_element_motion_t *m, const rmgui_style_motion_resolved_t *style) |
| Starts the attention shake from its beginning (restarting one already running): a sine wave of 72 ms period, phase counted from the trigger, and press_shake_amplitude_px device px, decaying to 0 as 1 - OUT_QUAD over press_shake_duration_ms. | |
| int | rmgui_element_motion_refuse (rmgui_element_motion_t *m, const rmgui_style_motion_resolved_t *style, uint32_t seed) |
| Starts the refusal shake from its beginning (restarting one already running): value noise of seed, one lattice cell per 36 ms counted from the trigger, of refusal_shake_amplitude_px device px, decaying to 0 as 1 - OUT_QUAD over refusal_shake_duration_ms. | |
| int | rmgui_element_motion_step (rmgui_element_motion_t *m, const rmgui_style_motion_resolved_t *style, uint16_t dt_ms) |
| Advances *m by dt_ms. | |
| int | rmgui_element_motion_is_at_rest (const rmgui_element_motion_t *m) |
| 1 when no level is held, every spring rests at 0 and no shake runs: the host may then drop the state (a fresh init with the same style is equivalent). | |
| int | rmgui_element_motion_is_moving (const rmgui_element_motion_t *m) |
| 1 when the next step of any dt > 0 would advance a spring or a shake, so the visual may change and the host should keep waking; a spring's last settling toward its rest may change nothing visible. | |
| int32_t | rmgui_element_motion_progress (const rmgui_element_motion_t *m, unsigned channel) |
| Q16 progress of exactly one channel. | |
| unsigned | rmgui_element_motion_visual (const rmgui_element_motion_t *m, const rmgui_style_resolved_t *rs, rmgui_corner_radii_t radii, rmgui_layer_transform_t *t, rmgui_layer_shadow_t *shadow) |
| The paint-only visual of the element painted from rs, the record resolved for its class, at UI scale rs->scale_percent (clamped into 1..400). | |
| void | rmgui_element_sway_init (rmgui_element_sway_t *s, const rmgui_style_motion_resolved_t *style) |
| Puts *s upright at rest with style's spring constants (clamped as rmgui_element_motion_init clamps them), no drag sampled. | |
| int | rmgui_element_sway_grab (rmgui_element_sway_t *s) |
| The drag starts: speed sampling starts now, the lean heads upright (a sway still settling keeps its position and velocity) and the rest deadline is disarmed. | |
| int | rmgui_element_sway_drag (rmgui_element_sway_t *s, int dx_px, int scale_percent) |
| Between a grab and its release, the dragged pointer moved dx_px device px horizontally (positive right) at UI scale scale_percent (1..400; clamped into that range). | |
| int | rmgui_element_sway_release (rmgui_element_sway_t *s) |
| The drag ends: the lean heads upright, the rest deadline is disarmed and sampling stops until the next grab. | |
| int | rmgui_element_sway_impulse (rmgui_element_sway_t *s, int32_t amplitude_q16) |
| Kicks the lean, as a jolt does: adds to the lean's velocity the swing that would carry an undamped lean amplitude_q16 off its target, in Q16 full leans (RMGUI_MOTION_ONE swings to the rotation rmgui_element_sway_turns_q16 reads as max_deg; positive swings clockwise first). | |
| int | rmgui_element_sway_step (rmgui_element_sway_t *s, const rmgui_style_motion_resolved_t *style, uint16_t dt_ms) |
| Advances *s by dt_ms: re-applies style's spring constants (clamped as at init) keeping the lean's position and velocity, then steps the lean, sending it upright at the exact clock time the rest deadline falls within the step. | |
| int | rmgui_element_sway_is_moving (const rmgui_element_sway_t *s) |
| 1 when a step of some dt > 0 would move the lean or send it upright, so the host should keep waking; 0 guarantees no step changes the rotation until a drag or impulse call. | |
| int32_t | rmgui_element_sway_turns_q16 (const rmgui_element_sway_t *s, int32_t max_deg_q16) |
| The lean as a layer rotation (rmgui_layer_transform_t rotation_turns_q16): the lean's progress (ONE at a full lean clockwise, overshooting with the spring) times max_deg_q16 Q16 degrees, in Q16 turns, rounded half away from zero and clamped to the int32 range. | |
Variables | |
| const rmgui_element_motion_recipe_t | rmgui_element_motion_recipes [RMGUI_ELEMENT_MOTION_RECIPE_COUNT] |
| Readable data used by the built-in motion evaluator, not editable state. | |
element_motion.h — one element's authored interaction motion: hover glow, press pop, drag lift, attention shake and refusal shake, as a class's resolved style record (rmgui_style_motion_resolved_t) describes them.
Protocol: the host reports the levels it holds (hover, press, lift) and fires one-shot triggers (shake, refuse), advances the state by clock dt with rmgui_element_motion_step, and reads a paint-only layer transform and shadow with rmgui_element_motion_visual to paint the element through layer.h. The visual is a pure integer function of (resolved style, levels and triggers, dt sequence): no clock, no allocation, no global state, the same bytes on every target. The state is caller-owned and has no resources; dropping it needs no call.
Levels drive damped springs (motion.h) from progress 0 toward 1 while held and back to 0 once released; springy constants overshoot both ways. Shakes are horizontal whole-pixel offsets, so a shake alone keeps the layer on its direct (unallocated, byte-identical) path. A style whose pop and lift scales are 100% and whose shake amplitudes and glow/shadow colours are zero yields no visual for any input.
A separate caller-owned sway (rmgui_element_sway_t) leans a dragged element with the pointer's speed, and rocks it on an impulse, on the same spring constants; the host adds its rotation to the visual's transform.
| #define RMGUI_ELEMENT_MOTION_HOVER 0x1u |
Level: the pointer is over the element (drives the hover glow).
| #define RMGUI_ELEMENT_MOTION_PRESSED 0x2u |
Level: a primary press is held on the element (drives the press pop).
| #define RMGUI_ELEMENT_MOTION_LIFTED 0x4u |
Level: the element is being dragged (drives the lift scale and shadow).
| #define RMGUI_ELEMENT_MOTION_SHAKE 0x8u |
Query channel: the attention shake's envelope (see rmgui_element_motion_progress); never a level.
| #define RMGUI_ELEMENT_MOTION_REFUSAL 0x10u |
Query channel: the refusal shake's envelope (see rmgui_element_motion_progress); never a level.
| #define RMGUI_ELEMENT_MOTION_RECIPE_COUNT 6 |
Number of read-only built-in recipes; the array has static lifetime.
| #define RMGUI_ELEMENT_MOTION_VISUAL_TRANSFORM 0x1u |
Visual flag: *t is not the identity (an offset or a scale).
| #define RMGUI_ELEMENT_MOTION_VISUAL_SHADOW 0x2u |
Visual flag: *shadow casts (its color.a > 0).
| void rmgui_element_motion_init | ( | rmgui_element_motion_t * | m, |
| const rmgui_style_motion_resolved_t * | style ) |
Puts *m at rest: no level held, every spring at 0 with style's spring constants, no shake running.
Constants outside the range rmgui_motion_spring_init accepts are clamped into it. NULL m or style: no-op.
| int rmgui_element_motion_set_levels | ( | rmgui_element_motion_t * | m, |
| unsigned | levels ) |
Holds exactly levels (a bitwise OR of the RMGUI_ELEMENT_MOTION_ level flags; other bits, the SHAKE and REFUSAL query channels included, are ignored): each held level's spring heads to full progress, each released one back to 0.
Sets spring targets only; never starts a shake. Returns 1 when the held levels changed, 0 otherwise (including NULL m).
| int rmgui_element_motion_shake | ( | rmgui_element_motion_t * | m, |
| const rmgui_style_motion_resolved_t * | style ) |
Starts the attention shake from its beginning (restarting one already running): a sine wave of 72 ms period, phase counted from the trigger, and press_shake_amplitude_px device px, decaying to 0 as 1 - OUT_QUAD over press_shake_duration_ms.
The amplitude is read by each visual; the duration is read now and by each step (see rmgui_element_motion_step). Only the host triggers it; PRESSED never implies it. Returns 1 when it started the shake; 0, changing nothing, when the amplitude or the duration is 0, or m or style is NULL.
| int rmgui_element_motion_refuse | ( | rmgui_element_motion_t * | m, |
| const rmgui_style_motion_resolved_t * | style, | ||
| uint32_t | seed ) |
Starts the refusal shake from its beginning (restarting one already running): value noise of seed, one lattice cell per 36 ms counted from the trigger, of refusal_shake_amplitude_px device px, decaying to 0 as 1 - OUT_QUAD over refusal_shake_duration_ms.
The amplitude is read by each visual; the duration is read now and by each step. Returns 1 when it started the shake; 0, changing nothing, when the amplitude or the duration is 0, or m or style is NULL.
| int rmgui_element_motion_step | ( | rmgui_element_motion_t * | m, |
| const rmgui_style_motion_resolved_t * | style, | ||
| uint16_t | dt_ms ) |
Advances *m by dt_ms.
First applies the style's current values without a jump: re-applies its spring constants (clamped as at init) keeping each spring's position and velocity, and retimes each running shake whose authored duration changed so its envelope keeps the same fraction (elapsed scaled by new / old, rounded) while its wave phase keeps counting from the trigger; a shake retimed to 0 ms, or already finished, is finished. Returns 1 when a spring or a shake advanced or a running shake was retimed, 0 otherwise (all at rest with no retime, dt 0 with no retime, or m or style NULL). Stepping by a then by b under one style leaves exactly the state stepping by a + b leaves.
| int rmgui_element_motion_is_at_rest | ( | const rmgui_element_motion_t * | m | ) |
1 when no level is held, every spring rests at 0 and no shake runs: the host may then drop the state (a fresh init with the same style is equivalent).
0 otherwise, or for NULL.
| int rmgui_element_motion_is_moving | ( | const rmgui_element_motion_t * | m | ) |
1 when the next step of any dt > 0 would advance a spring or a shake, so the visual may change and the host should keep waking; a spring's last settling toward its rest may change nothing visible.
0 guarantees no step changes the visual until a level or trigger changes. NULL: 0.
| int32_t rmgui_element_motion_progress | ( | const rmgui_element_motion_t * | m, |
| unsigned | channel ) |
Q16 progress of exactly one channel.
HOVER, PRESSED, LIFTED: the level's spring progress, 0 at rest-off and ONE at rest-on; may overshoot. SHAKE, REFUSAL: the envelope's OUT_QUAD progress, ONE when finished or never started. NULL, zero, or more than one bit returns 0.
| unsigned rmgui_element_motion_visual | ( | const rmgui_element_motion_t * | m, |
| const rmgui_style_resolved_t * | rs, | ||
| rmgui_corner_radii_t | radii, | ||
| rmgui_layer_transform_t * | t, | ||
| rmgui_layer_shadow_t * | shadow ) |
The paint-only visual of the element painted from rs, the record resolved for its class, at UI scale rs->scale_percent (clamped into 1..400).
The motion is rs->motion. Pass the SAME device-pixel radii value to this function and rmgui_draw_fill_rounded_corners; the transform scales both together. Built-in element painters use the uniform rmgui_corner_radii_uniform(rs->corner_radius). Writes *t and *shadow: t: offset_x = shake + refusal, whole device px; scale_x = scale_y = the press pop (1 to press_pop_scale_q16) times the lift (1 to lift_scale_q16), each mixed by its spring's progress, clamped to layer.h's scale range; no rotation, opacity 255, bilinear. shadow: the lift shadow when it casts (OVER, lift_shadow with alpha mixed from 0 by lift progress, lift_shadow_blur_px, dropped offset_y from 2 to 14 logical px scaled by scale_percent); otherwise the hover glow when it casts (ADD, hover_glow with alpha 3/8 of hover_glow.a, mixed from 0 by hover progress and rounded; hover_glow_blur_px > 0 required, no offset; layer.h keeps a glow off the element's own face); otherwise color.a 0. Blur is the authored device-pixel value; callers allow it in their layer; radii are the supplied face radii, negative components count as 0. Returns the RMGUI_ELEMENT_MOTION_VISUAL_ flags; 0 means paint plainly. A NULL m or rs writes the identity and a non-casting shadow and returns 0; a NULL t or shadow writes nothing and returns 0.
| void rmgui_element_sway_init | ( | rmgui_element_sway_t * | s, |
| const rmgui_style_motion_resolved_t * | style ) |
Puts *s upright at rest with style's spring constants (clamped as rmgui_element_motion_init clamps them), no drag sampled.
NULL s or style: no-op.
| int rmgui_element_sway_grab | ( | rmgui_element_sway_t * | s | ) |
The drag starts: speed sampling starts now, the lean heads upright (a sway still settling keeps its position and velocity) and the rest deadline is disarmed.
Grabbing while dragging restarts the drag. Returns 1 when *s changed, 0 otherwise (including NULL s).
| int rmgui_element_sway_drag | ( | rmgui_element_sway_t * | s, |
| int | dx_px, | ||
| int | scale_percent ) |
Between a grab and its release, the dragged pointer moved dx_px device px horizontally (positive right) at UI scale scale_percent (1..400; clamped into that range).
When clock time has been stepped since the sample started, the sample ends: its speed (the travel of every move in it per second of that time, rounded toward zero) over the full-lean speed, 1000 logical px/s scaled by scale_percent, rounded toward zero and clamped to one full lean each way, is the lean's new target (moving right leans clockwise), and the next sample starts. Moves at one clock time accumulate into one sample. Every move re-arms the rest deadline 50 ms of stepped clock ahead. Returns 1 when the lean's target changed; 0 otherwise, or outside a drag or for NULL s, which change nothing.
| int rmgui_element_sway_release | ( | rmgui_element_sway_t * | s | ) |
The drag ends: the lean heads upright, the rest deadline is disarmed and sampling stops until the next grab.
Returns 1 when *s changed, 0 otherwise (including NULL s).
| int rmgui_element_sway_impulse | ( | rmgui_element_sway_t * | s, |
| int32_t | amplitude_q16 ) |
Kicks the lean, as a jolt does: adds to the lean's velocity the swing that would carry an undamped lean amplitude_q16 off its target, in Q16 full leans (RMGUI_MOTION_ONE swings to the rotation rmgui_element_sway_turns_q16 reads as max_deg; positive swings clockwise first).
That velocity is amplitude * sqrt(stiffness) full leans per second at the spring stiffness of the last init or step, rounded half away from zero to the spring's resolution. amplitude_q16 is clamped to +-16 * RMGUI_MOTION_ONE, and the lean's velocity to what an impulse of that size gives. Steps then ring the lean about its target and bring it to rest there: the style's damping lowers the first swing below amplitude_q16 and sets how often it crosses the target. Impulses add, velocity for velocity, so equal and opposite impulses at one clock time cancel unless the first reached the velocity limit. Only the velocity changes: during a drag the lean rings about the drag's lean, and a grab, drag or release keeps the ringing (they change only where the lean heads). An impulse starts no drag, samples no speed and arms no deadline. Returns 1 when the lean's velocity changed; 0 when it did not (an amplitude that rounds to no velocity, an impulse toward a velocity already at its limit, or NULL s).
| int rmgui_element_sway_step | ( | rmgui_element_sway_t * | s, |
| const rmgui_style_motion_resolved_t * | style, | ||
| uint16_t | dt_ms ) |
Advances *s by dt_ms: re-applies style's spring constants (clamped as at init) keeping the lean's position and velocity, then steps the lean, sending it upright at the exact clock time the rest deadline falls within the step.
Returns 1 when the lean moved or its target changed, 0 otherwise (including NULL s or style). Stepping by a then by b leaves exactly the state stepping by a + b leaves.
| int rmgui_element_sway_is_moving | ( | const rmgui_element_sway_t * | s | ) |
1 when a step of some dt > 0 would move the lean or send it upright, so the host should keep waking; 0 guarantees no step changes the rotation until a drag or impulse call.
NULL: 0.
| int32_t rmgui_element_sway_turns_q16 | ( | const rmgui_element_sway_t * | s, |
| int32_t | max_deg_q16 ) |
The lean as a layer rotation (rmgui_layer_transform_t rotation_turns_q16): the lean's progress (ONE at a full lean clockwise, overshooting with the spring) times max_deg_q16 Q16 degrees, in Q16 turns, rounded half away from zero and clamped to the int32 range.
0 for NULL s.
|
extern |
Readable data used by the built-in motion evaluator, not editable state.