19 Commits
Author SHA1 Message Date
admin 808c18fb58 Merge pull request #27 from Alpaq92/release-0.3.0
Version 0.3.0
2026-10-06 19:53:43 +02:00
adminandClaude Opus 5.5 8c2f9cbc4f A release checks its tag against the version
The release notes take the find_package version from the tag, so a tag that
disagrees with CMakeLists.txt would publish packages and notes that do not
match. The source job now stops the release unless CMakeLists.txt and the
documentation's find_package line agree with the tag. NOTICE.md's paragraph
naming NukAnim is wrapped again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 19:49:14 +02:00
adminandClaude Opus 5.5 1bb65db393 The web canvas is square
The page rounded the canvas's top corners to stand in for a desktop window
manager's, and the page's own background showed through them. In a browser
the canvas is the page, so its corners are square now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 19:49:14 +02:00
adminandClaude Opus 5.5 9fcfe47728 Version 0.3.0
The version is 0.3.0, and the consumer example and the documentation ask
find_package for it; the release notes take it from the tag from now on.
The README and DEMO.md say what the animation does now, and DOCUMENTATION.md,
NOTICE.md and the release notes say a build compiles NukAnim in and installs
its header.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 18:59:53 +02:00
admin b741f81dbd Merge pull request #26 from Alpaq92/nukanim
Animation runs on NukAnim
2026-10-06 15:57:58 +02:00
adminandClaude Opus 5.5 5b15189d39 Animation runs on NukAnim
NukAnim, a submodule at external/nukanim, replaces core/anim's own tweens.
Each window keeps a NukAnim context: the runtime advances it before the page
and draws another frame while anything the page sampled still moves, so a
page at rest asks for none. reaktor_animate and the 31 REAKTOR_EASE_* curves
keep their names and meaning, and reaktor_anim(app) hands an application the
context for the rest of nukanim.h.

The showcase's Animation page shows it: its five tracks share one section,
and new sections cover clips staggered across a grid with NukAnim's debug
timeline, motion paths, procedural motion with a shaking password field,
five color spaces, and text arriving a glyph at a time. The ms property there
sat 8 px short of its row, squeezed by tiny.css's input margin; its row now
gives the three controls one height and wraps on a phone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 15:46:51 +02:00
admin ee8d1da49d Merge pull request #25 from Alpaq92/login-card-fits-phones
The login card fits a phone
2026-10-06 11:58:06 +02:00
adminandClaude Opus 5.5 95e5122ed0 The login card fits a phone
The card kept its 420 px on panels narrower than that, so on a phone it ran
off the right edge, clipping the field and the buttons. It now takes the
panel's width less 8 px a side, up to 420 px. Desktop pixels and the
accessibility dump are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 11:52:53 +02:00
admin 6ff47bce3b Merge pull request #24 from Alpaq92/touch-scrolling-and-fitting-buttons
A finger scrolls, and buttons fit their labels
2026-10-06 10:47:40 +02:00
adminandClaude Opus 5.5 42296886c6 Buttons fit their labels
Nuklear insets a button's label by its corner radius as well as its
padding, which CSS does not, so a button left to size itself cut the
end off its label. The runtime now hands Nuklear the padding less the
radius, and draws an icon beside a label itself, where Nuklear did.

A button too narrow for its icon and its label draws the label alone
instead of one over the other. .fit_content sizes a button to both,
whatever its box asks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 10:42:48 +02:00
adminandClaude Opus 5.5 93c636bc1c A finger scrolls
On a touchscreen a drag pressed whatever was under it and never
scrolled, since a touch reaches the runtime only as SDL's synthesized
mouse. A touch that moves mostly up or down, past 8 pixels, now
scrolls the panel under it: the runtime releases the press away from
every widget, so nothing is clicked, and turns the movement into wheel
steps sized to the page body or the window. A fast swipe coasts on
after the finger lifts and slows down; a touch catches it. Sideways
drags, and drags that start in a text field, stay drags.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 10:42:47 +02:00
admin 394ffacbaa Merge pull request #23 from Alpaq92/what-an-app-still-borrowed
What an app still borrowed
2026-10-06 09:20:31 +02:00
adminandClaude Opus 5.5 56e349bd51 What an app still borrowed
AntiClam, built against include/reaktor/ alone, still reached into
src/internal.h for four things a hand-laid page needs, with no public
call to stand in:

- reaktor_ionicon_exact and reaktor_glyph_at: an Ionicon in any color,
  as an image or drawn into a rectangle. reaktor_svg's query could
  rebuild the first, but only by copying the stroke widths the widgets
  pick.
- reaktor_button_icon and reaktor_field_text: the styled icon button and
  text field inside nk_ layouts. The declared reaktor_button and
  reaktor_field need a declared parent, so a page laid out with
  nk_layout_row_* had none.
- reaktor_icon_surface: an SVG asset as an SDL_Surface, for a tray of
  the app's own, as SDL_SetTrayIcon takes one.

Their declarations move from src/internal.h to ui.h and launch.h, which
internal.h already includes, so nothing inside Reaktor changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 09:17:26 +02:00
admin 73557404e2 Merge pull request #22 from Alpaq92/follow-the-system-language
Follow the system's language, and say what --lang asked for
2026-10-06 09:09:30 +02:00
adminandClaude Opus 5.5 3a5b9cc9b7 A note on bundle sizes
BENCHMARKS.md lists the size of Reaktor's four programs, measured on
Windows x64 with the C runtime linked in, and of every v0.2.0 download.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 08:43:56 +02:00
adminandClaude Opus 5.5 37f80df4b9 Follow the system's language, and say what --lang asked for
An application that keeps a language of its own must not override
--lang, and nothing public told it whether --lang was given: the runtime
strips the flag from argv before start() runs. reaktor_lang_pref(app)
answers with its value, or NULL.

Reaktor already opened in the system's language; now it keeps following
it. reaktor_locale_set(NULL) follows the system and
reaktor_locale_system() says whether it does; a code picks a language
and stops following. When the system's language changes, the runtime
switches and redraws every window. The showcase's language row starts
with System, and localetest covers the new state with a stand-in for
SDL's preferred locales.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 08:43:55 +02:00
adminandClaude Opus 5.5 3b41f696c1 build.ps1 takes absolute paths
-Out and -Source joined their value onto the current directory, so an
absolute path came out as an invalid one. They now resolve as PowerShell
resolves any path: relative to where the script runs, or as given.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 08:43:54 +02:00
admin 839873fb7f Merge pull request #21 from Alpaq92/no-but-i-was
No? But I was
2026-10-05 17:13:18 +02:00
adminandClaude Opus 5.5 311e1fdd89 No? But I was
The README's pitch asks whether you are tired of C having no
cross-platform GUI and then answers for you. It lost the "No?" that
made that a joke when the paragraph was rewritten in 0de1f81; it is
back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 16:57:51 +02:00
33 changed files with 1304 additions and 399 deletions
+18 -4
View File
@@ -44,6 +44,19 @@ jobs:
persist-credentials: false
path: src
- name: Version
run: |
v=${GITHUB_REF_NAME#v}
v=${v%%-*}
if ! grep -qF "project(reaktor VERSION $v " src/CMakeLists.txt; then
echo "$GITHUB_REF_NAME, but CMakeLists.txt is not at $v"
exit 1
fi
if ! grep -qF "find_package(reaktor ${v%.*} REQUIRED)" src/docs/DOCUMENTATION.md; then
echo "$GITHUB_REF_NAME, but docs/DOCUMENTATION.md does not ask find_package for ${v%.*}"
exit 1
fi
- name: Archive
run: |
name="reaktor-${GITHUB_REF_NAME#v}-source"
@@ -110,12 +123,13 @@ jobs:
systems and architectures, \`libreaktor-$v-<system>-<arch>\`, and
\`libreaktor-$v-wasm.tar.gz\`. Each holds one static library (\`reaktor.lib\`
on Windows, built against the DLL C runtime; \`libreaktor.a\` elsewhere)
with SDL, libcss, plutosvg, Onlay, mojibake and kb_text_shape inside it,
the public headers (\`#include "reaktor/reaktor.h"\`, with Nuklear's and
SDL's), a CMake package and a pkg-config file, and the licenses.
with SDL, libcss, plutosvg, Onlay, NukAnim, mojibake and kb_text_shape
inside it, the public headers (\`#include "reaktor/reaktor.h"\`, with
Nuklear's, NukAnim's and SDL's), a CMake package and a pkg-config file,
and the licenses.
\`\`\`cmake
find_package(reaktor 0.2 REQUIRED) # with CMAKE_PREFIX_PATH at the unpacked folder
find_package(reaktor ${v%.*} REQUIRED) # with CMAKE_PREFIX_PATH at the unpacked folder
add_executable(app WIN32 main.c)
target_link_libraries(app PRIVATE reaktor::reaktor)
\`\`\`
+3
View File
@@ -28,3 +28,6 @@
[submodule "external/kb"]
path = external/kb
url = https://github.com/JimmyLefevre/kb.git
[submodule "external/nukanim"]
path = external/nukanim
url = https://github.com/Alpaq92/NukAnim.git
+8 -8
View File
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.16)
project(reaktor VERSION 0.2.0 LANGUAGES C CXX)
project(reaktor VERSION 0.3.0 LANGUAGES C CXX)
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(_reaktor_top ON)
@@ -182,7 +182,7 @@ endif()
message(STATUS "assets: ${_n} compiled in")
add_library(reaktor_headers INTERFACE)
target_include_directories(reaktor_headers INTERFACE include "${TP}/nuklear")
target_include_directories(reaktor_headers INTERFACE include "${TP}/nuklear" "${TP}/nukanim")
add_library(reaktor_core STATIC
core/base/util.c
@@ -217,11 +217,10 @@ if(REAKTOR_TESTS AND NOT EMSCRIPTEN)
endif()
if(REAKTOR_TESTS AND NOT EMSCRIPTEN)
add_executable(animtest tools/animtest.c core/anim/anim.c)
target_link_libraries(animtest PRIVATE reaktor_headers)
target_include_directories(animtest PRIVATE core/anim core/a11y core/render
platform)
target_link_libraries(animtest PRIVATE SDL3::SDL3)
add_executable(animtest tools/animtest.c core/anim/anim.c core/render/nk_impl.c)
target_include_directories(animtest PRIVATE core/anim core/render
"${TP}/nuklear/demo/sdl3_renderer")
target_link_libraries(animtest PRIVATE reaktor_core SDL3::SDL3-static)
set_target_properties(animtest PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
@@ -471,7 +470,7 @@ set(REAKTOR_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" CACHE INTERNAL "")
# MIT wants each notice in every copy: they go beside the programs, unchanged.
foreach(_lic SDL/LICENSE.txt lcui/LICENSE.TXT plutosvg/LICENSE nuklear/LICENSE
onlay/LICENSE tinycss/LICENSE ionicons/LICENSE mojibake/LICENSE
nukanim/LICENSE onlay/LICENSE tinycss/LICENSE ionicons/LICENSE mojibake/LICENSE
kb/LICENSE)
string(REGEX REPLACE "/.*" "" _who "${_lic}")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/external/${_lic}"
@@ -909,6 +908,7 @@ if(REAKTOR_INSTALL)
install(FILES "${_lib}" DESTINATION lib COMPONENT libreaktor OPTIONAL)
install(DIRECTORY include/reaktor DESTINATION include COMPONENT libreaktor)
install(FILES "${TP}/nuklear/nuklear.h" DESTINATION include COMPONENT libreaktor)
install(FILES "${TP}/nukanim/nukanim.h" DESTINATION include COMPONENT libreaktor)
install(DIRECTORY "${TP}/SDL/include/SDL3" DESTINATION include COMPONENT libreaktor)
install(FILES "${CMAKE_BINARY_DIR}/reaktorConfig.cmake"
"${CMAKE_BINARY_DIR}/reaktorConfigVersion.cmake"
+8 -3
View File
@@ -10,8 +10,9 @@ Tired of C having no cross-platform GUI — nothing like
[Avalonia](https://github.com/avaloniaui/avalonia),
[Shaft](https://github.com/ShaftUI/Shaft) or
[Freya](https://github.com/marc2332/freya) — and of toolkits that want hundreds
of megabytes to put a dialog on screen? I was. So I wrote Reaktor: complete
without being big. A 2.3 MB binary, about 10 MB of RAM, and no GPU required.
of megabytes to put a dialog on screen? No? But I was, so I wrote Reaktor:
complete without being big. A 2.3 MB binary, about 10 MB of RAM, and no GPU
required.
**[Try the showcase in your browser](https://alpaq92.github.io/Reaktor/)** — the
same program, built to WebAssembly — or
@@ -42,7 +43,10 @@ How, and on what, is in [PERFORMANCE.md](docs/PERFORMANCE.md).
each language writes them.
- **Text past Latin-1** — direction, shaping, fallback fonts and Unicode line
breaking, so Japanese wraps properly.
- **Animation** — 31 easing curves, keyed per widget.
- **Animation** — tweens keyed per widget on 31 curves, springs, steps and
béziers; keyframed clips staggered across a grid; motion paths,
oscillators, noise and shakes; colors blended in five spaces; and text
that arrives a glyph at a time.
- **Modular** — accessibility, localization and text shaping each swap for a
stub, and only what they drew stops being drawn.
- **Windows, macOS, Linux, the BSDs and WebAssembly** from one set of sources,
@@ -99,6 +103,7 @@ value and position.
software renderer. libcss, from [LCUI](https://github.com/lc-soft/LCUI), parses
the stylesheets, and [Onlay](https://github.com/Alpaq92/Onlay), a fork of
[randrew/layout](https://github.com/randrew/layout), computes the rectangles.
[NukAnim](https://github.com/Alpaq92/NukAnim), a port of ImAnim, moves them.
Every dependency is a submodule, used as it ships; the full list is in
[NOTICE.md](docs/NOTICE.md).
+47
View File
@@ -132,3 +132,50 @@ colliding with Shaft itself.
exactly one more. Skipping vsyncs that are not due looks simpler and drifts:
to 41.6 fps in Flutter and 42.7 in Compose, which is why every arm prints
`fps`.
## Bundle sizes
Reaktor's arm ships as one file. SDL, the CSS engine, the SVG rasterizer, the
fonts and the default look are linked into every program, so `bench.exe`
needs nothing beside it. Built the way the release builds them — Windows x64,
MSVC 14.44 Release, the C runtime linked in:
| Program | Bytes |
| --- | --- |
| `bench.exe` | 2,752,512 |
| `simple.exe` | 2,760,192 |
| `notepad.exe` | 2,797,568 |
| `showcase.exe` | 3,782,656 |
The C runtime is about 300 KB of each; a default `./build.ps1` links its DLL
instead. Only the showcase links the three optional modules, and Text is
0.8 MB of the difference ([Modules](../docs/PERFORMANCE.md#modules)).
The v0.2.0 downloads, as GitHub Actions built and published them:
| System | Architecture | Programs | libreaktor |
| --- | --- | --- | --- |
| Windows | x64 | 6.2 MB | 4.4 MB |
| Windows | x86 | 5.4 MB | 3.6 MB |
| Windows | ARM64 | 5.6 MB | 4.4 MB |
| macOS | Apple silicon | 8.3 MB | 2.8 MB |
| macOS | Intel | 9.2 MB | 2.9 MB |
| Linux | x86-64 | 7.6 MB | 3.2 MB |
| Linux | x86 | 7.2 MB | 3.1 MB |
| Linux | ARM64 | 7.0 MB | 3.1 MB |
| Linux | ARMv7 | 5.7 MB | 2.6 MB |
| Linux | RISC-V 64 | 7.3 MB | 5.1 MB |
| FreeBSD 15.1 | x86-64 | 6.4 MB | 2.9 MB |
| FreeBSD 15.1 | ARM64 | 5.9 MB | 2.8 MB |
| OpenBSD 7.9 | x86-64 | 6.9 MB | 3.3 MB |
| OpenBSD 7.9 | ARM64 | 6.7 MB | 3.4 MB |
| NetBSD 11.0 | x86-64 | 7.1 MB | 3.0 MB |
| NetBSD 11.0 | ARM64 | 6.8 MB | 3.0 MB |
| Web | WebAssembly | 2.7 MB | 2.0 MB |
A program archive holds the showcase, Notepad, Simple and, natively, the
bench, with the files they read at runtime and every license; macOS's also
carries the showcase as `reaktor.app`. A libreaktor archive is one static
library with the public headers, Nuklear's and SDL's, a CMake package, a
pkg-config file outside Windows, and the licenses. The source, every submodule
included, is 23.2 MB.
+2 -2
View File
@@ -12,8 +12,8 @@ $hostArch = switch ([System.Runtime.InteropServices.RuntimeInformation]::OSArchi
}
if (-not $Arch) { $Arch = $hostArch }
$outDir = Join-Path $root $(if ($Arch -eq $hostArch) { "build" } else { "build-$Arch" })
if ($Out) { $outDir = [System.IO.Path]::GetFullPath((Join-Path (Get-Location) $Out)) }
$srcDir = if ($Source) { [System.IO.Path]::GetFullPath((Join-Path (Get-Location) $Source)) } else { $root }
if ($Out) { $outDir = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Out) }
$srcDir = if ($Source) { $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Source) } else { $root }
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
if (-not (Test-Path $vswhere)) { throw "vswhere.exe not found - install Visual Studio Build Tools" }
+55 -255
View File
@@ -1,140 +1,73 @@
#include <math.h>
#include <SDL3/SDL.h>
#include "reaktor/nuklear.h"
#define NUKANIM_IMPLEMENTATION
#include <nukanim.h>
#include "anim.h"
#define REAKTOR_ANIM_SLOTS 128
typedef char reaktor_curves_are_nukanims[(unsigned)REAKTOR_EASE_BOUNCE_IN_OUT == (unsigned)NKA_EASE_IN_OUT_BOUNCE ? 1 : -1];
typedef struct reaktor_anim_slot {
const void *owner;
unsigned key;
float from, to, value;
float elapsed, duration;
unsigned char curve;
unsigned char moving;
unsigned char started;
unsigned char seen;
unsigned char dead;
} reaktor_anim_slot;
static struct nka_context *g_anim;
static reaktor_anim_slot g_slot[REAKTOR_ANIM_SLOTS];
static const void *g_scope;
#define PI_F 3.14159265358979323846f
static float
pow_in(float t, int n)
static void *
anim_alloc(nk_handle h, void *old, nk_size n)
{
float r = t;
int i;
for (i = 1; i < n; i++) r *= t;
return r;
(void)h;
(void)old;
return SDL_malloc(n);
}
static float
pow_out(float t, int n)
static void
anim_free(nk_handle h, void *p)
{
float r = pow_in(1.0f - t, n);
return 1.0f - r;
(void)h;
SDL_free(p);
}
static float
pow_in_out(float t, int n)
struct nka_context *
reaktor_anim_create(void)
{
if (t < 0.5f) return pow_in(2.0f * t, n) * 0.5f;
return 1.0f - pow_in(2.0f * (1.0f - t), n) * 0.5f;
struct nk_allocator al;
struct nka_context *a;
al.userdata.ptr = NULL;
al.alloc = anim_alloc;
al.free = anim_free;
a = nka_create(&al);
/* A value starts where it is first asked to be, so it must be kept. */
if (a) nka_set_lazy_init(a, 0);
return a;
}
static float
bounce_out(float t)
void
reaktor_anim_destroy(struct nka_context *a)
{
const float n = 7.5625f, d = 2.75f;
if (g_anim == a) g_anim = NULL;
nka_destroy(a);
}
if (t < 1.0f / d) return n * t * t;
if (t < 2.0f / d) { t -= 1.5f / d; return n * t * t + 0.75f; }
if (t < 2.5f / d) { t -= 2.25f / d; return n * t * t + 0.9375f; }
t -= 2.625f / d;
return n * t * t + 0.984375f;
void
reaktor_anim_frame(struct nka_context *a, float dt_ms)
{
g_anim = a;
if (dt_ms < 0.0f) dt_ms = 0.0f;
if (dt_ms > 64.0f) dt_ms = 64.0f;
nka_update(a, dt_ms / 1000.0f);
}
int
reaktor_anim_settle(void)
{
if (!g_anim) return 0;
nka_gc(g_anim, 600);
return nka_busy(g_anim);
}
float
reaktor_ease_at(unsigned char curve, float t)
{
const float c1 = 1.70158f;
const float c2 = c1 * 1.525f;
const float c3 = c1 + 1.0f;
const float e1 = 2.0f * PI_F / 3.0f;
const float e2 = 2.0f * PI_F / 4.5f;
if (t <= 0.0f) return 0.0f;
if (t >= 1.0f) return 1.0f;
switch (curve) {
case REAKTOR_EASE_LINEAR: return t;
case REAKTOR_EASE_QUAD_IN: return pow_in(t, 2);
case REAKTOR_EASE_QUAD_OUT: return pow_out(t, 2);
case REAKTOR_EASE_QUAD_IN_OUT: return pow_in_out(t, 2);
case REAKTOR_EASE_CUBIC_IN: return pow_in(t, 3);
case REAKTOR_EASE_CUBIC_OUT: return pow_out(t, 3);
case REAKTOR_EASE_CUBIC_IN_OUT: return pow_in_out(t, 3);
case REAKTOR_EASE_QUART_IN: return pow_in(t, 4);
case REAKTOR_EASE_QUART_OUT: return pow_out(t, 4);
case REAKTOR_EASE_QUART_IN_OUT: return pow_in_out(t, 4);
case REAKTOR_EASE_QUINT_IN: return pow_in(t, 5);
case REAKTOR_EASE_QUINT_OUT: return pow_out(t, 5);
case REAKTOR_EASE_QUINT_IN_OUT: return pow_in_out(t, 5);
case REAKTOR_EASE_SINE_IN: return 1.0f - cosf(t * PI_F * 0.5f);
case REAKTOR_EASE_SINE_OUT: return sinf(t * PI_F * 0.5f);
case REAKTOR_EASE_SINE_IN_OUT: return -(cosf(PI_F * t) - 1.0f) * 0.5f;
case REAKTOR_EASE_EXPO_IN: return powf(2.0f, 10.0f * t - 10.0f);
case REAKTOR_EASE_EXPO_OUT: return 1.0f - powf(2.0f, -10.0f * t);
case REAKTOR_EASE_EXPO_IN_OUT:
return t < 0.5f ? powf(2.0f, 20.0f * t - 10.0f) * 0.5f
: (2.0f - powf(2.0f, -20.0f * t + 10.0f)) * 0.5f;
case REAKTOR_EASE_CIRC_IN: return 1.0f - sqrtf(1.0f - t * t);
case REAKTOR_EASE_CIRC_OUT: return sqrtf(1.0f - (t - 1.0f) * (t - 1.0f));
case REAKTOR_EASE_CIRC_IN_OUT:
return t < 0.5f
? (1.0f - sqrtf(1.0f - 4.0f * t * t)) * 0.5f
: (sqrtf(1.0f - (-2.0f * t + 2.0f) * (-2.0f * t + 2.0f))
+ 1.0f) * 0.5f;
case REAKTOR_EASE_BACK_IN: return c3 * t * t * t - c1 * t * t;
case REAKTOR_EASE_BACK_OUT: {
float u = t - 1.0f;
return 1.0f + c3 * u * u * u + c1 * u * u;
}
case REAKTOR_EASE_BACK_IN_OUT:
return t < 0.5f
? (4.0f * t * t * ((c2 + 1.0f) * 2.0f * t - c2)) * 0.5f
: ((2.0f * t - 2.0f) * (2.0f * t - 2.0f)
* ((c2 + 1.0f) * (2.0f * t - 2.0f) + c2) + 2.0f) * 0.5f;
case REAKTOR_EASE_ELASTIC_IN:
return -powf(2.0f, 10.0f * t - 10.0f)
* sinf((t * 10.0f - 10.75f) * e1);
case REAKTOR_EASE_ELASTIC_OUT:
return powf(2.0f, -10.0f * t) * sinf((t * 10.0f - 0.75f) * e1) + 1.0f;
case REAKTOR_EASE_ELASTIC_IN_OUT:
return t < 0.5f
? -(powf(2.0f, 20.0f * t - 10.0f)
* sinf((20.0f * t - 11.125f) * e2)) * 0.5f
: (powf(2.0f, -20.0f * t + 10.0f)
* sinf((20.0f * t - 11.125f) * e2)) * 0.5f + 1.0f;
case REAKTOR_EASE_BOUNCE_IN: return 1.0f - bounce_out(1.0f - t);
case REAKTOR_EASE_BOUNCE_OUT: return bounce_out(t);
case REAKTOR_EASE_BOUNCE_IN_OUT:
return t < 0.5f ? (1.0f - bounce_out(1.0f - 2.0f * t)) * 0.5f
: (1.0f + bounce_out(2.0f * t - 1.0f)) * 0.5f;
default: return t;
}
return nka_eval_preset(curve, t);
}
const char *
@@ -156,150 +89,17 @@ reaktor_ease_name(unsigned char curve)
return curve < REAKTOR_EASE_COUNT ? n[curve] : "?";
}
void
reaktor_anim_scope(const void *owner)
float
reaktor_animate(unsigned id, unsigned channel, float to, float ms,
unsigned char curve)
{
g_scope = owner;
}
static unsigned
key_of(unsigned id, unsigned channel)
{
unsigned k = id * 2654435761u + channel * 0x9e3779b9u +
(unsigned)(size_t)g_scope * 0x85ebca6bu;
k ^= k >> 15;
return k ? k : 1u;
}
static reaktor_anim_slot *
slot_of(unsigned key, const void *owner, int make)
{
unsigned i = key & (REAKTOR_ANIM_SLOTS - 1);
unsigned n;
for (n = 0; n < REAKTOR_ANIM_SLOTS; n++) {
reaktor_anim_slot *s = &g_slot[i];
if (s->key == key && s->owner == owner) return s;
if (!s->key) {
if (!make) return NULL;
s->key = key;
s->owner = owner;
return s;
}
i = (i + 1) & (REAKTOR_ANIM_SLOTS - 1);
}
return NULL;
}
static void
compact(void)
{
reaktor_anim_slot old[REAKTOR_ANIM_SLOTS];
int i;
SDL_memcpy(old, g_slot, sizeof(old));
SDL_memset(g_slot, 0, sizeof(g_slot));
for (i = 0; i < REAKTOR_ANIM_SLOTS; i++) {
reaktor_anim_slot *s;
if (!old[i].key || old[i].dead) continue;
s = slot_of(old[i].key, old[i].owner, 1);
if (s) *s = old[i];
}
if (ms <= 0.0f || !g_anim) return to;
return nka_tween_float(g_anim, id, channel, to, ms / 1000.0f,
nka_ease(curve), NKA_POLICY_CROSSFADE, to);
}
float
reaktor_anim_progress(unsigned id, unsigned channel)
{
reaktor_anim_slot *s = slot_of(key_of(id, channel), g_scope, 0);
if (!s || !s->moving || s->duration <= 0.0f) return -1.0f;
return s->elapsed / s->duration;
}
float
reaktor_animate(unsigned id, unsigned channel, float to, float ms,
unsigned char curve)
{
reaktor_anim_slot *s;
unsigned key;
if (ms <= 0.0f) return to;
key = key_of(id, channel);
s = slot_of(key, g_scope, 1);
if (!s) return to;
s->seen = 1;
if (!s->started) {
s->started = 1;
s->from = s->to = s->value = to;
s->curve = curve;
return to;
}
if (to != s->to) {
s->from = s->value;
s->to = to;
s->elapsed = 0.0f;
s->duration = ms;
s->curve = curve;
s->moving = 1;
}
return s->value;
}
int
reaktor_anim_tick(float dt_ms)
{
int i, moving = 0;
if (dt_ms < 0.0f) dt_ms = 0.0f;
if (dt_ms > 64.0f) dt_ms = 64.0f;
for (i = 0; i < REAKTOR_ANIM_SLOTS; i++) {
reaktor_anim_slot *s = &g_slot[i];
if (!s->key || !s->moving || s->owner != g_scope) continue;
s->elapsed += dt_ms;
if (s->elapsed >= s->duration) {
s->elapsed = s->duration;
s->value = s->to;
s->moving = 0;
} else {
float t = s->elapsed / s->duration;
s->value = s->from
+ (s->to - s->from) * reaktor_ease_at(s->curve, t);
}
/* The landing step needs a frame too. */
moving++;
}
return moving;
}
void
reaktor_anim_evict(const reaktor_a11y_change *c, int n)
{
int i, removed = 0;
for (i = 0; c && i < n; i++) {
unsigned ch;
if (c[i].kind != REAKTOR_A11Y_REMOVED) continue;
for (ch = 0; ch < 16u; ch++) {
reaktor_anim_slot *s = slot_of(key_of(c[i].id, ch), g_scope, 0);
if (s && !s->dead) { s->dead = 1; removed++; }
}
}
for (i = 0; i < REAKTOR_ANIM_SLOTS; i++) {
reaktor_anim_slot *s = &g_slot[i];
if (!s->key || s->dead || s->owner != g_scope) continue;
if (!s->seen) { s->dead = 1; removed++; continue; }
s->seen = 0;
}
if (removed) compact();
return g_anim ? nka_tween_progress(g_anim, id, channel) : -1.0f;
}
+6 -4
View File
@@ -1,13 +1,15 @@
#ifndef REAKTOR_ANIM_H
#define REAKTOR_ANIM_H
#include "a11y.h"
#include "reaktor/anim.h"
void reaktor_anim_scope(const void *owner);
struct nka_context *reaktor_anim_create(void);
void reaktor_anim_destroy(struct nka_context *a);
int reaktor_anim_tick(float dt_ms);
/* Before the page: makes a the context reaktor_animate uses and moves its time on. */
void reaktor_anim_frame(struct nka_context *a, float dt_ms);
void reaktor_anim_evict(const reaktor_a11y_change *changes, int n);
/* After the page: nonzero while something it drew is still moving. */
int reaktor_anim_settle(void);
#endif
+11 -1
View File
@@ -27,6 +27,7 @@ typedef struct locale_catalog {
static locale_catalog g_cat[LOCALE_MAX];
static int g_count;
static int g_current = -1;
static int g_system;
static int
by_code(const void *a, const void *b)
@@ -157,6 +158,7 @@ release(void)
}
g_count = 0;
g_current = -1;
g_system = 0;
}
#ifdef REAKTOR_LOCALE_EMBEDDED
@@ -245,13 +247,21 @@ reaktor_locale_name(int index)
int
reaktor_locale_set(const char *code)
{
int i = reaktor_locale_find(code);
int follow = !code;
int i = reaktor_locale_find(follow ? reaktor_locale_system_code() : code);
if (i < 0) return 0;
g_current = i;
g_system = follow;
return 1;
}
int
reaktor_locale_system(void)
{
return g_system;
}
const char *
reaktor_locale_current(void)
{
+1
View File
@@ -5,6 +5,7 @@
int reaktor_locale_init(void);
int reaktor_locale_find(const char *code);
const char *reaktor_locale_system_code(void);
int reaktor_locale_codepoints(unsigned *out, int cap);
long reaktor_plural_eval(const char *expr, unsigned long n);
+1
View File
@@ -8,6 +8,7 @@ int reaktor_locale_count(void) { return 0; }
const char *reaktor_locale_code(int i) { (void)i; return NULL; }
const char *reaktor_locale_name(int i) { (void)i; return NULL; }
int reaktor_locale_set(const char *c) { (void)c; return 0; }
int reaktor_locale_system(void) { return 0; }
const char *reaktor_locale_current(void) { return ""; }
const char *reaktor_tr(const char *key) { return key; }
+13 -7
View File
@@ -6,20 +6,26 @@
void
reaktor_locale_start(const char *lang)
{
SDL_Locale **pref;
int i, n = 0;
if (reaktor_locale_init() <= 0) return;
if (lang) {
if (reaktor_locale_set(lang)) return;
SDL_Log("no catalog for --lang %s", lang);
}
reaktor_locale_set(NULL);
}
const char *
reaktor_locale_system_code(void)
{
SDL_Locale **pref;
int i, at = -1, n = 0;
pref = SDL_GetPreferredLocales(&n);
for (i = 0; pref && i < n; i++)
if (pref[i] && reaktor_locale_set(pref[i]->language)) break;
for (i = 0; pref && i < n && at < 0; i++)
if (pref[i]) at = reaktor_locale_find(pref[i]->language);
SDL_free(pref);
if (!reaktor_locale_current()[0] && !reaktor_locale_set("en"))
reaktor_locale_set(reaktor_locale_code(0));
if (at < 0) at = reaktor_locale_find("en");
return reaktor_locale_code(at < 0 ? 0 : at);
}
unsigned *
+40 -3
View File
@@ -335,6 +335,40 @@ box_from_style(reaktor_box *box, const char *text, const char *selector,
}
}
static void
fit_button(reaktor_box *box, const reaktor_button_spec *s)
{
const struct nk_style_button *nb = &g_ctx->style.button;
const char *sel = rule_or(s->style, "button");
const struct nk_user_font *f = style_font(sel);
reaktor_style st;
float pad_x, pad_y, border, edge, text = 0.0f, w;
box->w = box->h = 0.0f;
box->flags &= ~(REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y);
box_from_style(box, NULL, s->style, "button", nb->padding.x, nb->padding.y);
reaktor_style_get(sel, &st);
pad_x = st.matched ? st.pad_x : nb->padding.x;
pad_y = st.matched ? st.pad_y : nb->padding.y;
border = st.matched ? st.border : nb->border;
edge = border + (st.matched ? st.rounding : nb->rounding);
if (s->label)
text = f->width(f->userdata, f->height, s->label, (int)strlen(s->label));
w = text + 2.0f * (pad_x + (st.matched ? border : edge));
if (s->icon && s->label) {
float room = SDL_max(box->h * 0.5f - edge, 0.0f);
float icon = box->h - 2.0f * SDL_min(pad_y, room)
- 2.0f * nb->image_padding.x;
w = SDL_max(w, text + 2.0f * (3.0f * pad_x + nb->image_padding.x + icon));
} else if (s->icon) {
w = box->h;
}
box->w = SDL_ceilf(w);
}
void
reaktor_gap(float w, float h)
{
@@ -367,9 +401,12 @@ reaktor_button(const reaktor_button_spec *s)
if (!g_app || !s) return 0;
box = s->box;
box_from_style(&box, s->label, s->style, "button",
g_ctx->style.button.padding.x,
g_ctx->style.button.padding.y);
if (s->fit_content)
fit_button(&box, s);
else
box_from_style(&box, s->label, s->style, "button",
g_ctx->style.button.padding.x,
g_ctx->style.button.padding.y);
if (!place(REAKTOR_A11Y_BUTTON, s->name ? s->name : s->label, NULL,
s->disabled ? REAKTOR_A11Y_DISABLED : 0u, s->keys, &box, &id))
+34 -6
View File
@@ -185,8 +185,9 @@ push_button_look(App *app, struct nk_context *ctx, const reaktor_button_look *k)
if (s.pad_y > room) s.pad_y = room;
}
/* Nuklear insets a label by the rounding as well; CSS does not. */
nk_style_push_vec2(ctx, &ctx->style.button.padding,
nk_vec2(s.pad_x, s.pad_y));
nk_vec2(s.pad_x - s.rounding - 0.5f, s.pad_y));
f.vec2s = 1;
if (s.font_px > 0) {
@@ -359,20 +360,47 @@ css_button_accent(App *app, struct nk_context *ctx, const char *selector,
return clicked;
}
/* Where Nuklear put an icon, left of a label centered across the button. */
static int
icon_place(struct nk_context *ctx, struct nk_rect b, float pad_x,
const char *label, struct nk_rect *at)
{
const struct nk_style_button *s = &ctx->style.button;
const struct nk_user_font *f = ctx->style.font;
float text = f->width(f->userdata, f->height, label, (int)SDL_strlen(label));
at->x = b.x + 2.0f * pad_x + s->image_padding.x;
at->y = b.y + s->padding.y + s->image_padding.y;
at->w = b.h - 2.0f * s->padding.y - 2.0f * s->image_padding.x;
at->h = b.h - 2.0f * s->padding.y - 2.0f * s->image_padding.y;
return b.w >= text + 2.0f * (3.0f * pad_x + s->image_padding.x + at->w);
}
int
css_button_icon(App *app, struct nk_context *ctx, const char *selector,
const char *icon_src, const char *label)
{
reaktor_button_look k;
style_frame f;
struct nk_image im = icon(app, icon_src, 18);
int clicked;
struct nk_rect b = nk_widget_bounds(ctx), at;
int clicked, drawn;
hot_push(app, nk_widget_bounds(ctx), 1, 1);
hot_push(app, b, 1, 1);
reaktor_note_here(app, ctx, REAKTOR_A11Y_BUTTON, label, 0);
f = push_button_style(app, ctx, selector);
reaktor_button_look_of(selector, &k);
f = push_button_look(app, ctx, &k);
drawn = icon_place(ctx, b, k.s.matched ? k.s.pad_x : ctx->style.button.padding.x,
label, &at);
reaktor_button_arm(ctx);
clicked = nk_button_image_label(ctx, im, label, NK_TEXT_CENTERED);
clicked = nk_button_label(ctx, label);
reaktor_chrome_disarm();
if (drawn) {
struct nk_image im = icon(app, icon_src, 18);
nk_draw_image(nk_window_get_canvas(ctx), at, &im,
nk_rgb_factor(nk_rgb(255, 255, 255),
ctx->style.button.color_factor_background));
}
pop_style(ctx, f);
return clicked;
}
+5 -2
View File
@@ -40,8 +40,11 @@ what the library draws, and where its claims are tested rather than asserted:
and can have the showcase ask before it closes.
- **Diagnostics** shows the renderer, and where each frame's milliseconds and
each megabyte went, live.
- **Animation** draws all 31 easing curves through the function the widgets
animate with.
- **Animation** sends five blocks to one stop, one of them instantly, draws
all 31 easing curves through the function the widgets animate with, and
plays the rest of NukAnim: a clip staggered across a grid under its debug
timeline, motion along paths, oscillators, noise and a shake, one blend in
five color spaces, and text arriving a glyph at a time.
## Notepad
+51 -17
View File
@@ -68,7 +68,9 @@ errors, so an internal function cannot slip back in.
| `reaktor_file_open(app)` | Show the platform's file picker; the answer goes to `file_opened` |
| `reaktor_user(app)` | The launch's `.user` |
| `reaktor_sdl_window(app)`, `reaktor_sdl_renderer(app)` | That App's SDL window and renderer |
| `reaktor_icon_surface(name, px)` | An SVG asset as an `SDL_Surface`, for a tray or icon of the app's own |
| `reaktor_dark(app)`, `reaktor_get_theme(app)` | Whether it draws dark; the scheme chosen |
| `reaktor_lang_pref(app)` | The language `--lang` asked for, or `NULL` |
| `reaktor_set_borderless(app, on)`, `reaktor_borderless(app)` | Switch the main window's frame off for a titlebar of your own, drawn with `.window.hit_test` |
The `set` calls are for the main thread, take effect at the next frame, and do
@@ -117,7 +119,7 @@ again), `.style` (a selector to read instead of the widget's own) and `.box`
| Widget | Call | Answers 1 | Its own fields |
| --- | --- | --- | --- |
| Button | `reaktor_button` | when pressed | `.label`, `.icon`, `.accent`, `.disabled`, `.repeat` (fires while held), `.keys`, `.on_press` |
| Button | `reaktor_button` | when pressed | `.label`, `.icon`, `.accent`, `.disabled`, `.repeat` (fires while held), `.keys`, `.on_press`, `.fit_content` (exactly as large as its label and icon, whatever `.box` asks) |
| Link | `reaktor_link` | when pressed | `.text`, `.active`, `.on_press` |
| Label | `reaktor_label` | — | `.text`, `.wrap`, `.align` (`REAKTOR_LEFT`, `_CENTRE`, `_RIGHT`), `.color` (a token), `.value`, `.silent` (left out of the tree) |
| Icon | `reaktor_icon` | — | `.name` (an Ionicon), `.accent` |
@@ -135,6 +137,9 @@ again), `.style` (a selector to read instead of the widget's own) and `.box`
| Sidebar | `reaktor_sidebar` | when an entry is chosen | [below](#sidebar-and-tabs) |
| Tabs | `reaktor_tabs` | when an entry is chosen | [below](#sidebar-and-tabs) |
**An icon gives way to its label**: a button too narrow for both draws the
label alone. `.fit_content` makes it as large as both need.
**A field writes back** its bytes into `.buf` and its length into `*.len`, and
reads both next frame, so the length must be the field's own: one from
anywhere else reseeds the buffer. Ctrl+Z and Ctrl+R undo and redo from a
@@ -417,7 +422,8 @@ The tree is still built, because layout and animation key on its ids.
## Animation
A number that takes time to change, keyed by a box's id.
[NukAnim](https://github.com/Alpaq92/NukAnim), in `external/nukanim`, runs it.
The simplest of it is a number that takes time to change, keyed by a box's id.
```c
REAKTOR_COLUMN(.name = "Track", .h = 56.0f) {
@@ -432,8 +438,26 @@ The first call starts at its target: nothing has changed yet. A new target
starts a run from wherever the value is, so a change mid-flight redirects
rather than restarts. `channel`, the second argument, tells several numbers on
one box apart, and each window keeps its own. There are 31 curves, and `reaktor_ease_at(curve, t)` draws
them. An entry dies with its node, and a page with nothing moving asks for no
frames.
them; `reaktor_anim_progress` says how far a run has got.
The rest of `nukanim.h` works on the window's context, `reaktor_anim(app)`:
springs, steps and béziers, colors blended in OKLAB, clips and timelines,
motion paths, oscillators and noise, and ImAnimate's way of animating a value
that keeps its own state:
```c
if (hovered) nka_animate(reaktor_anim(app), 1.0f, 1.1f, 150.0f, &size, NKA_EASE_OUT_CUBIC);
else nka_animate(reaktor_anim(app), 1.1f, 1.0f, 250.0f, &size, NKA_EASE_OUT_CUBIC);
```
The runtime moves the context's time before each page and draws another frame
while anything the page sampled is still moving, so a page with nothing moving
asks for no frames. What is not sampled for 600 frames is forgotten. Something
that changes under the pointer needs a hot rectangle, `reaktor_hot`, for the
pointer's motion to run a frame. NukAnim's debug timeline,
`nka_show_debug_timeline`, lays out a row of its own, so it goes between
declared blocks rather than inside one, and its tooltips follow the pointer
only across a `reaktor_hot_follow` rectangle.
## Beyond the specs
@@ -447,11 +471,11 @@ declared page. [`include/reaktor/ui.h`](../include/reaktor/ui.h) has the pieces
| --- | --- |
| `reaktor_token`, `reaktor_col`, `reaktor_on`, `reaktor_visible` | Colors from the sheet; readable text on a background |
| `reaktor_font`, `reaktor_style_font` | A baked face, by size or by selector |
| `reaktor_ionicon` | An Ionicon as an `nk_image` |
| `reaktor_ionicon`, `reaktor_ionicon_exact`, `reaktor_glyph_at` | An Ionicon as an `nk_image`, in any color, or drawn into a rectangle |
| `reaktor_svg`, `REAKTOR_MARK` | Any SVG asset, recolored by `?stroke=#rrggbb&fill=&sw=`; the mark's name |
| `reaktor_fill_round`, `reaktor_edge_round` | Rounded fills and borders, smooth on the software renderer |
| `reaktor_hot`, `reaktor_hot_top`, `reaktor_hot_follow` | A rectangle that redraws on hover ([the frame loop](#the-frame-loop)) |
| `reaktor_button_label`, `reaktor_button_accent`, `reaktor_slider_bar`, `reaktor_progress_bar`, `reaktor_chevron_at` | Styled controls inside `nk_` layouts |
| `reaktor_button_label`, `reaktor_button_icon`, `reaktor_button_accent`, `reaktor_field_text`, `reaktor_slider_bar`, `reaktor_progress_bar`, `reaktor_chevron_at` | Styled controls inside `nk_` layouts |
| `reaktor_menu_item`, `reaktor_menu_style_push`, `_pop`, `reaktor_menu_height`, `reaktor_menu_edge`, `reaktor_popup_rounding` | Menus and popups |
| `reaktor_note`, `_push`, `_pop`, `_here`, `_keys`, `_value`, `_bounds`, `reaktor_focus_activated` | The accessibility tree, and keyboard presses |
| `reaktor_focus_area`, `reaktor_focus_scroll` | A scrolling page body: the area and node focus moves within, and the rectangle it asks to see |
@@ -492,7 +516,7 @@ core/css cssflat and the libcss front end
core/render Nuklear, the SDL3 backend, drawing, SVG icons
core/ui specs, layout, widgets, the style map, keys, focus, floaters, toasts
core/a11y the shadow tree and its diff
core/anim eased values
core/anim NukAnim, a context a window
core/locale the Locale module
core/text the Text module
platform/ theme, process lifecycle, the accessibility bridges, the web keyboard
@@ -500,7 +524,7 @@ runtime/ the main window and its loop, other windows, the tray
samples/ showcase, notepad, simple, bench
tools/ the tests, the icon compiler, vmwalk
benchmarks/ bench in four other frameworks, and the sampler
external/ ten submodules, read as they ship
external/ eleven submodules, read as they ship
```
`runtime/` and `core/` build `reaktor_runtime`, a static library every
@@ -535,6 +559,13 @@ While a mouse button is held, frames follow the display's refresh, with two
more after the release. A turn of the wheel takes two frames, because Nuklear
scrolls a panel after drawing it.
A finger that moves mostly up or down, by more than 8 pixels, scrolls the
panel under it: the runtime releases what the finger pressed away from every
widget, so nothing is clicked, and turns its movement into wheel steps sized
to the page body `reaktor_focus_area` names, or to the window. A fast swipe
coasts on after the finger lifts, and a touch stops it. Sideways drags, and
drags that start in a text field, stay drags.
Nuklear reads input as it stands at a frame's end: a button pressed and
released within one frame was never down. So a frame takes one change — a
button or a key — or a run of text, and faster input is spread over the frames
@@ -608,13 +639,13 @@ cmake --install build --prefix libreaktor --component libreaktor
```
It is one static library — `reaktor.lib` with MSVC, `libreaktor.a` elsewhere
— holding Reaktor, every module, SDL, libcss, plutosvg, Onlay, mojibake and
kb_text_shape, merged with `lib.exe`, Apple's `libtool` or an `ar` MRI
script. Beside it go the public headers with Nuklear's and SDL's, a CMake
package, a pkg-config file and `share/reaktor/licenses`:
— holding Reaktor, every module, SDL, libcss, plutosvg, Onlay, NukAnim,
mojibake and kb_text_shape, merged with `lib.exe`, Apple's `libtool` or an
`ar` MRI script. Beside it go the public headers with Nuklear's, NukAnim's
and SDL's, a CMake package, a pkg-config file and `share/reaktor/licenses`:
```cmake
find_package(reaktor 0.2 REQUIRED)
find_package(reaktor 0.3 REQUIRED)
add_executable(app WIN32 main.c)
target_link_libraries(app PRIVATE reaktor::reaktor)
```
@@ -734,7 +765,7 @@ Built by default and run from `build/`:
| `laytest` | The layout engine's placement |
| `onlaytest` | Onlay's own suite, unmodified |
| `a11ytest` | Node identity, the diff, the pool |
| `animtest` | Curves, retargeting, eviction |
| `animtest` | Curves, retargeting, a context a window |
| `keytest` | Chord parsing and formatting |
| `localetest` | Catalogs, lookup, plural rules, formatting |
| `texttest` | Line breaks, direction, measuring and glyph order, against `assets/fonts`; with the Text module |
@@ -851,9 +882,12 @@ how its language writes numbers the way it says "Save" — Polish puts
no-break spaces between digit groups and before its symbol — and a symbol of
letters is always kept a space off the amount: `PLN 12.00`.
**The language** is `--lang` when a catalog has it, else the first of the
system's preferred languages that one has, else English, else the first
catalog. `reaktor_locale_set` switches at any time.
**The language** is `--lang` when a catalog has it, else the system's: the
first of its preferred languages that a catalog has, else English, else the
first catalog, and it changes when the system's does.
`reaktor_locale_set(code)` switches at any time and stops following the
system; `reaktor_locale_set(NULL)` follows it again, and
`reaktor_locale_system()` says whether it does.
**Leave `.name` to the translated text**, so a screen reader reads what is
drawn; the cost is that a switch makes each translated widget new, placed a
+8 -5
View File
@@ -9,6 +9,7 @@ from the project's own license file at the pinned revision.
| --- | --- | --- |
| [SDL](https://github.com/libsdl-org/SDL) | Window, input, renderer, system theme, file dialog, tray | zlib |
| [Nuklear](https://github.com/Immediate-Mode-UI/Nuklear) | Widgets, font baking, the SDL3 backend, and the stb_truetype the Text module rasterizes with | MIT **or** public domain |
| [NukAnim](https://github.com/Alpaq92/NukAnim) | Every animation, and `nukanim.h` for applications — a port of [ImAnim](https://github.com/soufianekhiat/ImAnim) with [ImAnimate](https://github.com/RaidcoreGG/ImAnimate)'s `animate` | MIT |
| [LCUI](https://github.com/lc-soft/LCUI) | `libcss` (parse, match, cascade) and `yutil` | MIT |
| [Onlay](https://github.com/Alpaq92/Onlay) | The rectangles — a fork of [randrew/layout](https://github.com/randrew/layout) | MIT |
| [tiny.css](https://github.com/ihsan6133/tiny.css) | The stylesheet the look comes from, compiled in | MIT |
@@ -24,7 +25,9 @@ static, without audio, joystick, haptic, HID, sensor, camera, power, GPU,
offscreen or the render backends Reaktor never selects. Its tray is built: on
Linux and the BSDs it loads AppIndicator and GTK 3 when a tray opens, and
nothing links them. mojibake is built without its collation, IDNA, security
and character-name tables. kb_text_shape is one header, compiled in
and character-name tables. NukAnim is one header, compiled in
`core/anim/anim.c`; its own Nuklear submodule, which only its tests use, comes
with a recursive checkout and is not built. kb_text_shape is one header, compiled in
`core/text/kb.c`; it shapes, and the Text module rasterizes with Nuklear's
stb_truetype.
@@ -120,10 +123,10 @@ each toolchain fetches its own framework, and none is part of a Reaktor build.
## What is redistributed
A native build links SDL, libcss, yutil, plutosvg and plutovg statically, plus
mojibake and kb_text_shape with the Text module, and compiles in Nuklear and
Onlay, so it carries the zlib and MIT terms above. Each license is copied
unchanged into `licenses/` beside the programs: ship that folder, and this
file, with a binary.
mojibake and kb_text_shape with the Text module, and compiles in Nuklear,
NukAnim and Onlay, so it carries the zlib and MIT terms above. Each license
is copied unchanged into `licenses/` beside the programs: ship that folder,
and this file, with a binary.
The binary also carries the default assets in `REAKTOR_BUILTINS`, byte for
byte: tiny.css's `core.css`, `variables-light.css` and `variables-dark.css`
+1 -1
View File
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.16)
project(consumer C)
find_package(reaktor 0.2 REQUIRED)
find_package(reaktor 0.3 REQUIRED)
add_executable(simple WIN32 ../../samples/simple/simple.c)
target_link_libraries(simple PRIVATE reaktor::reaktor)
Vendored Submodule
+1
Submodule external/nukanim added at 9e4eaf6a12
+11
View File
@@ -1,6 +1,14 @@
#ifndef REAKTOR_ANIM_PUBLIC_H
#define REAKTOR_ANIM_PUBLIC_H
#include "reaktor/nuklear.h"
#include <nukanim.h>
#ifndef REAKTOR_APP_FWD
#define REAKTOR_APP_FWD
typedef struct App App;
#endif
enum {
REAKTOR_EASE_LINEAR = 0,
@@ -30,4 +38,7 @@ float reaktor_animate(unsigned id, unsigned channel, float to,
float reaktor_anim_progress(unsigned id, unsigned channel);
/* The window's NukAnim context, for all of nukanim.h; its time moves every frame. */
struct nka_context *reaktor_anim(App *app);
#endif
+5
View File
@@ -123,8 +123,13 @@ void *reaktor_user(App *app);
SDL_Window *reaktor_sdl_window(App *app);
SDL_Renderer *reaktor_sdl_renderer(App *app);
/* An SVG asset at px, for a tray or window icon of one's own; the caller
* destroys it. NULL when the asset cannot be read. */
SDL_Surface *reaktor_icon_surface(const char *name, int px);
int reaktor_dark(App *app);
reaktor_theme reaktor_get_theme(App *app);
/* --lang's value, or NULL; the language in use is reaktor_locale_current(). */
const char *reaktor_lang_pref(App *app);
/* The main window's. */
void reaktor_set_borderless(App *app, int on);
int reaktor_borderless(App *app);
+2
View File
@@ -7,7 +7,9 @@ void reaktor_locale_start(const char *lang);
int reaktor_locale_count(void);
const char *reaktor_locale_code(int index);
const char *reaktor_locale_name(int index);
/* NULL follows the system's language, and keeps following it. */
int reaktor_locale_set(const char *code);
int reaktor_locale_system(void);
const char *reaktor_locale_current(void);
const char *reaktor_tr(const char *key);
+13
View File
@@ -29,6 +29,12 @@ struct nk_color reaktor_visible(struct nk_color want,
const struct nk_user_font *reaktor_font(App *app, int px, int bold);
struct nk_image reaktor_ionicon(App *app, const char *name, int px);
/* In stroke's color; sw is the stroke width, 0 for the default at px. */
struct nk_image reaktor_ionicon_exact(App *app, const char *name, int px,
struct nk_color stroke, float sw);
/* That Ionicon drawn centered in slot on the current window's canvas. */
void reaktor_glyph_at(App *app, struct nk_context *ctx, struct nk_rect slot,
const char *name, struct nk_color col, int px, float sw);
#define REAKTOR_MARK "assets/icons/reaktor-icon.svg"
/* An SVG by asset name; ?stroke=#rrggbb, &fill=, &sw= recolor it. */
@@ -46,6 +52,13 @@ void reaktor_hot_top(App *app, struct nk_rect r, int cursor, int repaint);
void reaktor_hot_follow(App *app, struct nk_rect r, int cursor);
int reaktor_button_label(App *app, struct nk_context *ctx, const char *label);
int reaktor_button_icon(App *app, struct nk_context *ctx,
const char *ionicon, const char *label);
/* A styled single-line field over buf, which holds *len bytes of cap; hint
* shows while it is empty, and pad_x, pad_y above 0 replace the padding. */
nk_flags reaktor_field_text(App *app, struct nk_context *ctx, nk_flags flags,
char *buf, int *len, int cap, const char *hint,
nk_plugin_filter filter, float pad_x, float pad_y);
void reaktor_slider_bar(App *app, struct nk_context *ctx, unsigned id,
float *val, float lo, float hi, float step);
+1
View File
@@ -72,6 +72,7 @@ typedef struct reaktor_button_spec {
unsigned char accent;
unsigned char disabled;
unsigned char repeat;
unsigned char fit_content;
} reaktor_button_spec;
int reaktor_button(const reaktor_button_spec *s);
+221 -10
View File
@@ -944,6 +944,7 @@ take_event(App *app, SDL_Event *event)
case SDL_EVENT_WINDOW_FOCUS_LOST:
case SDL_EVENT_WINDOW_MOUSE_LEAVE:
case SDL_EVENT_SYSTEM_THEME_CHANGED:
case SDL_EVENT_LOCALE_CHANGED:
case SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED:
app->dirty = 1;
break;
@@ -1002,6 +1003,11 @@ take_event(App *app, SDL_Event *event)
if (app->theme_mode == REAKTOR_THEME_SYSTEM) load_theme(app);
break;
case SDL_EVENT_LOCALE_CHANGED:
if (!app->secondary && reaktor_locale_system() && reaktor_locale_set(NULL))
reaktor_windows_dirty();
break;
case SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED:
if (app->secondary) break;
reaktor_set_scale(reaktor_dpi_query_scale(app->win));
@@ -1139,6 +1145,198 @@ bare_quit(App *app)
#endif
}
static void
feed(App *app, SDL_Event *event)
{
if (hold_for_next_frame(app, event)) app->dirty = 1;
else take_event(app, event);
}
enum { TOUCH_NONE, TOUCH_PRESSED, TOUCH_CAUGHT, TOUCH_DRAGGING, TOUCH_SCROLLING };
#define TOUCH_SLOP 8.0f
#define FLING_TAU_MS 325.0f
#define FLING_MIN 60.0f
#define FLING_STOP 20.0f
static void
touch_pointer(App *app, float x, float y, int release)
{
SDL_Event e;
SDL_zero(e);
e.type = SDL_EVENT_MOUSE_MOTION;
e.motion.windowID = SDL_GetWindowID(app->win);
e.motion.which = SDL_TOUCH_MOUSEID;
e.motion.x = x;
e.motion.y = y;
feed(app, &e);
if (!release) return;
SDL_zero(e);
e.type = SDL_EVENT_MOUSE_BUTTON_UP;
e.button.windowID = SDL_GetWindowID(app->win);
e.button.which = SDL_TOUCH_MOUSEID;
e.button.button = SDL_BUTTON_LEFT;
e.button.clicks = 1;
e.button.x = x;
e.button.y = y;
feed(app, &e);
}
static void
touch_wheel(App *app, float dy)
{
SDL_Event e;
if (dy == 0.0f || app->touch_unit <= 0.0f) return;
SDL_zero(e);
e.type = SDL_EVENT_MOUSE_WHEEL;
e.wheel.windowID = SDL_GetWindowID(app->win);
e.wheel.which = SDL_TOUCH_MOUSEID;
e.wheel.y = dy / app->touch_unit;
e.wheel.mouse_x = app->touch_x0;
e.wheel.mouse_y = app->touch_y0;
feed(app, &e);
}
static void
touch_sample(App *app, float y, Uint64 ns)
{
app->touch_ys[app->touch_n % 4] = y;
app->touch_ns[app->touch_n % 4] = ns;
app->touch_n++;
}
/* Nuklear moves a panel a tenth of its height per wheel step. */
static float
touch_unit(const App *app)
{
struct nk_rect b = app->body_rect;
float h = (float)app->laid_h;
if (b.h > 0.0f && app->touch_x0 >= b.x && app->touch_x0 < b.x + b.w &&
app->touch_y0 >= b.y && app->touch_y0 < b.y + b.h)
h = b.h;
return 0.1f * h;
}
static void
fling_start(App *app, Uint64 now)
{
int last = app->touch_n - 1, first = last, i;
Uint64 t;
float v;
if (last < 1 || now - app->touch_ns[last % 4] > 100000000u) return;
for (i = last - 1; i >= 0 && i > last - 4; i--) {
if (app->touch_ns[last % 4] - app->touch_ns[i % 4] > 100000000u) break;
first = i;
}
t = app->touch_ns[last % 4] - app->touch_ns[first % 4];
if (first == last || !t) return;
v = (app->touch_ys[last % 4] - app->touch_ys[first % 4]) / ((float)t / 1e9f);
if (SDL_fabsf(v) < FLING_MIN) return;
app->fling_v = v;
app->fling_ns = now;
app->restore_rate = 0;
hint(SDL_HINT_MAIN_CALLBACK_RATE, app->drag_rate);
app->dirty = 1;
}
static void
fling_step(App *app)
{
Uint64 now = SDL_GetTicksNS();
float dt;
if (app->fling_v == 0.0f) return;
dt = (float)(now - app->fling_ns) / 1e9f;
app->fling_ns = now;
if (app->touch_unit > 0.0f)
nk_input_scroll(app->ctx, nk_vec2(0.0f, app->fling_v * dt / app->touch_unit));
app->fling_v *= SDL_expf(-dt * 1000.0f / FLING_TAU_MS);
if (SDL_fabsf(app->fling_v) < FLING_STOP) {
app->fling_v = 0.0f;
app->restore_rate = 2;
}
}
/* A finger that moves mostly up or down scrolls, and presses nothing. */
static int
touch_takes(App *app, const SDL_Event *e)
{
struct nk_rect r = app->field_rect;
float dx, dy;
int was = app->touch;
switch (e->type) {
case SDL_EVENT_MOUSE_BUTTON_DOWN:
if (e->button.which != SDL_TOUCH_MOUSEID || e->button.button != SDL_BUTTON_LEFT)
return 0;
app->touch_x0 = e->button.x;
app->touch_y0 = e->button.y;
app->touch_n = 0;
touch_sample(app, e->button.y, e->button.timestamp);
app->touch_in_field = app->field_rect_valid &&
e->button.x >= r.x && e->button.x <= r.x + r.w &&
e->button.y >= r.y && e->button.y <= r.y + r.h;
if (app->fling_v != 0.0f) {
app->fling_v = 0.0f;
app->restore_rate = 2;
app->touch = TOUCH_CAUGHT;
return 1;
}
app->touch = TOUCH_PRESSED;
return 0;
case SDL_EVENT_MOUSE_MOTION:
if (e->motion.which != SDL_TOUCH_MOUSEID) return 0;
switch (app->touch) {
case TOUCH_SCROLLING:
touch_wheel(app, e->motion.y - app->touch_last);
app->touch_last = e->motion.y;
touch_sample(app, e->motion.y, e->motion.timestamp);
return 1;
case TOUCH_PRESSED:
case TOUCH_CAUGHT:
dx = e->motion.x - app->touch_x0;
dy = e->motion.y - app->touch_y0;
if (SDL_fabsf(dx) <= TOUCH_SLOP && SDL_fabsf(dy) <= TOUCH_SLOP)
return app->touch == TOUCH_CAUGHT;
if (app->touch_in_field || SDL_fabsf(dy) <= SDL_fabsf(dx)) {
if (app->touch == TOUCH_CAUGHT) return 1;
app->touch = TOUCH_DRAGGING;
return 0;
}
/* Released away from every widget, the press clicks nothing. */
if (app->touch == TOUCH_PRESSED) touch_pointer(app, -1e4f, -1e4f, 1);
touch_pointer(app, app->touch_x0, app->touch_y0, 0);
app->touch = TOUCH_SCROLLING;
app->touch_unit = touch_unit(app);
app->touch_last = app->touch_y0 + (dy > 0.0f ? TOUCH_SLOP : -TOUCH_SLOP);
touch_wheel(app, e->motion.y - app->touch_last);
app->touch_last = e->motion.y;
touch_sample(app, e->motion.y, e->motion.timestamp);
return 1;
default:
return 0;
}
case SDL_EVENT_MOUSE_BUTTON_UP:
if (e->button.which != SDL_TOUCH_MOUSEID || e->button.button != SDL_BUTTON_LEFT)
return 0;
app->touch = TOUCH_NONE;
if (was == TOUCH_SCROLLING) {
fling_start(app, e->button.timestamp);
return 1;
}
return was == TOUCH_CAUGHT;
default:
return 0;
}
}
static SDL_AppResult
app_event(void *appstate, SDL_Event *event)
{
@@ -1163,8 +1361,7 @@ app_event(void *appstate, SDL_Event *event)
}
if (!(to = app)) return SDL_APP_CONTINUE;
}
if (hold_for_next_frame(to, event)) to->dirty = 1;
else take_event(to, event);
if (!touch_takes(to, event)) feed(to, event);
return SDL_APP_CONTINUE;
}
@@ -1214,6 +1411,7 @@ reaktor_app_due(App *app, int w, int h)
SDL_Window *over = SDL_GetMouseFocus();
if (w != app->laid_w || h != app->laid_h) app->dirty = 1;
if (app->fling_v != 0.0f) app->dirty = 1;
if (app->hover_pending &&
SDL_GetTicks() - app->last_draw_ms >= g_hover_gap_ms) {
@@ -1335,13 +1533,15 @@ reaktor_app_frame(App *app, int win_w, int win_h, const char *title,
if (is_main) reaktor_a11y_platform_drain();
else reaktor_a11y_platform_window_drain(app->win);
key_click(app);
fling_step(app);
nk_input_end(ctx);
ctx->style.text.color = app->text;
file_answer(app);
app->focus_seen = 0;
app->popup_lo = app->popup_hi = app->trap_lo = app->trap_hi = -1;
reaktor_anim_scope(app);
if (!app->anim) app->anim = reaktor_anim_create();
if (app->anim) reaktor_anim_frame(app->anim, app->frame_gap_ms);
reaktor_a11y_begin(&app->a11y, title, area);
reaktor_frame_begin(app, ctx, area);
@@ -1400,13 +1600,7 @@ reaktor_app_frame(App *app, int win_w, int win_h, const char *title,
reader_activate, reader_focus, app);
}
{
int n = 0;
const reaktor_a11y_change *c = reaktor_a11y_changes(&app->a11y, &n);
reaktor_anim_evict(c, n);
}
if (reaktor_anim_tick(app->frame_gap_ms) > 0) {
if (app->anim && reaktor_anim_settle()) {
app->dirty = 1;
wake_app(app);
}
@@ -1538,6 +1732,8 @@ app_quit(void *appstate, SDL_AppResult result)
if (app->ctx) nk_sdl_shutdown(app->ctx);
if (app->ren) SDL_DestroyRenderer(app->ren);
if (app->win) SDL_DestroyWindow(app->win);
reaktor_anim_destroy(app->anim);
app->anim = NULL;
/* The picker's thread still writes into it. */
if (!app->file_pending) SDL_free(app);
g_app = NULL;
@@ -1713,6 +1909,13 @@ reaktor_main_app(void)
return g_app;
}
struct nka_context *
reaktor_anim(App *app)
{
if (app && !app->anim) app->anim = reaktor_anim_create();
return app ? app->anim : NULL;
}
const char *
reaktor_launch_icon(void)
{
@@ -1750,6 +1953,14 @@ reaktor_get_theme(App *app)
return app ? (reaktor_theme)app->theme_mode : REAKTOR_THEME_SYSTEM;
}
const char *
reaktor_lang_pref(App *app)
{
App *m = reaktor_main_app();
return app && m ? m->lang_pref : NULL;
}
void
reaktor_set_borderless(App *app, int on)
{
+12
View File
@@ -1,4 +1,5 @@
#include "internal.h"
#include "anim.h"
#include "declare.h"
#include "reaktor/launch.h"
@@ -77,6 +78,8 @@ teardown(App *a)
if (a->ren) SDL_DestroyRenderer(a->ren);
if (a->win) SDL_DestroyWindow(a->win);
SDL_free(a->glyphs);
reaktor_anim_destroy(a->anim);
a->anim = NULL;
a->win = NULL;
a->ren = NULL;
a->ctx = NULL;
@@ -296,6 +299,15 @@ reaktor_windows_restyle(void)
}
}
void
reaktor_windows_dirty(void)
{
int i;
for (i = 0; i < g_win_n; i++)
g_win[i].app->dirty = 1;
}
void
reaktor_windows_rescale(void)
{
+4 -5
View File
@@ -272,16 +272,15 @@ login_card(App *app, struct nk_context *ctx, float body_x, float body_w,
{
struct nk_rect at;
float card_h = card_height(g_show_contact);
float side = body_x + (body_w - (float)CARD_W) * 0.5f;
float card_w = body_w - 16.0f < (float)CARD_W ? body_w - 16.0f : (float)CARD_W;
float side = body_x + (body_w - card_w) * 0.5f;
float top = body_y + (body_h - card_height(0)) * 0.5f;
if (side < body_x + 8.0f) side = body_x + 8.0f;
if (top + card_h > body_y + body_h - 8.0f)
top = body_y + body_h - card_h - 8.0f;
if (top < body_y + 8.0f) top = body_y + 8.0f;
nk_layout_space_push(ctx, nk_rect(side, top, (float)CARD_W, card_h));
nk_layout_space_push(ctx, nk_rect(side, top, card_w, card_h));
at = nk_widget_bounds(ctx);
@@ -293,7 +292,7 @@ login_card(App *app, struct nk_context *ctx, float body_x, float body_w,
nk_style_push_vec2(ctx, &ctx->style.window.group_padding, nk_vec2(0, 0));
if (nk_group_begin(ctx, "card", NK_WINDOW_NO_SCROLLBAR)) {
REAKTOR_COLUMN(.name = "Proceed with login",
.w = CARD_W, .h = card_h, .gap = ROW_GAP) {
.w = card_w, .h = card_h, .gap = ROW_GAP) {
REAKTOR_ROW(.h = ROW_BRAND, .gap = 10, .flags = REAKTOR_LAY_FILL_X,
.ml = CARD_PAD_X, .mr = CARD_PAD_X, .mt = CARD_PAD_Y) {
reaktor_icon(&(reaktor_icon_spec){
+613 -15
View File
@@ -227,6 +227,7 @@ seed(showcase_state *s)
s->anim_ms = 320;
s->anim_curve = REAKTOR_EASE_CUBIC_OUT;
s->anim_slot = 0;
for (i = 0; i < 4; i++) s->grow[i] = 1.0f;
SDL_strlcpy(s->name, "Ada Lovelace", sizeof(s->name));
s->name_len = (int)strlen(s->name);
@@ -1861,24 +1862,550 @@ track_at(App *app, struct nk_context *ctx, struct nk_rect r, float where,
nk_rgb(140, 140, 140)));
}
static struct nk_color
well_color(void)
{
return reaktor_token("--background-alt", nk_rgb(48, 48, 48));
}
static struct nk_color
well_ink(float strength)
{
struct nk_colorf well = nk_color_cf(well_color());
return nk_rgb_cf(nka_color_blend(well, nk_color_cf(reaktor_on(well_color())),
strength, NKA_COL_OKLAB));
}
static void
well_caption(struct nk_context *ctx, struct nk_rect r, const char *text)
{
const struct nk_user_font *f = ctx->style.font;
int len = (int)strlen(text);
float w = f->width(f->userdata, f->height, text, len);
nk_draw_text(nk_window_get_canvas(ctx),
nk_rect(r.x + 10.0f, r.y + r.h - f->height - 8.0f, w + 2.0f, f->height + 2.0f),
text, len, f, nk_rgba(0, 0, 0, 0), well_ink(0.6f));
}
static float
tile_value(struct nka_context *a, nk_hash tile, nk_hash ch, float rest)
{
float v;
return nka_instance_get_float(a, tile, ch, &v) ? v : rest;
}
static void
clip_demo(App *app, struct nk_context *ctx)
{
const float cell = 34.0f;
struct nka_context *a = reaktor_anim(app);
nk_hash clip = nka_id("showcase.tiles");
nk_hash size = nka_id("size"), fade = nka_id("fade");
nk_hash lift = nka_id("lift"), glow = nka_id("glow");
int i, replay = 0;
section(app, ctx, "One clip, every tile",
"A clip is keyframes written once and played anywhere. Here the "
"same four tracks - size, opacity, a lift and a glow - run on "
"every tile in the grid, each tile starting a little after its "
"neighbor nearer the middle, so the grid opens from the center "
"out. The delay comes from a tile's place in the grid, not from "
"code that knows about the others. Under it is NukAnim's own "
"debug timeline, following the outlined tile: its tracks, its "
"keys, which one is running and where the playhead is.");
api(app, ctx, "nka_play_with_delay(anim, clip, tile, nka_stagger_grid_delay_index(anim, i, &grid))"
" / nka_show_debug_timeline(anim, ctx, tile)");
if (!nka_clip_exists(a, clip)) {
nka_clip_begin(a, clip);
nka_clip_key_float(a, size, 0.0f, 0.4f, NKA_EASE_OUT_BACK, NULL);
nka_clip_key_float(a, size, 0.5f, 1.0f, NKA_EASE_LINEAR, NULL);
nka_clip_key_float(a, fade, 0.0f, 0.0f, NKA_EASE_OUT_CUBIC, NULL);
nka_clip_key_float(a, fade, 0.3f, 1.0f, NKA_EASE_LINEAR, NULL);
nka_clip_key_vec2(a, lift, 0.0f, nk_vec2(0.0f, 12.0f), NKA_EASE_OUT_CUBIC, NULL);
nka_clip_key_vec2(a, lift, 0.45f, nk_vec2(0.0f, 0.0f), NKA_EASE_LINEAR, NULL);
nka_clip_key_float(a, glow, 0.0f, 1.0f, NKA_EASE_IN_OUT_SINE, NULL);
nka_clip_key_float(a, glow, 0.9f, 0.0f, NKA_EASE_LINEAR, NULL);
nka_clip_end(a);
}
REAKTOR_ROW(.h = ROW, .flags = REAKTOR_LAY_PACK_CENTER) {
if (reaktor_button(&(reaktor_button_spec){
.label = "Replay", .name = "Replay the tiles",
.box = { .w = 96.0f, .flags = REAKTOR_LAY_FILL_Y } }))
replay = 1;
}
REAKTOR_COLUMN(.gap = 6.0f) REAKTOR_ROW(.h = 4.0f * cell, .flags = REAKTOR_LAY_FILL_X) {
struct nk_rect r;
if (reaktor_box_rect(&r)) {
struct nk_command_buffer *cv = nk_window_get_canvas(ctx);
struct nka_stagger_grid_opts grid = nka_stagger_grid_opts_default();
struct nk_colorf rest = nk_color_cf(well_color());
struct nk_colorf lit = nk_color_cf(reaktor_token("--links", nk_rgb(0, 112, 224)));
int cols = (int)(r.w / cell), n;
float x0;
if (cols < 1) cols = 1;
n = cols * 4;
x0 = r.x + (r.w - (float)cols * cell) * 0.5f;
grid.cols = cols;
grid.rows = 4;
grid.from = NKA_STAGGER_CENTER;
grid.delay = 0.6f / (float)(n - 1);
for (i = 0; i < n; i++) {
nk_hash tile = nka_id_mix(clip, (nk_hash)i + 1u);
float cx = x0 + ((float)(i % cols) + 0.5f) * cell;
float cy = r.y + ((float)(i / cols) + 0.5f) * cell;
float side = cell - 6.0f, k, alpha;
struct nk_vec2 up = nk_vec2(0.0f, 0.0f);
struct nk_color c;
if (replay)
nka_play_with_delay(a, clip, tile, nka_stagger_grid_delay_index(a, i, &grid));
else if (!nka_instance_valid(a, tile) && nka_play(a, clip, tile))
nka_instance_seek(a, tile, nka_clip_duration(a, clip));
k = side * tile_value(a, tile, size, 1.0f);
alpha = tile_value(a, tile, fade, 1.0f);
nka_instance_get_vec2(a, tile, lift, &up);
c = nk_rgb_cf(nka_color_blend(rest, lit, tile_value(a, tile, glow, 0.0f), NKA_COL_OKLAB));
c.a = (nk_byte)(255.0f * (alpha < 0.0f ? 0.0f : alpha > 1.0f ? 1.0f : alpha) + 0.5f);
if (i == 0)
reaktor_edge_round(app, cv, nk_rect(cx - side * 0.5f - 3.0f, cy - side * 0.5f - 3.0f,
side + 6.0f, side + 6.0f),
8.0f, 2.0f, well_ink(0.7f));
if (c.a && k > 0.0f)
reaktor_fill_round(app, cv, nk_rect(cx - k * 0.5f, cy - k * 0.5f + up.y, k, k),
k * 0.2f, c);
}
}
}
nka_show_debug_timeline(a, ctx, nka_id_mix(clip, 1u));
{
const struct nk_panel *l = ctx->current->layout;
reaktor_hot_follow(app, nk_rect(l->bounds.x, l->at_y - (float)*l->offset_y,
l->bounds.w, l->row.height), 0);
}
}
static void
build_paths(struct nka_context *a, nk_hash curve, nk_hash wave, float w, float h, float wave_h)
{
const float m = 24.0f;
int i, n = (int)(w / 160.0f);
float y = wave_h * 0.66f, amp = wave_h * 0.2f, step;
n = n < 2 ? 2 : n > 4 ? 4 : n;
step = w / (float)n;
nka_path_begin(a, curve, nk_vec2(m, h - m));
nka_path_cubic_to(a, nk_vec2(w * 0.2f, h - m), nk_vec2(w * 0.24f, m), nk_vec2(w * 0.4f, m));
nka_path_line_to(a, nk_vec2(w * 0.55f, m));
nka_path_cubic_to(a, nk_vec2(w * 0.75f, m), nk_vec2(w * 0.62f, h - m), nk_vec2(w * 0.84f, h - m));
nka_path_quadratic_to(a, nk_vec2(w - m, h - m), nk_vec2(w - m, m));
nka_path_end(a);
nka_path_build_arc_lut(a, curve, 0);
nka_path_begin(a, wave, nk_vec2(0.0f, y));
for (i = 0; i < n; i++) {
float x = step * (float)i, dy = i & 1 ? amp : -amp;
nka_path_cubic_to(a, nk_vec2(x + step * 0.36f, y + dy), nk_vec2(x + step * 0.64f, y + dy),
nk_vec2(x + step, y));
}
nka_path_end(a);
nka_path_build_arc_lut(a, wave, 0);
}
static void
path_dots(App *app, struct nk_context *ctx, struct nka_context *a, nk_hash path, struct nk_vec2 at)
{
struct nk_command_buffer *cv = nk_window_get_canvas(ctx);
struct nk_color ink = well_ink(0.35f);
float len = nka_path_length(a, path), d;
for (d = 0.0f; d <= len; d += 12.0f) {
struct nk_vec2 p = nka_path_evaluate_at_distance(a, path, d);
reaktor_fill_round(app, cv, nk_rect(at.x + p.x - 1.5f, at.y + p.y - 1.5f, 3.0f, 3.0f), 1.5f, ink);
}
}
static void
path_demo(App *app, struct nk_context *ctx, showcase_state *s)
{
static float built_w, built_h;
static const char words[] = "Text can follow any path you draw";
const float wave_h = 96.0f;
struct nka_context *a = reaktor_anim(app);
nk_hash curve = nka_id("showcase.curve"), wave = nka_id("showcase.wave");
nk_hash run = (nk_hash)s->path_runs;
struct nka_ease linear = nka_ease(NKA_EASE_LINEAR);
struct nk_rect r;
section(app, ctx, "Along a path",
"A path is lines and curves joined end to end. Ridden by plain t, "
"a dot slows wherever a curve bunches up; NukAnim measures the "
"path once and rides it by distance, so the dot keeps one speed "
"through bends and straights alike, and the path's direction "
"turns it to face where it is going. The dots it passes are "
"spaced the same way, every twelve pixels along the line. Text "
"can travel a path too, a glyph at a time, each one standing on "
"the line.");
api(app, ctx, "nka_tween_path(anim, id, run, path, 2.4f, ease, 0) / nka_tween_path_angle / "
"nka_text_path_animated(anim, ctx, path, text, t, &opts)");
REAKTOR_ROW(.h = ROW, .flags = REAKTOR_LAY_PACK_CENTER) {
if (reaktor_button(&(reaktor_button_spec){
.label = "Send", .name = "Send the dot and the text",
.box = { .w = 96.0f, .flags = REAKTOR_LAY_FILL_Y } }))
s->path_runs++;
}
REAKTOR_COLUMN(.gap = 6.0f) {
REAKTOR_ROW(.h = 140.0f, .flags = REAKTOR_LAY_FILL_X) {
if (reaktor_box_rect(&r)) {
struct nk_command_buffer *cv = nk_window_get_canvas(ctx);
unsigned id = reaktor_box_id();
struct nk_vec2 p, tip, at = nk_vec2(r.x, r.y);
float angle;
if (r.w != built_w || r.h != built_h || !nka_path_exists(a, curve)) {
build_paths(a, curve, wave, r.w, r.h, wave_h);
built_w = r.w;
built_h = r.h;
}
reaktor_fill_round(app, cv, r, 6.0f, well_color());
path_dots(app, ctx, a, curve, at);
if (run) {
p = nka_tween_path(a, id, run, curve, 2.4f, linear, NKA_POLICY_CROSSFADE);
angle = nka_tween_path_angle(a, id, run, curve, 2.4f, linear, NKA_POLICY_CROSSFADE);
} else {
p = nka_path_evaluate(a, curve, 0.0f);
angle = nka_path_angle(a, curve, 0.0f);
}
p.x += at.x;
p.y += at.y;
tip = nk_vec2(p.x + 18.0f * cosf(angle), p.y + 18.0f * sinf(angle));
nk_stroke_line(cv, p.x, p.y, tip.x, tip.y, 2.0f, well_ink(1.0f));
reaktor_fill_round(app, cv, nk_rect(p.x - 8.0f, p.y - 8.0f, 16.0f, 16.0f), 8.0f,
reaktor_token("--links", nk_rgb(0, 112, 224)));
reaktor_fill_round(app, cv, nk_rect(tip.x - 3.0f, tip.y - 3.0f, 6.0f, 6.0f), 3.0f,
well_ink(1.0f));
}
}
REAKTOR_ROW(.h = wave_h, .flags = REAKTOR_LAY_FILL_X) {
unsigned id = reaktor_box_id();
float t = run ? nka_tween_float(a, id, run, 1.0f, 1.4f, linear, NKA_POLICY_CROSSFADE, 0.0f)
: 1.0f;
if (reaktor_box_rect(&r) && nka_path_exists(a, wave)) {
struct nka_text_path_opts o = nka_text_path_opts_default();
reaktor_fill_round(app, nk_window_get_canvas(ctx), r, 6.0f, well_color());
path_dots(app, ctx, a, wave, nk_vec2(r.x, r.y));
o.origin = nk_vec2(r.x, r.y);
o.align = NKA_TEXT_ALIGN_CENTER;
o.color = well_ink(1.0f);
nka_text_path_animated(a, ctx, wave, words, t, &o);
}
}
}
}
static void
fx_demo(App *app, struct nk_context *ctx, showcase_state *s)
{
static const char *const what[3] = { "oscillate", "wiggle", "noise" };
struct nka_context *a = reaktor_anim(app);
nk_hash fx = nka_id("showcase.fx"), shake = nka_id("showcase.shake");
float on;
int i;
section(app, ctx, "Motion nobody keyed",
"Some motion has no keyframes: a bob, a drift, a tremor. "
"Oscillate is a wave, wiggle wanders smoothly between random "
"points, and noise reads Perlin noise along time - each one a "
"function of the clock, so none of it needs a start or an end. "
"They move only while Play is on, because a page at rest should "
"draw nothing. A shake is the same idea with a decay: it starts "
"when something goes wrong and dies out on its own. Sign in "
"below - the password is wrong, and the field says so.");
api(app, ctx, "nka_oscillate / nka_wiggle_vec2 / nka_noise_channel_vec2 / "
"nka_trigger_shake + nka_shake");
REAKTOR_ROW(.h = ROW, .flags = REAKTOR_LAY_PACK_CENTER) {
if (reaktor_button(&(reaktor_button_spec){
.label = s->fx_play ? "Pause" : "Play", .name = "Play the motion",
.accent = (unsigned char)s->fx_play,
.box = { .w = 96.0f, .flags = REAKTOR_LAY_FILL_Y } }))
s->fx_play = !s->fx_play;
}
on = nka_tween_float(a, fx, 0, s->fx_play ? 1.0f : 0.0f, 0.4f, nka_ease(NKA_EASE_OUT_CUBIC),
NKA_POLICY_CROSSFADE, 0.0f);
if (on <= 0.0f) s->trail_n = 0;
REAKTOR_COLUMN(.gap = 6.0f) REAKTOR_ROW(.h = 120.0f, .gap = 12.0f, .flags = REAKTOR_LAY_FILL_X) {
for (i = 0; i < 3; i++)
REAKTOR_ROW(.name = what[i], .flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y) {
struct nk_rect r;
if (reaktor_box_rect(&r)) {
struct nk_command_buffer *cv = nk_window_get_canvas(ctx);
float ax = r.w * 0.34f, ay = (r.h - 24.0f) * 0.36f;
struct nk_vec2 c = nk_vec2(r.x + r.w * 0.5f, r.y + (r.h - 24.0f) * 0.5f);
struct nk_vec2 d = nk_vec2(0.0f, 0.0f);
struct nk_color dot = reaktor_token("--links", nk_rgb(0, 112, 224));
int j;
reaktor_fill_round(app, cv, r, 6.0f, well_color());
well_caption(ctx, r, what[i]);
if (i == 0)
nk_stroke_line(cv, c.x, c.y - ay, c.x, c.y + ay, 2.0f, well_ink(0.25f));
if (on > 0.0f) {
nk_hash id = nka_id_mix(fx, (nk_hash)i + 1u);
if (i == 0) {
d.y = nka_oscillate(a, id, ay, 0.6f, NKA_WAVE_SINE, 0.0f);
} else if (i == 1) {
d = nka_wiggle_vec2(a, id, nk_vec2(ax, ay), 1.4f);
} else {
struct nka_noise_opts o = nka_noise_opts_default();
o.octaves = 2;
d = nka_noise_channel_vec2(a, id, nk_vec2(0.7f, 0.7f),
nk_vec2(ax * 1.6f, ay * 1.6f), &o);
d.x = d.x < -ax ? -ax : d.x > ax ? ax : d.x;
d.y = d.y < -ay ? -ay : d.y > ay ? ay : d.y;
}
d.x *= on;
d.y *= on;
if (i == 2 && nka_time(a) - s->trail_at >= 0.035) {
s->trail_at = nka_time(a);
if (s->trail_n == (int)NK_LEN(s->trail)) {
memmove(s->trail, s->trail + 1, sizeof(s->trail) - sizeof(s->trail[0]));
s->trail_n--;
}
s->trail[s->trail_n++] = d;
}
}
if (i == 2)
for (j = 0; j + 1 < s->trail_n; j++) {
float k = (float)(j + 1) / (float)s->trail_n, rad = 2.0f + 4.0f * k;
struct nk_color t = dot;
t.a = (nk_byte)(160.0f * k);
reaktor_fill_round(app, cv,
nk_rect(c.x + s->trail[j].x - rad, c.y + s->trail[j].y - rad,
2.0f * rad, 2.0f * rad),
rad, t);
}
reaktor_fill_round(app, cv, nk_rect(c.x + d.x - 8.0f, c.y + d.y - 8.0f, 16.0f, 16.0f),
8.0f, dot);
}
}
}
REAKTOR_COLUMN(.gap = 6.0f) REAKTOR_ROW(.h = 40.0f, .gap = ctx->style.window.spacing.x,
.flags = REAKTOR_LAY_FILL_X) {
REAKTOR_ROW(.name = "Password", .flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y) {
float dx = nka_shake(a, shake, 26.0f, 22.0f, 0.6f);
struct nk_rect r;
if (reaktor_box_rect(&r)) {
struct nk_command_buffer *cv = nk_window_get_canvas(ctx);
const struct nk_style_edit *e = &ctx->style.edit;
struct nk_rect f = nk_rect(r.x + dx, r.y, r.w, r.h);
int j;
reaktor_fill_round(app, cv, f, e->rounding,
e->normal.type == NK_STYLE_ITEM_COLOR ? e->normal.data.color : well_color());
reaktor_edge_round(app, cv, f, e->rounding, 2.0f,
reaktor_token("--background-hover", nk_rgb(69, 69, 69)));
for (j = 0; j < 8; j++)
reaktor_fill_round(app, cv, nk_rect(f.x + 14.0f + 14.0f * (float)j, f.y + f.h * 0.5f - 3.5f,
7.0f, 7.0f),
3.5f, e->text_normal);
}
}
if (reaktor_button(&(reaktor_button_spec){
.label = "Sign in",
.box = { .w = 110.0f, .flags = REAKTOR_LAY_FILL_Y } }))
nka_trigger_shake(a, shake);
}
}
static void
color_demo(App *app, struct nk_context *ctx, showcase_state *s)
{
static const char *const name[5] = { "sRGB", "linear", "HSV", "OKLAB", "OKLCH" };
static const int space[5] = {
NKA_COL_SRGB, NKA_COL_SRGB_LINEAR, NKA_COL_HSV, NKA_COL_OKLAB, NKA_COL_OKLCH
};
struct nka_context *a = reaktor_anim(app);
struct nk_colorf from = nk_color_cf(nk_rgb(14, 165, 233)), to = nk_color_cf(nk_rgb(234, 88, 12));
int i;
section(app, ctx, "Five ways to mix two colors",
"Halfway from sky blue to orange is a different color depending "
"on what gets averaged. The numbers of sRGB meet in a muddy gray, "
"and linear light - the way light really adds - meets brighter. "
"HSV turns the hue and passes through green. OKLAB is built so "
"that equal steps look equal, and OKLCH turns the hue in it the "
"other way round, through violet: each takes the short way round "
"its own wheel, and the two wheels disagree. Each strip is one "
"blend drawn whole, and Swap sends the swatch beside it from one "
"end to the other through the same space.");
api(app, ctx, "nka_color_blend(a, b, t, NKA_COL_OKLCH) / "
"nka_tween_color(anim, id, 0, to, 1.6f, ease, NKA_POLICY_CROSSFADE, NKA_COL_OKLCH, from)");
REAKTOR_ROW(.h = ROW, .flags = REAKTOR_LAY_PACK_CENTER) {
if (reaktor_button(&(reaktor_button_spec){
.label = "Swap", .name = "Swap the colors",
.box = { .w = 96.0f, .flags = REAKTOR_LAY_FILL_Y } }))
s->color_swap = !s->color_swap;
}
REAKTOR_COLUMN(.gap = 6.0f) {
for (i = 0; i < 5; i++)
REAKTOR_ROW(.h = 34.0f, .gap = 12.0f, .flags = REAKTOR_LAY_FILL_X) {
struct nk_rect r;
reaktor_label(&(reaktor_label_spec){
.text = name[i], .color = "--text-bright",
.box = { .w = 74.0f, .flags = REAKTOR_LAY_CENTER_Y } });
REAKTOR_ROW(.flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y) {
if (reaktor_box_rect(&r)) {
struct nk_command_buffer *cv = nk_window_get_canvas(ctx);
int n = (int)(r.w / 4.0f), j;
for (j = 0; j < n; j++) {
float x0 = r.x + (float)(int)((float)j * r.w / (float)n);
float x1 = r.x + (float)(int)((float)(j + 1) * r.w / (float)n);
nk_fill_rect(cv, nk_rect(x0, r.y, x1 - x0, r.h), 0.0f,
nk_rgb_cf(nka_color_blend(from, to, ((float)j + 0.5f) / (float)n,
space[i])));
}
}
}
REAKTOR_ROW(.w = 64.0f, .flags = REAKTOR_LAY_FILL_Y) {
struct nk_colorf c = nka_tween_color(a, reaktor_box_id(), 0, s->color_swap ? to : from,
1.6f, nka_ease(NKA_EASE_IN_OUT_SINE),
NKA_POLICY_CROSSFADE, space[i], from);
if (reaktor_box_rect(&r))
reaktor_fill_round(app, nk_window_get_canvas(ctx), r, 6.0f, nk_rgb_cf(c));
}
}
}
}
static void
text_demo(App *app, struct nk_context *ctx, showcase_state *s)
{
static const char *const name[5] = { "fade", "slide up", "bounce", "typewriter", "scale" };
static const int effect[5] = {
NKA_TEXT_FX_FADE, NKA_TEXT_FX_SLIDE_UP, NKA_TEXT_FX_BOUNCE, NKA_TEXT_FX_TYPEWRITER, NKA_TEXT_FX_SCALE
};
static const char line[] = "Each glyph waits its turn";
struct nka_context *a = reaktor_anim(app);
int i;
section(app, ctx, "A glyph at a time",
"Text that arrives one letter after another reads as being said "
"rather than shown. Every line below is the same stagger - each "
"glyph starts a fixed time after the one before it - with a "
"different thing done to a glyph as it arrives: faded in, slid "
"up, overshot in size, typed, or grown.");
api(app, ctx, "nka_text_stagger(anim, ctx, text, progress, &opts) / NKA_TEXT_FX_*");
REAKTOR_ROW(.h = ROW, .flags = REAKTOR_LAY_PACK_CENTER) {
if (reaktor_button(&(reaktor_button_spec){
.label = "Replay", .name = "Replay the text",
.box = { .w = 96.0f, .flags = REAKTOR_LAY_FILL_Y } }))
s->text_plays++;
}
REAKTOR_COLUMN(.gap = 6.0f) {
for (i = 0; i < 5; i++)
REAKTOR_ROW(.h = 34.0f, .gap = 12.0f, .flags = REAKTOR_LAY_FILL_X) {
reaktor_label(&(reaktor_label_spec){
.text = name[i], .color = "--text-bright",
.box = { .w = 74.0f, .flags = REAKTOR_LAY_CENTER_Y } });
REAKTOR_ROW(.flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y) {
struct nka_text_stagger_opts o = nka_text_stagger_opts_default();
float t = 1.0f;
struct nk_rect r;
o.effect = effect[i];
o.char_delay = 0.035f;
o.char_duration = 0.4f;
o.effect_intensity = 14.0f;
o.color = well_ink(1.0f);
if (s->text_plays)
t = nka_tween_float(a, reaktor_box_id(), (nk_hash)s->text_plays, 1.0f,
nka_text_stagger_duration(line, &o), nka_ease(NKA_EASE_LINEAR),
NKA_POLICY_CROSSFADE, 0.0f);
if (reaktor_box_rect(&r)) {
struct nk_command_buffer *cv = nk_window_get_canvas(ctx);
struct nk_rect keep = cv->clip;
float x0 = r.x > keep.x ? r.x : keep.x, y0 = r.y > keep.y ? r.y : keep.y;
float x1 = r.x + r.w < keep.x + keep.w ? r.x + r.w : keep.x + keep.w;
float y1 = r.y + r.h < keep.y + keep.h ? r.y + r.h : keep.y + keep.h;
reaktor_fill_round(app, cv, r, 6.0f, well_color());
o.pos = nk_vec2(r.x + 12.0f, r.y + (r.h - ctx->style.font->height) * 0.5f);
nk_push_scissor(cv, nk_rect(x0, y0, x1 > x0 ? x1 - x0 : 0.0f, y1 > y0 ? y1 - y0 : 0.0f));
nka_text_stagger(a, ctx, line, t, &o);
nk_push_scissor(cv, keep);
}
}
}
}
}
static void
page_animation(App *app, struct nk_context *ctx, showcase_state *s)
{
static const float stop[3] = { 0.0f, 0.5f, 1.0f };
static const char *const stop_name[3] = { "Left", "Center", "Right" };
static const char *const kind[3] = { "spring", "steps", "bezier" };
unsigned char curve = (unsigned char)s->anim_curve;
float ms = (float)s->anim_ms;
struct nka_ease ease[3];
int i;
section(app, ctx, "The same change, twice",
"Both blocks are told to go to the same place by the same button. "
ease[0] = nka_ease_spring(1.0f, 170.0f, 16.0f, 0.0f);
ease[1] = nka_ease_steps(6, 0);
ease[2] = nka_ease_bezier(0.68f, -0.55f, 0.27f, 1.55f);
section(app, ctx, "The same change, five ways",
"Every block is told to go to the same place by the same button. "
"The top one is simply put there, which is what a frame does "
"without help. The bottom one is given the time to travel, and "
"the difference is the whole subject of this page: the eye "
"follows a thing that moves and has to re-find a thing that "
"jumps. Press one stop and then another before it arrives - it "
"redirects from where it is rather than starting again.");
api(app, ctx, "reaktor_animate(id, channel, to, ms, curve)");
"without help. The rest are given the time to travel, and the "
"difference is the whole subject of this page: the eye follows a "
"thing that moves and has to re-find a thing that jumps. Eased "
"runs the curve picked further down. The last three go past the "
"classic thirty-one, with NukAnim, which runs every animation on "
"this page: a spring that settles the way a spring does, steps "
"that move in jumps like the hand of a clock, and whatever cubic "
"bezier a design hands over. Press one stop and then another "
"before they arrive - each redirects from where it is rather "
"than starting again.");
api(app, ctx, "reaktor_animate(id, channel, to, ms, curve) / "
"nka_tween_float(reaktor_anim(app), id, 0, to, 0.6f, nka_ease_spring(1, 170, 16, 0), ...)");
REAKTOR_ROW(.h = ROW, .gap = ctx->style.window.spacing.x) {
for (i = 0; i < 3; i++)
@@ -1916,6 +2443,23 @@ page_animation(App *app, struct nk_context *ctx, showcase_state *s)
track_at(app, ctx, r, where, 1);
}
}
for (i = 0; i < 3; i++)
REAKTOR_ROW(.h = 44.0f, .gap = 12.0f, .flags = REAKTOR_LAY_FILL_X) {
reaktor_label(&(reaktor_label_spec){
.text = kind[i], .color = "--text-bright",
.box = { .w = 74.0f, .flags = REAKTOR_LAY_CENTER_Y } });
REAKTOR_ROW(.flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y) {
unsigned id = reaktor_box_id();
float to = stop[s->anim_slot];
float where = nka_tween_float(reaktor_anim(app), id, 0, to, 0.6f,
ease[i], NKA_POLICY_CROSSFADE, to);
struct nk_rect r;
if (reaktor_box_rect(&r))
track_at(app, ctx, r, where, 1);
}
}
}
section(app, ctx, "Pick a curve by looking at it",
@@ -1930,8 +2474,8 @@ page_animation(App *app, struct nk_context *ctx, showcase_state *s)
"chose, which is the value arriving.");
api(app, ctx, "reaktor_ease_at(curve, t) / REAKTOR_EASE_*");
REAKTOR_ROW(.h = ROW, .gap = ctx->style.window.spacing.x,
.flags = REAKTOR_LAY_PACK_CENTER) {
REAKTOR_ROW(.gap = ctx->style.window.spacing.x,
.flags = REAKTOR_LAY_PACK_CENTER | REAKTOR_LAY_WRAP) {
unsigned id = reaktor_box_id();
reaktor_animate(id, 0, s->anim_play ? 1.0f : 0.0f, ms, curve);
@@ -1940,13 +2484,12 @@ page_animation(App *app, struct nk_context *ctx, showcase_state *s)
if (reaktor_button(&(reaktor_button_spec){
.label = "Play",
.name = "Run the selected curve",
.box = { .w = 96.0f, .flags = REAKTOR_LAY_FILL_Y } }))
.box = { .w = 96.0f, .h = ROW } }))
s->anim_play = !s->anim_play;
REAKTOR_COMBO(.label = reaktor_ease_name(curve), .name = "Curve",
.body_h = 300.0f,
.box = { .w = 190.0f,
.flags = REAKTOR_LAY_FILL_Y }) {
.box = { .w = 190.0f, .h = ROW }) {
nk_layout_row_dynamic(ctx, 26.0f, 1);
for (i = 0; i < REAKTOR_EASE_COUNT; i++)
if (reaktor_combo_item(reaktor_ease_name((unsigned char)i),
@@ -1958,7 +2501,7 @@ page_animation(App *app, struct nk_context *ctx, showcase_state *s)
.label = "ms:", .name = "Duration",
.ivalue = &s->anim_ms, .lo = 60, .hi = 3000, .step = 20,
.grain = 4.0f,
.box = { .w = 200.0f, .flags = REAKTOR_LAY_FILL_Y } });
.box = { .w = 200.0f, .h = ROW } });
}
REAKTOR_ROW(.gap = 6.0f, .flags = REAKTOR_LAY_WRAP) {
@@ -1983,6 +2526,58 @@ page_animation(App *app, struct nk_context *ctx, showcase_state *s)
}
}
section(app, ctx, "Grows when you point at it",
"A tile that rises a little under the pointer says it can be "
"pressed before anyone presses it. Each one keeps its size in a "
"float of its own, and nka_animate, which comes from ImAnimate, "
"eases that float up while the pointer is over the tile and back "
"when it leaves - from wherever it got to, so a quick pass never "
"jumps. The color crossfades the same way, through OKLAB, where "
"the middle of two colors still looks like both of them.");
api(app, ctx, "nka_animate(reaktor_anim(app), 1, 1.1f, 150, &size, NKA_EASE_OUT_CUBIC)");
REAKTOR_COLUMN(.gap = 6.0f) REAKTOR_ROW(.h = 96.0f, .gap = 12.0f, .flags = REAKTOR_LAY_FILL_X) {
static const char *const word[4] = { "Home", "Search", "Library", "Profile" };
struct nka_context *anim = reaktor_anim(app);
struct nk_command_buffer *cv = nk_window_get_canvas(ctx);
const struct nk_user_font *f = ctx->style.font;
struct nk_colorf rest = nk_color_cf(reaktor_token("--background-alt", nk_rgb(48, 48, 48)));
struct nk_colorf lit = nk_color_cf(reaktor_token("--links", nk_rgb(0, 112, 224)));
for (i = 0; i < 4; i++)
REAKTOR_ROW(.name = word[i], .flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y) {
struct nk_rect r;
if (reaktor_box_rect(&r)) {
int over = nk_input_is_mouse_hovering_rect(&ctx->input, r);
int len = (int)strlen(word[i]);
float w, h, tw;
struct nk_color bg;
reaktor_hot(app, r, 0, 1);
if (over) nka_animate(anim, 1.0f, 1.1f, 150.0f, &s->grow[i], NKA_EASE_OUT_CUBIC);
else nka_animate(anim, 1.1f, 1.0f, 250.0f, &s->grow[i], NKA_EASE_OUT_CUBIC);
bg = nk_rgb_cf(nka_tween_color(anim, reaktor_box_id(), 1, over ? lit : rest, 0.2f,
nka_ease(NKA_EASE_OUT_CUBIC), NKA_POLICY_CROSSFADE,
NKA_COL_OKLAB, rest));
w = r.w * 0.86f * s->grow[i];
h = r.h * 0.8f * s->grow[i];
reaktor_fill_round(app, cv, nk_rect(r.x + (r.w - w) * 0.5f, r.y + (r.h - h) * 0.5f, w, h),
10.0f * s->grow[i], bg);
tw = f->width(f->userdata, f->height, word[i], len);
nk_draw_text(cv, nk_rect(r.x + (r.w - tw) * 0.5f, r.y + (r.h - f->height) * 0.5f,
tw + 2.0f, f->height + 2.0f),
word[i], len, f, nk_rgba(0, 0, 0, 0), reaktor_on(bg));
}
}
}
clip_demo(app, ctx);
path_demo(app, ctx, s);
fx_demo(app, ctx, s);
color_demo(app, ctx, s);
text_demo(app, ctx, s);
nk_layout_row_dynamic(ctx, 8.0f, 1);
nk_spacer(ctx);
}
@@ -2258,14 +2853,17 @@ page_translations(App *app, struct nk_context *ctx, showcase_state *s)
int i, n = reaktor_locale_count();
struct nk_rect row;
nk_layout_row_begin(ctx, NK_STATIC, (float)(TAB_H - 6), n);
nk_layout_row_begin(ctx, NK_STATIC, (float)(TAB_H - 6), n + 1);
row = nk_widget_bounds(ctx);
row.w = nk_window_get_content_region_size(ctx).x;
reaktor_note_push(app, REAKTOR_A11Y_GROUP, "Language", NULL, 0, row);
if (sample_option(app, ctx, "System", 0.0f, reaktor_locale_system()))
reaktor_locale_set(NULL);
for (i = 0; i < n; i++) {
const char *code = reaktor_locale_code(i);
if (sample_option(app, ctx, reaktor_locale_name(i), 0.0f,
!reaktor_locale_system() &&
!strcmp(code, reaktor_locale_current())))
reaktor_locale_set(code);
}
+6
View File
@@ -84,6 +84,12 @@ typedef struct showcase_state {
int anim_ms;
float anim_head;
nk_bool anim_play;
float grow[4];
int path_runs, text_plays;
nk_bool fx_play, color_swap;
struct nk_vec2 trail[16];
int trail_n;
double trail_at;
char menu_pick[40];
char file_pick[SC_PATH_CAP];
+9 -10
View File
@@ -124,6 +124,13 @@ struct App {
int dragging;
int drag_mouse;
int touch, touch_in_field, touch_n;
float touch_x0, touch_y0, touch_last, touch_unit;
float touch_ys[4];
Uint64 touch_ns[4];
float fling_v;
Uint64 fling_ns;
int restore_rate;
int borderless;
#ifdef __APPLE__
@@ -219,6 +226,7 @@ struct App {
Uint64 fps_t0;
Uint64 last_frame_ms;
float frame_gap_ms;
struct nka_context *anim;
int style_ms_x100;
int sheets;
const char *font_face, *font_face_bold;
@@ -239,7 +247,6 @@ void image_centred(struct nk_context *ctx, struct nk_image im, int px);
const struct nk_user_font *pick_font(App *app, int px, int bold);
void rebuild_font(App *app);
void apply_render_scale(App *app);
SDL_Surface *reaktor_icon_surface(const char *name, int px);
void reaktor_set_window_icon(SDL_Window *win, const char *name);
struct nk_color col_of(const unsigned char c[4]);
@@ -318,6 +325,7 @@ void reaktor_windows_take(App *app, const SDL_Event *event);
int reaktor_windows_retitle(App *app, const char *title);
void reaktor_windows_draw(void);
void reaktor_windows_restyle(void);
void reaktor_windows_dirty(void);
void reaktor_windows_rescale(void);
void reaktor_windows_close_all(void);
const char *reaktor_launch_icon(void);
@@ -359,8 +367,6 @@ void note_ime_caret(App *app, struct nk_context *ctx, struct nk_rect bounds,
void draw_hint(struct nk_context *ctx, struct nk_rect bounds, const char *hint,
const reaktor_style *s);
struct nk_image reaktor_ionicon_exact(App *app, const char *name, int px,
struct nk_color stroke, float sw);
struct nk_image reaktor_ionicon_col(App *app, const char *name, int px,
struct nk_color stroke);
@@ -370,8 +376,6 @@ void reaktor_image(App *app, struct nk_context *ctx, struct nk_image im,
int reaktor_fit_label(App *app, struct nk_context *ctx, struct nk_rect b);
void reaktor_unfit_label(struct nk_context *ctx, int fitted);
void reaktor_glyph_at(App *app, struct nk_context *ctx, struct nk_rect slot,
const char *name, struct nk_color col, int px, float sw);
#define REAKTOR_DISC_ROUND "ellipse"
#define REAKTOR_DISC_RING "radio-button-off"
#define REAKTOR_DISC_OUTLINE "ellipse-outline"
@@ -395,14 +399,9 @@ void reaktor_combo_chrome(App *app, struct nk_context *ctx, struct nk_rect h,
int reaktor_link_label(App *app, struct nk_context *ctx, const char *label,
int active);
int reaktor_button_icon(App *app, struct nk_context *ctx,
const char *ionicon, const char *label);
int reaktor_button_color(App *app, struct nk_context *ctx, const char *name,
struct nk_color fill);
nk_flags reaktor_field_text(App *app, struct nk_context *ctx, nk_flags flags,
char *buf, int *len, int cap, const char *hint,
nk_plugin_filter filter, float pad_x, float pad_y);
void field_undo_clear(App *app);
int reaktor_focus_step(App *app, unsigned id);
+76 -39
View File
@@ -5,6 +5,7 @@
#include "anim.h"
static int g_fail;
static int g_moving;
static void
ok(const char *what, int cond)
@@ -13,16 +14,30 @@ ok(const char *what, int cond)
if (!cond) g_fail = 1;
}
static int
advance(float ms)
/* A frame of a page that shows one value: time moves, the page asks, the runtime settles. */
static float
frame(struct nka_context *a, unsigned id, unsigned channel, float to, float ms,
unsigned char curve, float gap_ms)
{
int moving = 0;
while (ms > 0.0f) {
float step = ms > 16.0f ? 16.0f : ms;
moving = reaktor_anim_tick(step);
ms -= step;
float v;
reaktor_anim_frame(a, gap_ms);
v = reaktor_animate(id, channel, to, ms, curve);
g_moving = reaktor_anim_settle();
return v;
}
/* Frames 16 ms apart until total has passed. */
static float
frames(struct nka_context *a, unsigned id, unsigned channel, float to, float ms,
unsigned char curve, float total)
{
float v = 0.0f;
while (total > 0.0f) {
float step = total > 16.0f ? 16.0f : total;
v = frame(a, id, channel, to, ms, curve, step);
total -= step;
}
return moving;
return v;
}
static int
@@ -109,63 +124,85 @@ static void
test_table(void)
{
const unsigned id = 4242u;
const unsigned char lin = REAKTOR_EASE_LINEAR;
struct nka_context *a = reaktor_anim_create();
float v;
int n;
puts("");
puts("a value starts where it is asked to, not at zero");
v = reaktor_animate(id, 0, 0.75f, 200.0f, REAKTOR_EASE_LINEAR);
v = frame(a, id, 0, 0.75f, 200.0f, lin, 16.0f);
ok("the first sight of it is its target", near(v, 0.75f));
ok("and nothing is moving", advance(16.0f) == 0);
ok("and nothing is moving", !g_moving);
puts("");
puts("a new target starts a run, and the run ends");
v = reaktor_animate(id, 0, 0.0f, 200.0f, REAKTOR_EASE_LINEAR);
v = frame(a, id, 0, 0.0f, 200.0f, lin, 0.0f);
ok("the frame that asks still sees the old value", near(v, 0.75f));
ok("something is moving now", advance(100.0f) == 1);
v = reaktor_animate(id, 0, 0.0f, 200.0f, REAKTOR_EASE_LINEAR);
ok("half way through a linear run is half way there",
near(v, 0.375f));
ok("the step that lands asks for the frame that shows it",
advance(100.0f) == 1);
ok("then nothing is moving", advance(16.0f) == 0);
v = reaktor_animate(id, 0, 0.0f, 200.0f, REAKTOR_EASE_LINEAR);
ok("and it arrives exactly", near(v, 0.0f));
ok("something is moving now", g_moving);
v = frames(a, id, 0, 0.0f, 200.0f, lin, 100.0f);
ok("half way through a linear run is half way there", near(v, 0.375f));
ok("and the dot on its curve says so", near(reaktor_anim_progress(id, 0), 0.5f));
v = frames(a, id, 0, 0.0f, 200.0f, lin, 100.0f);
ok("the frame that lands shows it arrived exactly", near(v, 0.0f));
ok("and asks for no more", !g_moving && reaktor_anim_progress(id, 0) < 0.0f);
puts("");
puts("a target that changes mid-flight redirects rather than restarts");
reaktor_animate(id, 0, 1.0f, 200.0f, REAKTOR_EASE_LINEAR);
advance(100.0f);
v = reaktor_animate(id, 0, 1.0f, 200.0f, REAKTOR_EASE_LINEAR);
frame(a, id, 0, 1.0f, 200.0f, lin, 0.0f);
v = frames(a, id, 0, 1.0f, 200.0f, lin, 100.0f);
ok("half way to 1", near(v, 0.5f));
reaktor_animate(id, 0, 0.0f, 200.0f, REAKTOR_EASE_LINEAR);
advance(100.0f);
v = reaktor_animate(id, 0, 0.0f, 200.0f, REAKTOR_EASE_LINEAR);
frame(a, id, 0, 0.0f, 200.0f, lin, 0.0f);
v = frames(a, id, 0, 0.0f, 200.0f, lin, 100.0f);
ok("and half way back from there, not from the end", near(v, 0.25f));
puts("");
puts("a channel is a separate value on the same widget");
reaktor_animate(id, 1, 10.0f, 200.0f, REAKTOR_EASE_LINEAR);
v = reaktor_animate(id, 1, 10.0f, 200.0f, REAKTOR_EASE_LINEAR);
v = frame(a, id, 1, 10.0f, 200.0f, lin, 16.0f);
ok("channel 1 starts at its own target", near(v, 10.0f));
v = reaktor_animate(id, 0, 0.0f, 200.0f, REAKTOR_EASE_LINEAR);
ok("and channel 0 is where it was left", near(v, 0.25f));
reaktor_anim_frame(a, 0.0f);
v = reaktor_animate(id, 0, 0.0f, 200.0f, lin);
ok("and channel 0 is still on its way", v > 0.0f && v < 0.25f);
puts("");
puts("a long gap between frames does not teleport a run");
{
float start = reaktor_animate(id, 0, 1.0f, 1000.0f,
REAKTOR_EASE_LINEAR);
float start = frame(a, id, 0, 1.0f, 1000.0f, lin, 16.0f);
reaktor_anim_tick(5000.0f);
v = reaktor_animate(id, 0, 1.0f, 1000.0f, REAKTOR_EASE_LINEAR);
v = frame(a, id, 0, 1.0f, 1000.0f, lin, 5000.0f);
ok("five seconds of sleep move it forward", v > start);
ok("...by one capped step, not by all five seconds",
v - start < 0.10f);
ok("and the run is still going", advance(16.0f) == 1);
ok("it does finish, given the frames", advance(1000.0f) == 0);
v = reaktor_animate(id, 0, 1.0f, 1000.0f, REAKTOR_EASE_LINEAR);
ok("...by one capped step, not by all five seconds", v - start < 0.10f);
ok("and the run is still going", g_moving);
for (n = 0; g_moving && n < 200; n++)
v = frame(a, id, 0, 1.0f, 1000.0f, lin, 16.0f);
ok("it does finish, given the frames", !g_moving && n < 200);
ok("exactly where it was sent", near(v, 1.0f));
}
puts("");
puts("a settled value holds still when only its curve changes");
v = frame(a, id, 0, 1.0f, 300.0f, REAKTOR_EASE_BOUNCE_OUT, 16.0f);
ok("it stays where it is", near(v, 1.0f) && !g_moving);
ok("with no dot running on its curve", reaktor_anim_progress(id, 0) < 0.0f);
frame(a, id, 0, 0.0f, 300.0f, REAKTOR_EASE_BOUNCE_OUT, 0.0f);
v = frames(a, id, 0, 0.0f, 300.0f, REAKTOR_EASE_BOUNCE_OUT, 150.0f);
ok("and the next run takes the new curve",
near(v, 1.0f - reaktor_ease_at(REAKTOR_EASE_BOUNCE_OUT, 0.5f)));
puts("");
puts("each window has a table of its own");
{
struct nka_context *b = reaktor_anim_create();
v = frame(b, id, 0, 42.0f, 200.0f, lin, 16.0f);
ok("the same id starts afresh in another", near(v, 42.0f));
v = frame(a, id, 0, 0.0f, 300.0f, REAKTOR_EASE_BOUNCE_OUT, 0.0f);
ok("and the first one is left as it was", v > 0.0f && v < 1.0f);
reaktor_anim_destroy(b);
}
reaktor_anim_destroy(a);
ok("a destroyed table leaves reaktor_animate answering its target",
near(reaktor_animate(id, 0, 3.0f, 200.0f, lin), 3.0f));
}
int
+18
View File
@@ -57,6 +57,15 @@ const int reaktor_locale_catalog_count =
static int failures;
/* locale_runtime.c asks SDL; the test answers for it. */
static const char *g_system_code = "en";
const char *
reaktor_locale_system_code(void)
{
return g_system_code;
}
static void
check(const char *what, long got, long want)
{
@@ -220,8 +229,17 @@ catalogs(void)
check("codepoints include the kanji in the language name", has_ni, 1);
check("codepoints leave out Latin-1", has_o, 0);
g_system_code = "pl";
check("NULL follows the system", reaktor_locale_set(NULL), 1);
check_str("to the system's language", reaktor_locale_current(), "pl");
check("and says it follows", reaktor_locale_system(), 1);
check("a code stops following",
reaktor_locale_set("ja") && !reaktor_locale_system(), 1);
reaktor_locale_set(NULL);
check("init again reloads cleanly", reaktor_locale_init(), 3);
check_str("and forgets the current catalog", reaktor_locale_current(), "");
check("and stops following", reaktor_locale_system(), 0);
}
static void
-2
View File
@@ -23,8 +23,6 @@
display: block;
outline: none;
border-radius: 10px 10px 0 0;
transform: translate3d(0, 0, 0);
image-rendering: pixelated;
image-rendering: crisp-edges;