30 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
admin 84e45229ea Merge pull request #19 from Alpaq92/libreaktor
libreaktor, and a public API to build against
2026-10-05 16:52:00 +02:00
adminandClaude Opus 5.5 b748fd9984 Merge master: a build with nothing to do does nothing
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 15:51:40 +02:00
adminandClaude Opus 5.5 965ee181b5 libreaktor finds what SDL found
On NetBSD SDL links X11 and Wayland through targets it imports in its
own directory, where Reaktor's directory cannot see them, so their names
reached the package unresolved and CMake refused it. A Namespace::
target found in another directory is now found again here with
find_package, from the same cache; a PkgConfig:: one is read from the
variables pkg_check_modules caches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 15:51:38 +02:00
admin 1f67384eba Merge pull request #20 from Alpaq92/a-build-with-nothing-to-do
A build with nothing to do does nothing
2026-10-05 15:51:19 +02:00
adminandClaude Opus 5.5 4f9f322a33 A build with nothing to do does nothing
build.ps1 configures before every build, and the configure rewrote gen/lcui/config.h and gen/reaktor.rc each time, so a build with nothing changed recompiled all 64 lcui objects and style.c, rebuilt four resource files and relinked every program. Both are now written only when their text changes, as reaktor_builtins.c already was.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 15:40:26 +02:00
adminandClaude Opus 5.5 6d009d1ad5 The scrollbar keeps its distance
The showcase popped its page padding right after nk_group_begin, so
nk_group_end placed the vertical scrollbar with Nuklear's 4 px default:
the bar sat 4 px from the content and 16 px from the card's edge. The
end call now sees the page's metrics again, with half the padding, which
centers the bar in the gutter, 10 px from each.

It also sees the page's zero scrollbar height, so the Inputs page no
longer draws a horizontal bar across the card's foot. That bar showed
because two rows of combo boxes, 440 px each, were wider than the page;
they now share their rows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 15:17:10 +02:00
adminandClaude Opus 5.5 468c6e2d1c libreaktor reads what its parts link
NetBSD's consumer failed to link: SDL links X11 and Wayland there
instead of loading them, and the package listed only what the other
systems need. The list was also a copy of SDL's, which the house rules
forbid. CMake now walks the link interfaces of everything merged into
the archive and keeps what is left outside it: system libraries,
frameworks and linker flags. A shared library found on the build machine
goes in by name, with its directory when the compiler would not search
it, so a package built on one distribution links on another.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 15:14:39 +02:00
adminandClaude Opus 5.5 e6c0b85601 libreaktor, and a public API to build against
Applications now include reaktor/reaktor.h and nothing else of
Reaktor's: include/reaktor holds every type and call a program uses,
App is opaque, and the internal headers include the public ones instead
of declaring the same things again. The samples prove it: each builds
from the public headers alone, MSVC refuses an implicit declaration in
any app, and the showcase draws every page as before. Where they reached
into App there are calls now: the SDL window and renderer, the theme,
the borderless titlebar, focus areas, SVG icons, and the frame and
process timings.

The libreaktor target merges Reaktor, its modules and every dependency
into one static archive, and the libreaktor install component lays it
out with the public headers, Nuklear's and SDL's, a CMake package
(find_package(reaktor), reaktor::reaktor), a pkg-config file and the
licenses. Added with add_subdirectory, Reaktor builds no samples or
tests and installs nothing unless asked. examples/consumer builds Simple
against an installed package.

Every workflow builds, installs and links libreaktor and checks that the
consumer's Simple draws exactly what the tree's does. Releases gain a
libreaktor archive for every system and architecture, and SHA256SUMS.
The version is 0.2.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 14:46:41 +02:00
admin 68f16bb0e4 Merge pull request #18 from Alpaq92/downloads-for-the-bsds-and-the-web
Downloads for the BSDs and the web
2026-10-05 11:33:14 +02:00
adminandClaude Opus 5.5 5f08f33872 The pitch before the links
The README now says why Reaktor exists before it offers the showcase in the browser or a download.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 11:05:45 +02:00
adminandClaude Opus 5.5 36f3c4fdc5 Downloads for the BSDs and the web
The BSD workflow now packs what it builds, as the other three do: each
VM packs its build with tools/package.sh, runs the packed showcase under
the dummy driver, checks it draws its Translations page as the built one
does, and hands the archive back with its shots. FreeBSD 15.1, OpenBSD
7.9 and NetBSD 11.0 each get one for x86-64 and ARM64.

web.yml builds the WebAssembly programs on every pull request and packs
the showcase, Notepad and Simple with their licenses, ready for any HTTP
server. release.yml calls both, every job required, and the release notes
and the README name the new downloads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 11:04:35 +02:00
65 changed files with 2947 additions and 1152 deletions
+74 -2
View File
@@ -5,12 +5,20 @@ on:
branches: [master]
pull_request:
workflow_dispatch:
workflow_call:
inputs:
version:
type: string
default: ''
strict:
type: boolean
default: false
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
group: bsd-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
@@ -18,7 +26,7 @@ jobs:
name: ${{ matrix.os }} ${{ matrix.version }} ${{ matrix.arch }}
runs-on: ubuntu-latest
timeout-minutes: ${{ matrix.timeout }}
continue-on-error: ${{ matrix.arch == 'arm64' }}
continue-on-error: ${{ matrix.arch == 'arm64' && !inputs.strict }}
strategy:
fail-fast: false
matrix:
@@ -151,6 +159,52 @@ jobs:
export PATH
cmake --build build --target mkicon </dev/null
- name: Package
id: package
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
run: |
PATH=/usr/pkg/sbin:/usr/pkg/bin:/usr/local/sbin:/usr/local/bin:$PATH
export PATH
version='${{ inputs.version || 'dev' }}'
name="reaktor-${version#v}-${{ matrix.os }}-${{ matrix.arch }}"
sh tools/package.sh build "dist/$name"
mkdir -p check
for from in "built build" "packed dist/$name"; do
set -- $from
dbus-run-session -- "$2/showcase" --tab 8 --theme light --video dummy \
--shot "check/$1.bmp" --a11y-dump "check/$1.txt" </dev/null
done
for e in bmp txt; do
cmp "check/built.$e" "check/packed.$e"
done
tar -C dist -czf "dist/$name.tar.gz" "$name"
rm -rf "dist/$name"
- name: Check and pack libreaktor
id: libcheck
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
run: |
PATH=/usr/pkg/sbin:/usr/pkg/bin:/usr/local/sbin:/usr/local/bin:$PATH
export PATH
version='${{ inputs.version || 'dev' }}'
name="libreaktor-${version#v}-${{ matrix.os }}-${{ matrix.arch }}"
cmake --build build --target libreaktor </dev/null
cmake --install build --prefix "dist/$name" --component libreaktor </dev/null
cmake -S examples/consumer -B build-consumer -G Ninja -DCMAKE_BUILD_TYPE=Release \
"-DCMAKE_PREFIX_PATH=$PWD/dist/$name" </dev/null
cmake --build build-consumer </dev/null
mkdir -p check
for from in "lib-built build/simple" "lib-linked build-consumer/simple"; do
set -- $from
dbus-run-session -- "$2" --theme light --video dummy \
--shot "check/$1.bmp" --a11y-dump "check/$1.txt" </dev/null
done
for e in bmp txt; do
cmp "check/lib-built.$e" "check/lib-linked.$e"
done
tar -C dist -czf "dist/$name.tar.gz" "$name"
rm -rf "dist/$name" build-consumer
- name: Collect the shots
if: ${{ always() && steps.vm.outcome == 'success' }}
shell: cpa.sh {0} --sync-files vm-to-runner
@@ -161,6 +215,24 @@ jobs:
done
rm -rf build
- name: Upload the package
if: ${{ !cancelled() && steps.package.outcome == 'success' }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: package-${{ matrix.os }}-${{ matrix.arch }}
path: dist/reaktor-*.tar.gz
if-no-files-found: error
retention-days: 14
- name: Upload libreaktor
if: ${{ !cancelled() && steps.libcheck.outcome == 'success' }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: package-libreaktor-${{ matrix.os }}-${{ matrix.arch }}
path: dist/libreaktor-*.tar.gz
if-no-files-found: error
retention-days: 14
- name: Upload the shots
if: ${{ always() && steps.vm.outcome == 'success' }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
+34 -1
View File
@@ -163,7 +163,40 @@ jobs:
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: package-linux-${{ matrix.arch }}
path: dist/*.tar.gz
path: dist/reaktor-*.tar.gz
if-no-files-found: error
retention-days: 14
- name: Check and pack libreaktor
id: libcheck
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
run: |
version='${{ inputs.version || 'dev' }}'
name="libreaktor-${version#v}-linux-${{ matrix.arch }}"
docker exec -i -e name="$name" debian sh -eu <<'EOF'
cmake --build build --target libreaktor </dev/null
cmake --install build --prefix "dist/$name" --component libreaktor </dev/null
cmake -S examples/consumer -B build-consumer -G Ninja -DCMAKE_BUILD_TYPE=Release \
"-DCMAKE_PREFIX_PATH=$PWD/dist/$name" </dev/null
cmake --build build-consumer </dev/null
mkdir -p check
for from in "lib-built build/simple" "lib-linked build-consumer/simple"; do
set -- $from
timeout 600 "$2" --theme light --video dummy \
--shot "check/$1.bmp" --a11y-dump "check/$1.txt" </dev/null
done
for e in bmp txt; do
cmp "check/lib-built.$e" "check/lib-linked.$e"
done
tar -C dist -czf "dist/$name.tar.gz" "$name"
EOF
- name: Upload libreaktor
if: ${{ !cancelled() && steps.libcheck.outcome == 'success' }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: package-libreaktor-linux-${{ matrix.arch }}
path: dist/libreaktor-*.tar.gz
if-no-files-found: error
retention-days: 14
+32 -1
View File
@@ -126,7 +126,38 @@ jobs:
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: package-macos-${{ matrix.arch }}
path: dist/*.zip
path: dist/reaktor-*.zip
if-no-files-found: error
retention-days: 14
- name: Check and zip libreaktor
id: libcheck
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
run: |
version='${{ inputs.version || 'dev' }}'
name="libreaktor-${version#v}-macos-${{ matrix.arch }}"
cmake --build build --target libreaktor </dev/null
cmake --install build --prefix "dist/$name" --component libreaktor </dev/null
cmake -S examples/consumer -B build-consumer -G Ninja -DCMAKE_BUILD_TYPE=Release \
"-DCMAKE_PREFIX_PATH=$PWD/dist/$name" </dev/null
cmake --build build-consumer </dev/null
mkdir -p check
for from in "lib-built build/simple" "lib-linked build-consumer/simple"; do
set -- $from
"$2" --theme light --video dummy \
--shot "check/$1.bmp" --a11y-dump "check/$1.txt" </dev/null
done
for e in bmp txt; do
cmp "check/lib-built.$e" "check/lib-linked.$e"
done
ditto -c -k --keepParent "dist/$name" "dist/$name.zip"
- name: Upload libreaktor
if: ${{ !cancelled() && steps.libcheck.outcome == 'success' }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: package-libreaktor-macos-${{ matrix.arch }}
path: dist/libreaktor-*.zip
if-no-files-found: error
retention-days: 14
+62 -7
View File
@@ -24,6 +24,17 @@ jobs:
version: ${{ github.ref_name }}
strict: true
bsd:
uses: ./.github/workflows/bsd.yml
with:
version: ${{ github.ref_name }}
strict: true
web:
uses: ./.github/workflows/web.yml
with:
version: ${{ github.ref_name }}
source:
runs-on: ubuntu-24.04
steps:
@@ -33,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"
@@ -47,7 +71,7 @@ jobs:
retention-days: 14
publish:
needs: [windows, macos, linux, source]
needs: [windows, macos, linux, bsd, web, source]
runs-on: ubuntu-24.04
permissions:
contents: write
@@ -70,11 +94,16 @@ jobs:
| Windows | x64, x86, ARM64 | \`reaktor-$v-windows-<arch>.zip\` |
| macOS | Apple silicon (arm64), Intel (x86_64) | \`reaktor-$v-macos-<arch>.zip\` |
| Linux | x86-64, x86, ARM64, ARMv7 (armhf), RISC-V 64 | \`reaktor-$v-linux-<arch>.tar.gz\` |
| FreeBSD 15.1 | x86-64, ARM64 | \`reaktor-$v-freebsd-<arch>.tar.gz\` |
| OpenBSD 7.9 | x86-64, ARM64 | \`reaktor-$v-openbsd-<arch>.tar.gz\` |
| NetBSD 11.0 | x86-64, ARM64 | \`reaktor-$v-netbsd-<arch>.tar.gz\` |
| Web | WebAssembly | \`reaktor-$v-web.zip\` |
| Source | every submodule included | \`reaktor-$v-source.tar.gz\` |
Each package holds the showcase, Notepad, Simple and the bench, the files
they read at runtime, and every license (\`licenses/\`, \`NOTICE.md\`).
Unpack it anywhere and run \`showcase\`; it finds its files beside itself.
Each native package holds the showcase, Notepad, Simple and the bench,
the files they read at runtime, and every license (\`licenses/\`,
\`NOTICE.md\`). Unpack it anywhere and run \`showcase\`; it finds its files
beside itself.
- **Windows**: the C runtime is linked in, so there is nothing to install.
The programs are not signed, and SmartScreen may ask before the first run.
@@ -82,11 +111,37 @@ jobs:
notarized: open it from its context menu the first time.
- **Linux**: glibc 2.36 or newer (2.41 for RISC-V), libdbus-1, and X11 or
Wayland.
- **Web**: the same showcase runs at https://alpaq92.github.io/Reaktor/.
- **BSDs**: the release named above, the dbus package, and X11.
- **Web**: the showcase, Notepad and Simple as \`.html\`, \`.js\`, \`.wasm\`
and \`.data\`. Serve the folder over HTTP (a \`file://\` page cannot fetch
the \`.wasm\`) and open \`showcase.html\`; the same showcase runs at
https://alpaq92.github.io/Reaktor/.
GitHub's own source archives below leave the submodules out; the
\`-source.tar.gz\` above has them.
### libreaktor
The library itself, for building your own applications: the same
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, 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 ${v%.*} REQUIRED) # with CMAKE_PREFIX_PATH at the unpacked folder
add_executable(app WIN32 main.c)
target_link_libraries(app PRIVATE reaktor::reaktor)
\`\`\`
or \`cc main.c \$(pkg-config --cflags --libs reaktor)\` with
\`PKG_CONFIG_PATH\` at its \`lib/pkgconfig\`.
\`SHA256SUMS\` lists every download's checksum. GitHub's own source
archives below leave the submodules out; the \`-source.tar.gz\` above has
them.
EOF
(cd dist && sha256sum -- * >SHA256SUMS)
gh release create "$GITHUB_REF_NAME" dist/* --repo "$GITHUB_REPOSITORY" \
--title "Reaktor $GITHUB_REF_NAME" --notes-file notes.md --generate-notes \
--verify-tag
+90
View File
@@ -0,0 +1,90 @@
name: Web
on:
push:
branches: [master]
pull_request:
workflow_dispatch:
workflow_call:
inputs:
version:
type: string
default: ''
permissions:
contents: read
concurrency:
group: web-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
web:
name: web
runs-on: ubuntu-24.04
timeout-minutes: 60
env:
EMSCRIPTEN_VERSION: 6.0.9
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
submodules: recursive
persist-credentials: false
- name: Install emsdk
run: |
git clone --depth 1 https://github.com/emscripten-core/emsdk.git "$HOME/emsdk"
"$HOME/emsdk/emsdk" install "$EMSCRIPTEN_VERSION"
"$HOME/emsdk/emsdk" activate "$EMSCRIPTEN_VERSION"
sudo apt-get update && sudo apt-get install -y ninja-build
- name: Build
run: EMSDK="$HOME/emsdk" ./build-wasm.sh
- name: Package
run: |
version='${{ inputs.version || 'dev' }}'
name="reaktor-${version#v}-web"
mkdir -p "dist/$name/licenses"
for p in showcase notepad simple; do
cp "build-wasm/$p.html" "build-wasm/$p.js" "build-wasm/$p.wasm" \
"build-wasm/$p.data" "dist/$name/"
done
cp build-wasm/keylog.js build-wasm/reaktor-icon.svg build-wasm/reaktor-icon.png \
"dist/$name/"
cp build-wasm/licenses/*.txt "dist/$name/licenses/"
cp external/simplecss/LICENSE "dist/$name/licenses/simplecss.txt"
cp assets/fonts/Aileron-Notice.txt assets/fonts/MPLUS1p-Notice.txt \
"dist/$name/licenses/"
cp docs/NOTICE.md "dist/$name/"
(cd dist && zip -qr "$name.zip" "$name")
- name: Upload the package
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: package-web
path: dist/reaktor-*.zip
if-no-files-found: error
retention-days: 14
- name: Check and pack libreaktor
run: |
version='${{ inputs.version || 'dev' }}'
name="libreaktor-${version#v}-wasm"
cmake --build build-wasm --target libreaktor
cmake --install build-wasm --prefix "dist/$name" --component libreaktor
cmake -S examples/consumer -B build-consumer -G Ninja -DCMAKE_BUILD_TYPE=Release \
"-DCMAKE_TOOLCHAIN_FILE=$HOME/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake" \
"-Dreaktor_DIR=$PWD/dist/$name/lib/cmake/reaktor"
cmake --build build-consumer
test -s build-consumer/simple.wasm
tar -C dist -czf "dist/$name.tar.gz" "$name"
- name: Upload libreaktor
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: package-libreaktor-wasm
path: dist/libreaktor-*.tar.gz
if-no-files-found: error
retention-days: 14
+42 -1
View File
@@ -122,7 +122,48 @@ jobs:
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: package-windows-${{ matrix.arch }}
path: dist/*.zip
path: dist/reaktor-*.zip
if-no-files-found: error
retention-days: 14
- name: Build libreaktor
id: lib
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
run: ./build.ps1 -Arch ${{ matrix.arch }} -Out build-lib libreaktor
- name: Check and zip libreaktor
id: libcheck
if: ${{ !cancelled() && steps.lib.outcome == 'success' }}
run: |
$version = '${{ inputs.version || 'dev' }}' -replace '^v', ''
$name = "libreaktor-$version-windows-${{ matrix.arch }}"
cmake --install build-lib --prefix "dist/$name" --component libreaktor
if ($LASTEXITCODE -ne 0) { throw "install failed" }
./build.ps1 -Arch ${{ matrix.arch }} -Source examples/consumer -Out build-consumer `
"-DCMAKE_PREFIX_PATH=$PWD/dist/$name"
New-Item -ItemType Directory -Force check | Out-Null
foreach ($from in @(@('lib-built', "${{ matrix.out }}/simple.exe"),
@('lib-linked', 'build-consumer/simple.exe'))) {
$p = Start-Process -FilePath $from[1] -PassThru -ArgumentList @(
'--theme', 'light', '--video', 'dummy',
'--shot', "check/$($from[0]).bmp", '--a11y-dump', "check/$($from[0]).txt")
$null = $p.Handle
if (-not $p.WaitForExit(600000)) { $p.Kill(); throw "$($from[0]): timed out" }
if ($p.ExitCode -ne 0) { throw "$($from[0]): exit status $($p.ExitCode)" }
}
foreach ($e in 'bmp', 'txt') {
if ((Get-FileHash "check/lib-built.$e").Hash -ne (Get-FileHash "check/lib-linked.$e").Hash) {
throw "simple linked against libreaktor draws differently ($e)"
}
}
Compress-Archive -Path "dist/$name" -DestinationPath "dist/$name.zip"
- name: Upload libreaktor
if: ${{ !cancelled() && steps.libcheck.outcome == 'success' }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: package-libreaktor-windows-${{ matrix.arch }}
path: dist/libreaktor-*.zip
if-no-files-found: error
retention-days: 14
+2
View File
@@ -9,6 +9,8 @@ build-wasm/
build-x64/
build-x86/
build-arm64/
build-lib/
build-consumer/
.claude/settings.local.json
.dart_tool/
.gradle/
+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
+4
View File
@@ -113,6 +113,10 @@ regression oracle for every layout or style change.
toast's close cross) are compiled in byte for byte, beside the Aileron
fonts, the mark and reaktor.css. Nothing else from a submodule is — not the
rest of Ionicons, not simple.css.
- Applications see only `include/reaktor/`. The samples include
`reaktor/reaktor.h` and `reaktor/main.h`, nothing from `src/` or `core/`, and
`App` is opaque to them; what a sample needs becomes a public call there.
MSVC builds apps with implicit declarations as errors, which catches a miss.
- American English, in code and prose.
- No environment variables. Anything worth overriding is a command-line flag
the runtime strips from `argv`.
+291 -18
View File
@@ -1,10 +1,18 @@
cmake_minimum_required(VERSION 3.16)
project(reaktor C CXX)
project(reaktor VERSION 0.3.0 LANGUAGES C CXX)
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(_reaktor_top ON)
else()
set(_reaktor_top OFF)
endif()
option(REAKTOR_SAMPLES "Build the samples" ${_reaktor_top})
option(REAKTOR_TESTS "Build the tests" ${_reaktor_top})
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
if(_reaktor_top AND NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Release CACHE STRING "" FORCE)
endif()
@@ -79,7 +87,13 @@ foreach(_in "${LC}/yutil/include/yutil/config.h.in"
lcui_expand("${_in}" _part)
string(APPEND LCUI_MERGED "\n${_part}")
endforeach()
file(WRITE "${LCUI_CFG}/config.h" "${LCUI_MERGED}")
set(_old "")
if(EXISTS "${LCUI_CFG}/config.h")
file(READ "${LCUI_CFG}/config.h" _old)
endif()
if(NOT _old STREQUAL LCUI_MERGED)
file(WRITE "${LCUI_CFG}/config.h" "${LCUI_MERGED}")
endif()
if(UNIX AND NOT EMSCRIPTEN)
find_library(REAKTOR_LIBM m)
@@ -116,7 +130,7 @@ add_library(onlay STATIC ${TP}/onlay/onlay.c)
target_include_directories(onlay PUBLIC ${TP}/onlay)
target_compile_definitions(onlay PUBLIC LAY_FLOAT=1)
if(NOT EMSCRIPTEN)
if(REAKTOR_TESTS AND NOT EMSCRIPTEN)
add_executable(onlaytest ${TP}/onlay/test_onlay.c)
target_link_libraries(onlaytest PRIVATE onlay)
set_target_properties(onlaytest PROPERTIES
@@ -167,12 +181,15 @@ if(NOT _old STREQUAL _gen)
endif()
message(STATUS "assets: ${_n} compiled in")
add_library(reaktor_headers INTERFACE)
target_include_directories(reaktor_headers INTERFACE include "${TP}/nuklear" "${TP}/nukanim")
add_library(reaktor_core STATIC
core/base/util.c
core/render/appicon.c
"${_builtins}")
target_include_directories(reaktor_core PUBLIC core/base core/render)
target_link_libraries(reaktor_core PUBLIC plutosvg)
target_link_libraries(reaktor_core PUBLIC plutosvg reaktor_headers)
set(APP_ICON assets/icons/reaktor-icon.ico)
set(APP_RESOURCES "")
@@ -182,38 +199,42 @@ target_link_libraries(mkicon PRIVATE reaktor_core)
set_target_properties(mkicon PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
if(NOT EMSCRIPTEN)
if(REAKTOR_TESTS AND NOT EMSCRIPTEN)
add_executable(keytest tools/keytest.c core/ui/keys.c)
target_link_libraries(keytest PRIVATE reaktor_headers)
target_include_directories(keytest PRIVATE core/ui)
target_link_libraries(keytest PRIVATE SDL3::SDL3-static)
set_target_properties(keytest PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
endif()
if(NOT EMSCRIPTEN)
if(REAKTOR_TESTS AND NOT EMSCRIPTEN)
add_executable(a11ytest tools/a11ytest.c core/a11y/a11y.c)
target_link_libraries(a11ytest PRIVATE reaktor_headers)
target_include_directories(a11ytest PRIVATE core/a11y core/render)
set_target_properties(a11ytest PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
endif()
if(NOT EMSCRIPTEN)
add_executable(animtest tools/animtest.c core/anim/anim.c)
target_include_directories(animtest PRIVATE core/anim core/a11y core/render
platform)
target_link_libraries(animtest PRIVATE SDL3::SDL3)
if(REAKTOR_TESTS AND NOT EMSCRIPTEN)
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}")
add_executable(localetest tools/localetest.c
core/locale/locale.c core/locale/plural.c
core/locale/format.c)
target_link_libraries(localetest PRIVATE reaktor_headers)
target_include_directories(localetest PRIVATE core/locale)
target_compile_definitions(localetest PRIVATE REAKTOR_LOCALE_EMBEDDED)
set_target_properties(localetest PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
add_executable(laytest tools/laytest.c core/ui/layout.c)
target_link_libraries(laytest PRIVATE reaktor_headers)
target_include_directories(laytest PRIVATE core/ui core/render)
target_link_libraries(laytest PRIVATE onlay)
set_target_properties(laytest PROPERTIES
@@ -229,8 +250,14 @@ if(WIN32)
file(MAKE_DIRECTORY "${GEN}")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${APP_ICON}"
"${GEN}/reaktor.ico" COPYONLY)
file(WRITE "${GEN}/reaktor.rc" "1 ICON \"reaktor.ico\"
")
set(_rc "1 ICON \"reaktor.ico\"\n")
set(_old "")
if(EXISTS "${GEN}/reaktor.rc")
file(READ "${GEN}/reaktor.rc" _old)
endif()
if(NOT _old STREQUAL _rc)
file(WRITE "${GEN}/reaktor.rc" "${_rc}")
endif()
set(APP_RESOURCES "${GEN}/reaktor.rc")
elseif(UNIX AND NOT APPLE AND NOT EMSCRIPTEN)
file(WRITE "${CMAKE_BINARY_DIR}/reaktor.desktop"
@@ -375,8 +402,9 @@ else()
target_link_libraries(reaktor_text INTERFACE Mojibake::mojibake kb_text_shape)
message(STATUS "text: shaping by kb_text_shape; direction and line breaking by mojibake")
if(NOT EMSCRIPTEN)
if(REAKTOR_TESTS AND NOT EMSCRIPTEN)
add_executable(texttest tools/texttest.c core/render/nk_impl.c)
target_link_libraries(texttest PRIVATE reaktor_headers)
target_include_directories(texttest PRIVATE core/render core/text)
target_link_libraries(texttest PRIVATE reaktor_text reaktor_core
SDL3::SDL3-static)
@@ -442,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}"
@@ -475,6 +503,9 @@ function(reaktor_add_app name)
endif()
endforeach()
target_link_libraries(${name} PRIVATE reaktor_runtime ${_mods})
if(MSVC)
target_compile_options(${name} PRIVATE /we4013)
endif()
set_target_properties(${name} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
if(EMSCRIPTEN)
@@ -510,6 +541,7 @@ function(reaktor_add_app name)
endif()
endfunction()
if(REAKTOR_SAMPLES)
reaktor_add_app(showcase SOURCES
samples/showcase/shell.c
samples/showcase/shortcuts.c
@@ -632,9 +664,7 @@ endif()
if(MSVC)
target_compile_options(showcase PRIVATE /wd5287 /wd4101)
target_compile_options(plutovg PRIVATE /wd4244 /wd4267 /wd4018)
target_compile_definitions(showcase PRIVATE _CRT_SECURE_NO_WARNINGS)
target_compile_definitions(reaktor_core PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()
if(APPLE AND NOT EMSCRIPTEN)
@@ -651,3 +681,246 @@ if(APPLE AND NOT EMSCRIPTEN)
COMMENT "Assembling reaktor.app"
VERBATIM)
endif()
endif()
if(MSVC)
target_compile_options(plutovg PRIVATE /wd4244 /wd4267 /wd4018)
target_compile_definitions(reaktor_core PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()
add_library(reaktor_modules STATIC)
target_link_libraries(reaktor_modules PRIVATE reaktor_runtime reaktor_a11y reaktor_locale reaktor_text)
set_target_properties(reaktor_modules PROPERTIES EXCLUDE_FROM_ALL ON)
set(_parts reaktor_runtime reaktor_core reaktor_modules plutosvg plutovg lcui onlay SDL3-static)
foreach(_t mojibake_lib kb_text_shape)
if(TARGET ${_t})
list(APPEND _parts ${_t})
endif()
endforeach()
set(_files "")
foreach(_t IN LISTS _parts)
list(APPEND _files "$<TARGET_FILE:${_t}>")
endforeach()
# What a program links beside libreaktor: whatever its parts link that is not merged in.
function(reaktor_outside_links)
set(_libs "")
set(_dirs "")
set(_opts "")
set(_weak "")
set(_seen "")
set(_refound "")
set(_todo ${ARGN})
while(_todo)
list(POP_FRONT _todo _t)
get_target_property(_real ${_t} ALIASED_TARGET)
if(_real)
set(_t ${_real})
endif()
if(_t IN_LIST _seen)
continue()
endif()
list(APPEND _seen ${_t})
get_target_property(_type ${_t} TYPE)
get_target_property(_imported ${_t} IMPORTED)
set(_items "")
if(_imported AND NOT _type STREQUAL "INTERFACE_LIBRARY")
set(_props IMPORTED_IMPLIB_RELEASE IMPORTED_IMPLIB IMPORTED_LOCATION_RELEASE
IMPORTED_LOCATION)
get_target_property(_cfgs ${_t} IMPORTED_CONFIGURATIONS)
if(_cfgs)
foreach(_c IN LISTS _cfgs)
list(APPEND _props IMPORTED_IMPLIB_${_c} IMPORTED_LOCATION_${_c})
endforeach()
endif()
set(_file "")
foreach(_p IN LISTS _props)
get_target_property(_f ${_t} ${_p})
if(_f)
set(_file "${_f}")
break()
endif()
endforeach()
if(_file)
list(APPEND _libs "${_file}")
else()
message(WARNING "libreaktor finds no file for ${_t}, which its parts link")
endif()
elseif(_t IN_LIST ARGN)
get_target_property(_v ${_t} LINK_LIBRARIES)
if(_v)
list(APPEND _items ${_v})
endif()
elseif(NOT _type MATCHES "^(INTERFACE|OBJECT)_LIBRARY$")
message(WARNING "libreaktor leaves out ${_t}, which its parts link")
endif()
foreach(_p INTERFACE_LINK_LIBRARIES INTERFACE_LINK_OPTIONS INTERFACE_LINK_DIRECTORIES)
get_target_property(_v ${_t} ${_p})
if(NOT _v)
continue()
endif()
if(_p STREQUAL "INTERFACE_LINK_LIBRARIES")
list(APPEND _items ${_v})
elseif(_v MATCHES "\\$<")
message(WARNING "libreaktor cannot carry ${_t}'s ${_p}: ${_v}")
elseif(_p STREQUAL "INTERFACE_LINK_OPTIONS")
list(APPEND _opts ${_v})
else()
list(APPEND _dirs ${_v})
endif()
endforeach()
foreach(_i IN LISTS _items)
if(_i MATCHES "^\\$<LINK_ONLY:(.*)>$")
set(_i "${CMAKE_MATCH_1}")
endif()
if(_i MATCHES "^\\$<(TARGET_NAME|BUILD_INTERFACE):(.*)>$")
set(_i "${CMAKE_MATCH_2}")
endif()
if(_i MATCHES "^\\$<INSTALL_INTERFACE:")
continue()
endif()
# A dependency's own directory may have found it: its targets are not seen here.
if(NOT TARGET "${_i}" AND _i MATCHES "^([A-Za-z0-9_]+)::")
set(_pkg "${CMAKE_MATCH_1}")
if(NOT _pkg STREQUAL "PkgConfig" AND NOT _pkg IN_LIST _refound)
list(APPEND _refound ${_pkg})
find_package(${_pkg} QUIET)
endif()
endif()
if(TARGET "${_i}")
list(APPEND _todo "${_i}")
elseif(_i MATCHES "^PkgConfig::(.+)$")
set(_pc_prefix "${CMAKE_MATCH_1}")
list(APPEND _libs ${${_pc_prefix}_LIBRARIES})
list(APPEND _dirs ${${_pc_prefix}_LIBRARY_DIRS})
list(APPEND _opts ${${_pc_prefix}_LDFLAGS_OTHER})
elseif(_i MATCHES "::")
message(WARNING "libreaktor cannot find ${_i}, which ${_t} links")
elseif(_i MATCHES "^\\$<LINK_LIBRARY:FRAMEWORK,(.*)>$")
list(APPEND _libs "-framework ${CMAKE_MATCH_1}")
elseif(_i MATCHES "^\\$<LINK_LIBRARY:WEAK_FRAMEWORK,(.*)>$")
list(APPEND _weak "${CMAKE_MATCH_1}")
elseif(_i MATCHES "\\$<")
message(WARNING "libreaktor cannot carry ${_t}'s link to ${_i}")
elseif(_i)
list(APPEND _libs "${_i}")
endif()
endforeach()
endwhile()
# A shared library found on this machine is named, so the package finds it on another.
set(_named "")
foreach(_l IN LISTS _libs)
if(IS_ABSOLUTE "${_l}" AND _l MATCHES "/lib([^/]+)\\.(so|dylib|tbd)(\\.[0-9.]+)?$")
list(APPEND _named "${CMAKE_MATCH_1}")
get_filename_component(_d "${_l}" DIRECTORY)
string(FIND "${_d}" "${CMAKE_OSX_SYSROOT}" _in_sdk)
if(NOT (CMAKE_OSX_SYSROOT AND _in_sdk EQUAL 0))
list(APPEND _dirs "${_d}")
endif()
else()
list(APPEND _named "${_l}")
endif()
endforeach()
list(REMOVE_DUPLICATES _named)
list(REMOVE_DUPLICATES _dirs)
foreach(_d IN LISTS CMAKE_C_IMPLICIT_LINK_DIRECTORIES CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES)
list(REMOVE_ITEM _dirs "${_d}")
endforeach()
list(REMOVE_DUPLICATES _opts)
list(REMOVE_DUPLICATES _weak)
set(_pc "")
foreach(_d IN LISTS _dirs)
string(APPEND _pc " -L${_d} -Wl,-rpath,${_d}")
endforeach()
foreach(_l IN LISTS _named)
if(_l MATCHES "^-" OR IS_ABSOLUTE "${_l}")
string(APPEND _pc " ${_l}")
else()
string(APPEND _pc " -l${_l}")
endif()
endforeach()
foreach(_w IN LISTS _weak)
list(APPEND _opts "SHELL:-Xlinker -weak_framework -Xlinker ${_w}")
endforeach()
foreach(_o IN LISTS _opts)
string(REGEX REPLACE "^SHELL:" "" _o "${_o}")
string(REGEX REPLACE "-Xlinker -weak_framework -Xlinker " "-Wl,-weak_framework," _o "${_o}")
string(APPEND _pc " ${_o}")
endforeach()
set(REAKTOR_LINK_LIBS "${_named}" PARENT_SCOPE)
set(REAKTOR_LINK_DIRS "${_dirs}" PARENT_SCOPE)
set(REAKTOR_OUTSIDE_OPTIONS "${_opts}" PARENT_SCOPE)
set(REAKTOR_PC_LIBS "${_pc}" PARENT_SCOPE)
endfunction()
reaktor_outside_links(${_parts})
set(REAKTOR_LINK_OPTIONS ${REAKTOR_OUTSIDE_OPTIONS})
if(EMSCRIPTEN)
set(_wasm -sALLOW_MEMORY_GROWTH=1 -sINITIAL_MEMORY=64MB -sSTACK_SIZE=4MB
-sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2 -sEXIT_RUNTIME=0)
list(APPEND REAKTOR_LINK_OPTIONS ${_wasm})
string(JOIN " " _wasm ${_wasm})
string(APPEND REAKTOR_PC_LIBS " ${_wasm}")
endif()
string(JOIN " " _beside ${REAKTOR_LINK_LIBS} ${REAKTOR_LINK_DIRS} ${REAKTOR_LINK_OPTIONS})
message(STATUS "libreaktor: a program links beside it ${_beside}")
if(MSVC)
set(REAKTOR_LIB_NAME reaktor.lib)
else()
set(REAKTOR_LIB_NAME libreaktor.a)
endif()
set(_lib "${CMAKE_BINARY_DIR}/lib/${REAKTOR_LIB_NAME}")
if(MSVC)
set(_merge "${CMAKE_AR}" /NOLOGO "/OUT:${_lib}" ${_files})
elseif(APPLE)
find_program(REAKTOR_LIBTOOL NAMES libtool PATHS /usr/bin NO_DEFAULT_PATH)
set(_merge "${REAKTOR_LIBTOOL}" -static -o "${_lib}" ${_files})
else()
set(_mri "CREATE ${_lib}\n")
foreach(_f IN LISTS _files)
string(APPEND _mri "ADDLIB ${_f}\n")
endforeach()
string(APPEND _mri "SAVE\nEND\n")
file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/reaktor.mri" CONTENT "${_mri}")
set(_merge "${CMAKE_COMMAND}" "-DAR=${CMAKE_AR}" "-DMRI=${CMAKE_BINARY_DIR}/reaktor.mri"
-P "${CMAKE_CURRENT_SOURCE_DIR}/tools/merge-lib.cmake")
endif()
add_custom_command(OUTPUT "${_lib}"
COMMAND "${CMAKE_COMMAND}" -E make_directory "${CMAKE_BINARY_DIR}/lib"
COMMAND "${CMAKE_COMMAND}" -E remove -f "${_lib}"
COMMAND ${_merge}
DEPENDS ${_parts}
COMMENT "Merging libreaktor"
VERBATIM)
add_custom_target(libreaktor DEPENDS "${_lib}")
option(REAKTOR_INSTALL "Install libreaktor's files" ${_reaktor_top})
if(REAKTOR_INSTALL)
include(CMakePackageConfigHelpers)
configure_file(tools/reaktorConfig.cmake.in "${CMAKE_BINARY_DIR}/reaktorConfig.cmake" @ONLY)
write_basic_package_version_file("${CMAKE_BINARY_DIR}/reaktorConfigVersion.cmake"
COMPATIBILITY SameMinorVersion)
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"
DESTINATION lib/cmake/reaktor COMPONENT libreaktor)
if(NOT MSVC)
configure_file(tools/reaktor.pc.in "${CMAKE_BINARY_DIR}/reaktor.pc" @ONLY)
install(FILES "${CMAKE_BINARY_DIR}/reaktor.pc" DESTINATION lib/pkgconfig
COMPONENT libreaktor)
endif()
install(DIRECTORY "${CMAKE_BINARY_DIR}/licenses/" DESTINATION share/reaktor/licenses
COMPONENT libreaktor)
install(FILES assets/fonts/Aileron-Notice.txt DESTINATION share/reaktor/licenses
COMPONENT libreaktor)
install(FILES docs/NOTICE.md DESTINATION share/reaktor COMPONENT libreaktor)
endif()
+19 -8
View File
@@ -6,17 +6,19 @@ A Nuklear-powered GUI library for C.
<img src="assets/screenshots/screenshot.png" alt="Two Reaktor showcase windows, the light scheme behind and the dark scheme in front: each has the sidebar of pages with its own scheme chosen at the foot, and the front one shows the Login page's card in a rounded panel">
</p>
**[Try the showcase in your browser](https://alpaq92.github.io/Reaktor/)** — the
same program, built to WebAssembly — or
**[download it](https://github.com/Alpaq92/Reaktor/releases/latest)** for
Windows, macOS or Linux.
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
**[download it](https://github.com/Alpaq92/Reaktor/releases/latest)** for
Windows, macOS, Linux, FreeBSD, OpenBSD or NetBSD, or as WebAssembly to serve
yourself.
> ⚠️ **Reaktor is in active development**, and breaking changes might occur.
@@ -41,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,
@@ -65,6 +70,11 @@ cd Reaktor
[emsdk](https://emscripten.org)) builds the web versions into `build-wasm/`, to
be served over HTTP.
To build your own application, add Reaktor with `add_subdirectory` and declare
it with `reaktor_add_app`, or take a `libreaktor` package from the
[releases](https://github.com/Alpaq92/Reaktor/releases/latest) and
`find_package(reaktor)`: [In your own project](docs/DOCUMENTATION.md#in-your-own-project).
## Usage
```c
@@ -93,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.
+6 -2
View File
@@ -1,4 +1,5 @@
param([string]$Target = "", [ValidateSet("", "x64", "x86", "arm64")][string]$Arch = "")
param([string]$Target = "", [ValidateSet("", "x64", "x86", "arm64")][string]$Arch = "",
[string]$Out = "", [string]$Source = "")
$extra = @($args)
if ($Target -like '-*') { $extra = @($Target) + $extra; $Target = "" }
@@ -11,6 +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 = $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" }
@@ -42,7 +45,7 @@ $bat = Join-Path $env:TEMP "reaktor_build_$PID.bat"
@(
'@echo off',
('call "' + $vcvars + '" ' + $vcarch + ' >nul 2>&1'),
('"' + $cmake + '" -S "' + $root + '" -B "' + $outDir + '" -G Ninja ' +
('"' + $cmake + '" -S "' + $srcDir + '" -B "' + $outDir + '" -G Ninja ' +
'-DCMAKE_MAKE_PROGRAM="' + $ninja + '" -DCMAKE_BUILD_TYPE=Release' +
(($extra | ForEach-Object { ' "' + $_ + '"' }) -join '')),
'if errorlevel 1 exit /b 1',
@@ -64,4 +67,5 @@ try {
if ($rc -ne 0) { throw "build failed ($rc)" }
Write-Host ""
if ($Target) { Write-Host "built target: $Target ($Arch)" }
elseif ($Source) { Write-Host "built: $outDir ($Arch)" }
else { Write-Host "built: $outDir\showcase.exe (plus simple.exe and notepad.exe), $Arch" }
+1 -35
View File
@@ -3,41 +3,7 @@
#include "nk_common.h"
#include <stdio.h>
enum {
REAKTOR_A11Y_NONE = 0,
REAKTOR_A11Y_WINDOW,
REAKTOR_A11Y_GROUP,
REAKTOR_A11Y_TABLIST,
REAKTOR_A11Y_TAB,
REAKTOR_A11Y_BUTTON,
REAKTOR_A11Y_LINK,
REAKTOR_A11Y_CHECKBOX,
REAKTOR_A11Y_RADIO,
REAKTOR_A11Y_TEXTBOX,
REAKTOR_A11Y_SLIDER,
REAKTOR_A11Y_SPINBUTTON,
REAKTOR_A11Y_PROGRESS,
REAKTOR_A11Y_COMBOBOX,
REAKTOR_A11Y_LISTITEM,
REAKTOR_A11Y_TREEITEM,
REAKTOR_A11Y_MENUBAR,
REAKTOR_A11Y_MENU,
REAKTOR_A11Y_MENUITEM,
REAKTOR_A11Y_DIALOG,
REAKTOR_A11Y_LABEL,
REAKTOR_A11Y_ROLE_COUNT
};
enum {
REAKTOR_A11Y_FOCUSED = 1u << 0,
REAKTOR_A11Y_CHECKED = 1u << 1,
REAKTOR_A11Y_EXPANDED = 1u << 2,
REAKTOR_A11Y_SELECTED = 1u << 3,
REAKTOR_A11Y_DISABLED = 1u << 4,
REAKTOR_A11Y_OFFSCREEN = 1u << 6,
REAKTOR_A11Y_VOLATILE = 1u << 7
};
#include "reaktor/a11y.h"
typedef struct reaktor_a11y_node {
unsigned id;
+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;
}
+7 -34
View File
@@ -1,42 +1,15 @@
#ifndef REAKTOR_ANIM_H
#define REAKTOR_ANIM_H
#include "a11y.h"
#include "reaktor/anim.h"
enum {
REAKTOR_EASE_LINEAR = 0,
struct nka_context *reaktor_anim_create(void);
void reaktor_anim_destroy(struct nka_context *a);
REAKTOR_EASE_QUAD_IN, REAKTOR_EASE_QUAD_OUT, REAKTOR_EASE_QUAD_IN_OUT,
REAKTOR_EASE_CUBIC_IN, REAKTOR_EASE_CUBIC_OUT, REAKTOR_EASE_CUBIC_IN_OUT,
REAKTOR_EASE_QUART_IN, REAKTOR_EASE_QUART_OUT, REAKTOR_EASE_QUART_IN_OUT,
REAKTOR_EASE_QUINT_IN, REAKTOR_EASE_QUINT_OUT, REAKTOR_EASE_QUINT_IN_OUT,
REAKTOR_EASE_SINE_IN, REAKTOR_EASE_SINE_OUT, REAKTOR_EASE_SINE_IN_OUT,
REAKTOR_EASE_EXPO_IN, REAKTOR_EASE_EXPO_OUT, REAKTOR_EASE_EXPO_IN_OUT,
REAKTOR_EASE_CIRC_IN, REAKTOR_EASE_CIRC_OUT, REAKTOR_EASE_CIRC_IN_OUT,
REAKTOR_EASE_BACK_IN, REAKTOR_EASE_BACK_OUT, REAKTOR_EASE_BACK_IN_OUT,
REAKTOR_EASE_ELASTIC_IN, REAKTOR_EASE_ELASTIC_OUT,
REAKTOR_EASE_ELASTIC_IN_OUT,
REAKTOR_EASE_BOUNCE_IN, REAKTOR_EASE_BOUNCE_OUT,
REAKTOR_EASE_BOUNCE_IN_OUT,
REAKTOR_EASE_COUNT
};
float reaktor_ease_at(unsigned char curve, float t);
const char *reaktor_ease_name(unsigned char curve);
float reaktor_animate(unsigned id, unsigned channel, float to,
float ms, unsigned char curve);
float reaktor_anim_progress(unsigned id, unsigned channel);
void reaktor_anim_scope(const void *owner);
int reaktor_anim_tick(float dt_ms);
void reaktor_anim_evict(const reaktor_a11y_change *changes, int n);
/* 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);
/* After the page: nonzero while something it drew is still moving. */
int reaktor_anim_settle(void);
#endif
+1 -32
View File
@@ -1,41 +1,10 @@
#ifndef REAKTOR_STYLE_H
#define REAKTOR_STYLE_H
enum { REAKTOR_SIDE_TOP = 0, REAKTOR_SIDE_RIGHT, REAKTOR_SIDE_BOTTOM, REAKTOR_SIDE_LEFT };
enum { REAKTOR_CORNER_TL = 0, REAKTOR_CORNER_TR, REAKTOR_CORNER_BR, REAKTOR_CORNER_BL };
typedef struct reaktor_style {
unsigned char bg[4];
unsigned char fg[4];
unsigned char border_col[4];
float border;
float rounding;
float pad_x, pad_y;
float pad[4];
float border_w[4];
float radius[4];
float margin[4];
float width, height;
float min_width, min_height;
float max_width, max_height;
float line_height;
int font_px;
int bold;
int matched;
} reaktor_style;
#include "reaktor/style.h"
int reaktor_style_init(const char *const *css_paths, int count,
const char *theme);
void reaktor_style_shutdown(void);
void reaktor_style_get(const char *selector, reaktor_style *out);
void reaktor_style_darken(unsigned char rgba[4], float amount);
int reaktor_style_token(const char *name, unsigned char rgba[4]);
#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 -27
View File
@@ -1,35 +1,9 @@
#ifndef REAKTOR_LOCALE_H
#define REAKTOR_LOCALE_H
#include <stddef.h>
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);
int reaktor_locale_set(const char *code);
const char *reaktor_locale_current(void);
const char *reaktor_tr(const char *key);
const char *reaktor_trn(const char *key, unsigned long n, char *buf, size_t cap);
#include "reaktor/locale.h"
/* The caller SDL_frees them. */
unsigned *reaktor_locale_glyphs(const unsigned char *ttf);
const char *reaktor_format_number(char *buf, size_t cap, double value,
int decimals);
const char *reaktor_format_money(char *buf, size_t cap, double amount,
const char *currency);
enum {
REAKTOR_DATE_SHORT,
REAKTOR_DATE_LONG,
REAKTOR_DATE_FULL,
REAKTOR_TIME_SHORT
};
struct tm;
const char *reaktor_format_date(char *buf, size_t cap, const struct tm *t,
int style);
#endif
+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 *
+6
View File
@@ -196,6 +196,12 @@ icon(App *app, const char *src, int px)
return icon_over(app, src, px, 2.0f);
}
struct nk_image
reaktor_svg(App *app, const char *src, int px)
{
return icon(app, src, px);
}
void
image_centred(struct nk_context *ctx, struct nk_image im, int px)
{
+1 -15
View File
@@ -1,21 +1,7 @@
#ifndef REAKTOR_NK_COMMON_H
#define REAKTOR_NK_COMMON_H
#define NK_INCLUDE_FIXED_TYPES
#define NK_INCLUDE_STANDARD_IO
#define NK_INCLUDE_STANDARD_VARARGS
#define NK_INCLUDE_DEFAULT_ALLOCATOR
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
#define NK_INCLUDE_COMMAND_USERDATA
#define NK_INCLUDE_FONT_BAKING
#define NK_INCLUDE_DEFAULT_FONT
/* A browser delivers press and release in one task. */
#define NK_BUTTON_TRIGGER_ON_RELEASE
#include <stddef.h>
#include "../../external/nuklear/nuklear.h"
#include "reaktor/nuklear.h"
/* The caller SDL_frees the ranges. */
int reaktor_font_valid(const void *ttf, size_t size);
+2 -5
View File
@@ -1,6 +1,8 @@
#ifndef REAKTOR_TEXT_H
#define REAKTOR_TEXT_H
#include "reaktor/text.h"
struct nk_context;
struct nk_font;
struct SDL_Renderer;
@@ -9,9 +11,4 @@ void reaktor_text_add_fallback(const char *path);
void reaktor_text_attach_font(struct nk_font *font, const char *path);
void reaktor_text_prepare(struct nk_context *ctx, struct SDL_Renderer *renderer);
/* Where the next line starts, at or before limit; 0 if nowhere. */
int reaktor_text_break(const char *s, int len, int limit);
int reaktor_text_rtl(const char *s, int len);
void reaktor_text_describe(char *buf, int cap);
#endif
+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))
+1 -241
View File
@@ -2,6 +2,7 @@
#define REAKTOR_DECLARE_H
#include "layout.h"
#include "reaktor/widgets.h"
#ifndef REAKTOR_APP_FWD
#define REAKTOR_APP_FWD
@@ -13,245 +14,4 @@ void reaktor_frame_end(void);
int reaktor_frame_settled(const App *app);
void reaktor_box_open(unsigned char dir, const reaktor_box *b);
void reaktor_box_close(void);
#define REAKTOR_BOX_SCOPE_(axis, ...) \
for (int reaktor_box_scope_ = \
(reaktor_box_open((unsigned char)(axis), \
&(reaktor_box){ 0, __VA_ARGS__ }), 1); \
reaktor_box_scope_; \
reaktor_box_scope_ = (reaktor_box_close(), 0))
int reaktor_box_rect(struct nk_rect *out);
unsigned reaktor_box_id(void);
#define REAKTOR_ROW(...) REAKTOR_BOX_SCOPE_(REAKTOR_LAY_ROW, __VA_ARGS__)
#define REAKTOR_COLUMN(...) REAKTOR_BOX_SCOPE_(REAKTOR_LAY_COLUMN, __VA_ARGS__)
#define REAKTOR_FREE(...) REAKTOR_BOX_SCOPE_(REAKTOR_LAY_FREE, __VA_ARGS__)
void reaktor_gap(float w, float h);
void reaktor_soak(void);
typedef void (*reaktor_action)(void *user);
typedef struct reaktor_handler {
reaktor_action fn;
void *user;
} reaktor_handler;
enum { REAKTOR_LEFT = 0, REAKTOR_CENTRE, REAKTOR_RIGHT };
typedef struct reaktor_button_spec {
const char *label;
const char *icon;
const char *name;
const char *style;
const char *keys;
reaktor_box box;
reaktor_handler on_press;
unsigned char accent;
unsigned char disabled;
unsigned char repeat;
} reaktor_button_spec;
int reaktor_button(const reaktor_button_spec *s);
typedef struct reaktor_label_spec {
const char *text;
const char *name;
const char *value;
const char *style;
const char *color;
reaktor_box box;
unsigned char align;
unsigned char wrap;
unsigned char silent;
} reaktor_label_spec;
void reaktor_label(const reaktor_label_spec *s);
typedef struct reaktor_swatch_spec {
const char *name;
struct nk_color fill;
const char *style;
reaktor_box box;
reaktor_handler on_press;
} reaktor_swatch_spec;
int reaktor_swatch(const reaktor_swatch_spec *s);
typedef struct reaktor_icon_spec {
const char *name;
const char *style;
reaktor_box box;
unsigned char accent;
} reaktor_icon_spec;
void reaktor_icon(const reaktor_icon_spec *s);
typedef struct reaktor_field_spec {
char *buf;
int *len;
int cap;
const char *hint;
const char *name;
const char *style;
float pad_x, pad_y;
nk_plugin_filter filter;
reaktor_box box;
unsigned char multiline;
} reaktor_field_spec;
void reaktor_field(const reaktor_field_spec *s);
typedef struct reaktor_check_spec {
const char *label;
const char *name;
nk_bool *on;
unsigned *flags;
unsigned bit;
const char *style;
reaktor_box box;
unsigned char box_right;
} reaktor_check_spec;
int reaktor_check(const reaktor_check_spec *s);
typedef struct reaktor_radio_spec {
const char *label;
const char *name;
int *choice;
int value;
const char *style;
reaktor_box box;
} reaktor_radio_spec;
int reaktor_radio(const reaktor_radio_spec *s);
typedef struct reaktor_select_spec {
const char *label;
const char *name;
nk_bool *on;
const char *icon;
unsigned char disc;
const char *style;
reaktor_box box;
unsigned char centered;
} reaktor_select_spec;
int reaktor_select(const reaktor_select_spec *s);
typedef struct reaktor_slider_spec {
const char *name;
const char *text;
float *value;
int *ivalue;
float lo, hi, step;
const char *style;
reaktor_box box;
} reaktor_slider_spec;
void reaktor_slider(const reaktor_slider_spec *s);
typedef struct reaktor_progress_spec {
const char *name;
nk_size *value;
nk_size max;
const char *style;
reaktor_box box;
unsigned char modifiable;
} reaktor_progress_spec;
void reaktor_progress(const reaktor_progress_spec *s);
typedef struct reaktor_knob_spec {
const char *name;
float *value;
float lo, hi;
const char *style;
reaktor_box box;
} reaktor_knob_spec;
void reaktor_knob(const reaktor_knob_spec *s);
typedef struct reaktor_property_spec {
const char *label;
const char *name;
int *ivalue;
float *fvalue;
double *dvalue;
double lo, hi, step;
float grain;
const char *style;
reaktor_box box;
} reaktor_property_spec;
void reaktor_property(const reaktor_property_spec *s);
typedef struct reaktor_combo_spec {
const char *label;
const char *name;
float body_h;
const char *style;
reaktor_box box;
unsigned char disc;
const struct nk_color *swatch;
} reaktor_combo_spec;
int reaktor_combo_open(const reaktor_combo_spec *s);
void reaktor_combo_close(void);
#define REAKTOR_COMBO(...) \
for (int reaktor_combo_scope_ = \
reaktor_combo_open(&(reaktor_combo_spec){ __VA_ARGS__ }); \
reaktor_combo_scope_; \
reaktor_combo_scope_ = (reaktor_combo_close(), 0))
int reaktor_combo_item(const char *label, int chosen);
typedef struct reaktor_colour_spec {
const char *name;
struct nk_colorf *value;
const char *style;
reaktor_box box;
} reaktor_colour_spec;
void reaktor_colour_pick(const reaktor_colour_spec *s);
typedef struct reaktor_link_spec {
const char *text;
const char *name;
const char *style;
reaktor_box box;
reaktor_handler on_press;
unsigned char active;
} reaktor_link_spec;
int reaktor_link(const reaktor_link_spec *s);
enum { REAKTOR_NAV_PAGES, REAKTOR_NAV_CHOICE, REAKTOR_NAV_ACTIONS };
typedef struct reaktor_nav_spec {
const char *const *items;
const char *const *icons;
const char *const *keys;
int count;
int *chosen;
const char *name;
const char *list_keys;
const char *style;
reaktor_box box;
unsigned char kind;
unsigned char narrow;
} reaktor_nav_spec;
typedef reaktor_nav_spec reaktor_sidebar_spec;
typedef reaktor_nav_spec reaktor_tabs_spec;
int reaktor_sidebar(const reaktor_sidebar_spec *s);
int reaktor_tabs(const reaktor_tabs_spec *s);
#endif
+16
View File
@@ -238,6 +238,22 @@ reaktor_focus_activated(App *app, unsigned id)
return !held_back(app);
}
void
reaktor_focus_area(App *app, struct nk_rect area, unsigned node)
{
app->body_rect = area;
app->page_node = node;
}
int
reaktor_focus_scroll(App *app, struct nk_rect *reveal)
{
if (!app->focus_scroll) return 0;
app->focus_scroll = 0;
if (reveal) *reveal = app->focus_scroll_rect;
return 1;
}
int
reaktor_focus_step(App *app, unsigned id)
{
+3 -27
View File
@@ -1,30 +1,6 @@
#ifndef REAKTOR_KEYS_H
#define REAKTOR_KEYS_H
#ifndef REAKTOR_KEYS_INTERNAL_H
#define REAKTOR_KEYS_INTERNAL_H
#include <SDL3/SDL.h>
enum {
REAKTOR_MOD_SHIFT = 1u << 0,
REAKTOR_MOD_CTRL = 1u << 1,
REAKTOR_MOD_ALT = 1u << 2,
REAKTOR_MOD_CMD = 1u << 3
};
typedef struct reaktor_shortcut {
unsigned mods;
SDL_Keycode key, key_last;
int action;
const char *name;
} reaktor_shortcut;
int reaktor_chord(const SDL_Event *e, unsigned mods, SDL_Keycode key);
int reaktor_shortcut_match(const reaktor_shortcut *table, int count,
const SDL_Event *e, int *index);
int reaktor_chord_text(unsigned mods, SDL_Keycode key, char *out, int cap);
int reaktor_shortcut_text(const reaktor_shortcut *table, int count,
int action, int index, char *out, int cap);
#include "reaktor/keys.h"
#endif
+1 -27
View File
@@ -3,33 +3,7 @@
#include "nk_common.h"
#include "onlay.h"
enum {
REAKTOR_LAY_ROW = 0,
REAKTOR_LAY_COLUMN,
REAKTOR_LAY_FREE
};
enum {
REAKTOR_LAY_FILL_X = 1u << 0,
REAKTOR_LAY_FILL_Y = 1u << 1,
REAKTOR_LAY_WRAP = 1u << 2,
REAKTOR_LAY_CENTER_X = 1u << 3,
REAKTOR_LAY_CENTER_Y = 1u << 4,
REAKTOR_LAY_PACK_CENTER = 1u << 5,
REAKTOR_LAY_PACK_END = 1u << 6,
REAKTOR_LAY_PACK_SPREAD = 1u << 7
};
typedef struct reaktor_box {
unsigned char dir;
const char *name;
float w, h;
float weight;
float gap;
float ml, mt, mr, mb;
unsigned flags;
} reaktor_box;
#include "reaktor/widgets.h"
#define REAKTOR_LAY_MAX 256
#define REAKTOR_LAY_DEPTH 32
+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;
}
+9 -1
View File
@@ -1157,6 +1157,14 @@ reaktor_menu_item(App *app, struct nk_context *ctx, const char *label,
}
return hit;
}
void
reaktor_frame_ms(App *app, double *build, double *render, double *present)
{
if (build) *build = app->build_ms_x100 / 100.0;
if (render) *render = app->render_ms_x100 / 100.0;
if (present) *present = app->present_ms_x100 / 100.0;
}
void
reaktor_diagnostics(App *app, reaktor_diag *out)
{
@@ -1213,7 +1221,7 @@ reaktor_diagnostics(App *app, reaktor_diag *out)
out->atlas_bpp = app->atlas_bpp;
{
int i;
for (i = 0; i < RSS_STEPS; i++) {
for (i = 0; i < REAKTOR_RSS_STEPS; i++) {
out->rss_at[i] = (unsigned long)reaktor_rss[i];
out->priv_at[i] = (unsigned long)reaktor_priv[i];
}
+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
+129 -32
View File
@@ -19,7 +19,7 @@
web it returns at once, and a second call returns 1.
```c
#include "reaktor/launch.h"
#include "reaktor/reaktor.h"
#include "reaktor/main.h" /* in the one file that defines main */
int
@@ -39,6 +39,14 @@ keys mean. Only `.page` is required. `launchApp` is an inline alias of
`reaktor_launch_app`, left out under `REAKTOR_NO_SHORT_NAMES`.
[`samples/simple/simple.c`](../samples/simple/simple.c) is a whole application.
`reaktor/reaktor.h` is the whole public API: it includes the rest of
[`include/reaktor/`](../include/reaktor/) — Nuklear as Reaktor configures it,
`launch.h`, `widgets.h`, `keys.h`, `a11y.h`, `ui.h`, `anim.h`, `locale.h`,
`style.h` and `text.h` — and nothing from `src/` or `core/`. `App` is opaque:
the calls below ask it what an application may know. Every sample includes
only these headers, and MSVC builds an app with implicit declarations as
errors, so an internal function cannot slip back in.
| Hook | When |
| --- | --- |
| `page(app, ctx, w, h)` | Every frame, inside a panel covering the window |
@@ -59,6 +67,11 @@ keys mean. Only `.page` is required. `launchApp` is an inline alias of
| `reaktor_set_confirm_close(app, question)` | Ask `question` before quitting, or with `NULL` stop asking |
| `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
nothing when nothing changes.
@@ -102,11 +115,11 @@ if (reaktor_button(&(reaktor_button_spec){
Every spec has `.name` (the accessible name, and how layout finds the widget
again), `.style` (a selector to read instead of the widget's own) and `.box`
([Layout](#layout)). They are declared in
[`core/ui/declare.h`](../core/ui/declare.h).
[`include/reaktor/widgets.h`](../include/reaktor/widgets.h).
| 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` |
@@ -124,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
@@ -222,7 +238,7 @@ logs the box.
Above the page, inside the main window: floaters, then toasts. Windows and
the tray are the system's. Their specs are in
[`include/reaktor/launch.h`](../include/reaktor/launch.h), except the toast's,
in [`src/ui.h`](../src/ui.h); all of them are main-thread calls.
in [`include/reaktor/ui.h`](../include/reaktor/ui.h); all of them are main-thread calls.
### Floaters
@@ -386,7 +402,7 @@ test that the look is not in the code.
A field keeps the arrows, Home, End, Enter and Space while it is edited; Tab
leaves it. A modal floater or an open popup keeps focus inside. A spec's
`.keys` only announces a shortcut; bind it in the `key` hook.
[`core/ui/keys.h`](../core/ui/keys.h) matches events against a table of
[`include/reaktor/keys.h`](../include/reaktor/keys.h) matches events against a table of
shortcuts (`reaktor_shortcut_match`) and writes the same table as text for
`.keys` (`reaktor_shortcut_text`), so the two never disagree.
@@ -406,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) {
@@ -421,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
@@ -430,23 +465,27 @@ Nuklear is still there. Groups, trees, list views, charts, menus and popup
bodies have no spec, and the samples call `nk_*` for them. A declared tree and
`nk_layout_row_*` cannot share a panel, so convert a whole container at a
time; a group or popup is its own panel and may be laid out by hand inside a
declared page. [`src/ui.h`](../src/ui.h) has the pieces the specs are made of:
declared page. [`include/reaktor/ui.h`](../include/reaktor/ui.h) has the pieces the specs are made of:
| Helper | For |
| --- | --- |
| `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_diagnostics` | What the Diagnostics page shows |
| `reaktor_focus_area`, `reaktor_focus_scroll` | A scrolling page body: the area and node focus moves within, and the rectangle it asks to see |
| `reaktor_diagnostics`, `reaktor_frame_ms` | What the Diagnostics page shows; one frame's build, render and present |
| `reaktor_process_memory`, `reaktor_process_cpu_ms` | The process's resident and private bytes, and its CPU time |
The rest is by subject: [`keys.h`](../core/ui/keys.h),
[`anim.h`](../core/anim/anim.h), [`locale.h`](../core/locale/locale.h),
[`text.h`](../core/text/text.h) and [`style.h`](../core/css/style.h).
The rest is by subject: [`keys.h`](../include/reaktor/keys.h),
[`anim.h`](../include/reaktor/anim.h), [`locale.h`](../include/reaktor/locale.h),
[`text.h`](../include/reaktor/text.h), [`style.h`](../include/reaktor/style.h)
and [`a11y.h`](../include/reaktor/a11y.h).
---
@@ -477,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
@@ -485,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
@@ -520,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
@@ -549,23 +595,69 @@ writes a `--shot` and an `--a11y-dump` of `simple` and the showcase through
the system's video driver and SDL's `dummy` one: `.github/workflows/` holds a
workflow per system. The BSDs run in virtual machines, ARM64 among them under
emulation, and a job that emulates may fail without failing its run. The web
build is checked by hand in headless Edge, as desktop, Android and iOS.
build is built and packed on every pull request too (`web.yml`), and checked
by hand in headless Edge, as desktop, Android and iOS.
`build.sh` builds for the machine it runs on. `build.ps1 -Arch x86` (or `x64`,
`arm64`) builds that architecture with MSVC's matching toolset, into
`build-<arch>` when it is not the machine's own; ARM64 needs Visual Studio's
ARM64 build tools.
**Releases.** Pushing a `v*` tag runs `release.yml`: the three workflows
again, with every job required, and a GitHub release of what they packed —
one archive per system and architecture, and the source with its submodules,
which GitHub's own archives leave out. `tools/package.sh <build> <folder>
[.exe]` packs one: the four programs without their symbols, the `.reaktor-root` marker, the files
they read at runtime (`tools/assets.sh`, which the macOS app bundle uses too),
`licenses/` and `NOTICE.md`. Each job runs the packed showcase and checks it
draws its Translations page as the built one does. Windows links the C runtime
statically (`-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded`); the macOS app is
signed ad hoc, not notarized; Linux needs glibc 2.36, or 2.41 on RISC-V.
**Releases.** Pushing a `v*` tag runs `release.yml`: the four native
workflows again, with every job required, a web build, and a GitHub release
of what they packed — one archive per system and architecture, the three
WebAssembly programs, libreaktor for each ([In your own project](#in-your-own-project)),
the source with its submodules, which GitHub's own archives leave out, and a
`SHA256SUMS` of them all. `tools/package.sh <build> <folder> [.exe]` packs a native
one: the four programs without their symbols, the `.reaktor-root` marker, the
files they read at runtime (`tools/assets.sh`, which the macOS app bundle uses
too), `licenses/` and `NOTICE.md`. Each job runs the packed showcase and
checks it draws its Translations page as the built one does. Windows links the
C runtime statically (`-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded`); the macOS
app is signed ad hoc, not notarized; Linux needs glibc 2.36, or 2.41 on
RISC-V; a BSD package wants the release it was built on.
## In your own project
**Embedded.** Add the checkout, submodules and all, and declare the app:
```cmake
add_subdirectory(reaktor) # or FetchContent, which clones the submodules too
reaktor_add_app(myapp SOURCES main.c)
```
Under another project Reaktor builds none of its samples or tests and
installs nothing (`REAKTOR_SAMPLES`, `REAKTOR_TESTS` and `REAKTOR_INSTALL`
default to on only at the top), and its settings stay in its own directory.
**libreaktor.** Each release carries `libreaktor-<version>-<system>-<arch>`
for every platform above, and `-wasm`. Build one yourself with:
```bash
cmake --build build --target libreaktor
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, 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.3 REQUIRED)
add_executable(app WIN32 main.c)
target_link_libraries(app PRIVATE reaktor::reaktor)
```
`pkg-config --cflags --libs reaktor` answers the same outside CMake. The
library takes the C runtime its build used: the release's Windows ones use
the DLL runtime, CMake's default, while the programs in a release link it
statically. On the web, point `reaktor_DIR` at its `lib/cmake/reaktor`, as
the emscripten toolchain searches only its own sysroot.
[`examples/consumer`](../examples/consumer) builds `samples/simple/simple.c`
against an installed package: every CI job does, and checks it draws as the
in-tree build does.
## Build options
@@ -583,6 +675,8 @@ Passed to CMake, through either script:
| `REAKTOR_LOCALE_EMBED` | `OFF` | Compile the catalogs in rather than read them at startup |
| `REAKTOR_TEXT` | `ON` | Direction, shaping, fallback glyphs and Unicode line breaks — [Text](#text) |
| `REAKTOR_SDL_GL` | `OFF` | Build SDL's OpenGL and GLES drivers on Linux and the BSDs |
| `REAKTOR_SAMPLES`, `REAKTOR_TESTS` | `ON` at the top | Build the samples, and the tests in `tools/` |
| `REAKTOR_INSTALL` | `ON` at the top | Install rules for libreaktor's files |
**CMake keeps an option**, so a build without the flag keeps the last value;
pass `=ON` to switch one back.
@@ -671,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 |
@@ -788,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`
+10
View File
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.16)
project(consumer C)
find_package(reaktor 0.3 REQUIRED)
add_executable(simple WIN32 ../../samples/simple/simple.c)
target_link_libraries(simple PRIVATE reaktor::reaktor)
if(EMSCRIPTEN)
set_target_properties(simple PROPERTIES SUFFIX ".html")
endif()
Vendored Submodule
+1
Submodule external/nukanim added at 9e4eaf6a12
+39
View File
@@ -0,0 +1,39 @@
#ifndef REAKTOR_A11Y_PUBLIC_H
#define REAKTOR_A11Y_PUBLIC_H
enum {
REAKTOR_A11Y_NONE = 0,
REAKTOR_A11Y_WINDOW,
REAKTOR_A11Y_GROUP,
REAKTOR_A11Y_TABLIST,
REAKTOR_A11Y_TAB,
REAKTOR_A11Y_BUTTON,
REAKTOR_A11Y_LINK,
REAKTOR_A11Y_CHECKBOX,
REAKTOR_A11Y_RADIO,
REAKTOR_A11Y_TEXTBOX,
REAKTOR_A11Y_SLIDER,
REAKTOR_A11Y_SPINBUTTON,
REAKTOR_A11Y_PROGRESS,
REAKTOR_A11Y_COMBOBOX,
REAKTOR_A11Y_LISTITEM,
REAKTOR_A11Y_TREEITEM,
REAKTOR_A11Y_MENUBAR,
REAKTOR_A11Y_MENU,
REAKTOR_A11Y_MENUITEM,
REAKTOR_A11Y_DIALOG,
REAKTOR_A11Y_LABEL,
REAKTOR_A11Y_ROLE_COUNT
};
enum {
REAKTOR_A11Y_FOCUSED = 1u << 0,
REAKTOR_A11Y_CHECKED = 1u << 1,
REAKTOR_A11Y_EXPANDED = 1u << 2,
REAKTOR_A11Y_SELECTED = 1u << 3,
REAKTOR_A11Y_DISABLED = 1u << 4,
REAKTOR_A11Y_OFFSCREEN = 1u << 6,
REAKTOR_A11Y_VOLATILE = 1u << 7
};
#endif
+44
View File
@@ -0,0 +1,44 @@
#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,
REAKTOR_EASE_QUAD_IN, REAKTOR_EASE_QUAD_OUT, REAKTOR_EASE_QUAD_IN_OUT,
REAKTOR_EASE_CUBIC_IN, REAKTOR_EASE_CUBIC_OUT, REAKTOR_EASE_CUBIC_IN_OUT,
REAKTOR_EASE_QUART_IN, REAKTOR_EASE_QUART_OUT, REAKTOR_EASE_QUART_IN_OUT,
REAKTOR_EASE_QUINT_IN, REAKTOR_EASE_QUINT_OUT, REAKTOR_EASE_QUINT_IN_OUT,
REAKTOR_EASE_SINE_IN, REAKTOR_EASE_SINE_OUT, REAKTOR_EASE_SINE_IN_OUT,
REAKTOR_EASE_EXPO_IN, REAKTOR_EASE_EXPO_OUT, REAKTOR_EASE_EXPO_IN_OUT,
REAKTOR_EASE_CIRC_IN, REAKTOR_EASE_CIRC_OUT, REAKTOR_EASE_CIRC_IN_OUT,
REAKTOR_EASE_BACK_IN, REAKTOR_EASE_BACK_OUT, REAKTOR_EASE_BACK_IN_OUT,
REAKTOR_EASE_ELASTIC_IN, REAKTOR_EASE_ELASTIC_OUT,
REAKTOR_EASE_ELASTIC_IN_OUT,
REAKTOR_EASE_BOUNCE_IN, REAKTOR_EASE_BOUNCE_OUT,
REAKTOR_EASE_BOUNCE_IN_OUT,
REAKTOR_EASE_COUNT
};
float reaktor_ease_at(unsigned char curve, float t);
const char *reaktor_ease_name(unsigned char curve);
float reaktor_animate(unsigned id, unsigned channel, float to,
float ms, unsigned char curve);
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
+30
View File
@@ -0,0 +1,30 @@
#ifndef REAKTOR_KEYS_H
#define REAKTOR_KEYS_H
#include <SDL3/SDL.h>
enum {
REAKTOR_MOD_SHIFT = 1u << 0,
REAKTOR_MOD_CTRL = 1u << 1,
REAKTOR_MOD_ALT = 1u << 2,
REAKTOR_MOD_CMD = 1u << 3
};
typedef struct reaktor_shortcut {
unsigned mods;
SDL_Keycode key, key_last;
int action;
const char *name;
} reaktor_shortcut;
int reaktor_chord(const SDL_Event *e, unsigned mods, SDL_Keycode key);
int reaktor_shortcut_match(const reaktor_shortcut *table, int count,
const SDL_Event *e, int *index);
int reaktor_chord_text(unsigned mods, SDL_Keycode key, char *out, int cap);
int reaktor_shortcut_text(const reaktor_shortcut *table, int count,
int action, int index, char *out, int cap);
#endif
+13
View File
@@ -121,6 +121,19 @@ void reaktor_set_title(App *app, const char *title);
void reaktor_set_confirm_close(App *app, const char *question);
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);
/* Main thread. Answers 0 on the web. */
int reaktor_window_open(App *app, const reaktor_window *window);
void reaktor_window_close(App *app, int id);
+34
View File
@@ -0,0 +1,34 @@
#ifndef REAKTOR_LOCALE_PUBLIC_H
#define REAKTOR_LOCALE_PUBLIC_H
#include <stddef.h>
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);
const char *reaktor_trn(const char *key, unsigned long n, char *buf, size_t cap);
const char *reaktor_format_number(char *buf, size_t cap, double value,
int decimals);
const char *reaktor_format_money(char *buf, size_t cap, double amount,
const char *currency);
enum {
REAKTOR_DATE_SHORT,
REAKTOR_DATE_LONG,
REAKTOR_DATE_FULL,
REAKTOR_TIME_SHORT
};
struct tm;
const char *reaktor_format_date(char *buf, size_t cap, const struct tm *t,
int style);
#endif
+19
View File
@@ -0,0 +1,19 @@
#ifndef REAKTOR_NUKLEAR_H
#define REAKTOR_NUKLEAR_H
#define NK_INCLUDE_FIXED_TYPES
#define NK_INCLUDE_STANDARD_IO
#define NK_INCLUDE_STANDARD_VARARGS
#define NK_INCLUDE_DEFAULT_ALLOCATOR
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
#define NK_INCLUDE_COMMAND_USERDATA
#define NK_INCLUDE_FONT_BAKING
#define NK_INCLUDE_DEFAULT_FONT
/* A browser delivers press and release in one task. */
#define NK_BUTTON_TRIGGER_ON_RELEASE
#include <stddef.h>
#include <nuklear.h>
#endif
+15
View File
@@ -0,0 +1,15 @@
#ifndef REAKTOR_REAKTOR_H
#define REAKTOR_REAKTOR_H
#include "reaktor/nuklear.h"
#include "reaktor/launch.h"
#include "reaktor/widgets.h"
#include "reaktor/keys.h"
#include "reaktor/a11y.h"
#include "reaktor/ui.h"
#include "reaktor/anim.h"
#include "reaktor/locale.h"
#include "reaktor/style.h"
#include "reaktor/text.h"
#endif
+37
View File
@@ -0,0 +1,37 @@
#ifndef REAKTOR_STYLE_PUBLIC_H
#define REAKTOR_STYLE_PUBLIC_H
enum { REAKTOR_SIDE_TOP = 0, REAKTOR_SIDE_RIGHT, REAKTOR_SIDE_BOTTOM, REAKTOR_SIDE_LEFT };
enum { REAKTOR_CORNER_TL = 0, REAKTOR_CORNER_TR, REAKTOR_CORNER_BR, REAKTOR_CORNER_BL };
typedef struct reaktor_style {
unsigned char bg[4];
unsigned char fg[4];
unsigned char border_col[4];
float border;
float rounding;
float pad_x, pad_y;
float pad[4];
float border_w[4];
float radius[4];
float margin[4];
float width, height;
float min_width, min_height;
float max_width, max_height;
float line_height;
int font_px;
int bold;
int matched;
} reaktor_style;
void reaktor_style_get(const char *selector, reaktor_style *out);
void reaktor_style_darken(unsigned char rgba[4], float amount);
int reaktor_style_token(const char *name, unsigned char rgba[4]);
#endif
+9
View File
@@ -0,0 +1,9 @@
#ifndef REAKTOR_TEXT_PUBLIC_H
#define REAKTOR_TEXT_PUBLIC_H
/* Where the next line starts, at or before limit; 0 if nowhere. */
int reaktor_text_break(const char *s, int len, int limit);
int reaktor_text_rtl(const char *s, int len);
void reaktor_text_describe(char *buf, int cap);
#endif
+148
View File
@@ -0,0 +1,148 @@
#ifndef REAKTOR_UI_PUBLIC_H
#define REAKTOR_UI_PUBLIC_H
#include "reaktor/nuklear.h"
#include "reaktor/a11y.h"
#ifndef REAKTOR_APP_FWD
#define REAKTOR_APP_FWD
typedef struct App App;
#endif
enum {
REAKTOR_RSS_ENTRY,
REAKTOR_RSS_SDL,
REAKTOR_RSS_WINDOW,
REAKTOR_RSS_ICON,
REAKTOR_RSS_NUKLEAR,
REAKTOR_RSS_FONT,
REAKTOR_RSS_STYLE,
REAKTOR_RSS_STEPS
};
struct nk_color reaktor_col(const unsigned char rgba[4]);
struct nk_color reaktor_token(const char *name,
struct nk_color def);
struct nk_color reaktor_visible(struct nk_color want,
struct nk_color behind,
struct nk_color fallback);
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. */
struct nk_image reaktor_svg(App *app, const char *src, int px);
void reaktor_fill_round(App *app, struct nk_command_buffer *cv,
struct nk_rect b, float rounding, struct nk_color col);
void reaktor_edge_round(App *app, struct nk_command_buffer *cv,
struct nk_rect b, float rounding, float width,
struct nk_color col);
struct nk_color reaktor_on(struct nk_color bg);
void reaktor_hot(App *app, struct nk_rect r, int cursor, int repaint);
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);
void reaktor_progress_bar(App *app, struct nk_context *ctx, nk_size *cur,
nk_size max, int modifiable);
void reaktor_chevron_at(App *app, struct nk_context *ctx, struct nk_rect slot,
const char *name, struct nk_color col);
int reaktor_button_accent(App *app, struct nk_context *ctx, const char *label);
const struct nk_user_font *reaktor_style_font(App *app,
const char *selector,
int px, int bold);
float reaktor_popup_rounding(void);
#define REAKTOR_MENU_ROW 22.0f
#define REAKTOR_MENU_GAP 2.0f
void reaktor_menu_style_push(struct nk_context *ctx);
void reaktor_menu_style_pop(struct nk_context *ctx);
float reaktor_menu_height(int rows);
void reaktor_menu_edge(App *app, struct nk_context *ctx);
typedef struct reaktor_toast_spec {
const char *text;
const char *icon;
const char *action;
void (*on_action)(App *app, void *user);
void (*content)(App *app, struct nk_context *ctx, void *user);
float content_w;
void *user;
int timeout_ms;
int no_close;
} reaktor_toast_spec;
/* Main thread; hooks get the main window's App. */
void reaktor_toast(App *app, const reaktor_toast_spec *spec);
int reaktor_menu_item(App *app, struct nk_context *ctx, const char *label,
const char *accel, int contextual);
unsigned reaktor_note(App *app, unsigned char role, const char *name,
const char *value, unsigned state,
struct nk_rect bounds);
unsigned reaktor_note_push(App *app, unsigned char role, const char *name,
const char *value, unsigned state,
struct nk_rect bounds);
void reaktor_note_pop(App *app);
int reaktor_focus_activated(App *app, unsigned id);
void reaktor_focus_area(App *app, struct nk_rect area, unsigned node);
int reaktor_focus_scroll(App *app, struct nk_rect *reveal);
void reaktor_note_keys(App *app, unsigned id, const char *keys);
void reaktor_note_value(App *app, unsigned id, const char *value);
void reaktor_note_bounds(App *app, unsigned id, struct nk_rect r);
unsigned reaktor_note_here(App *app, struct nk_context *ctx,
unsigned char role, const char *name,
unsigned state);
int reaktor_file_open(App *app);
typedef struct reaktor_diag {
const char *renderer;
const char *mode;
const char *frame_rate;
const char *drag_rate;
const char *font;
int vsync, dark, sheets;
const char *aa;
float scale, style_ms, build_ms, render_ms, present_ms;
float frame_gap_ms;
float cpu_ms_per_frame;
int hover_gap_ms;
unsigned long nk_bytes, nk_used, icon_bytes;
unsigned long rss_bytes, private_bytes;
int icons;
int atlas_w, atlas_h, atlas_bpp;
unsigned long rss_at[REAKTOR_RSS_STEPS];
unsigned long priv_at[REAKTOR_RSS_STEPS];
} reaktor_diag;
void reaktor_diagnostics(App *app, reaktor_diag *out);
void reaktor_frame_ms(App *app, double *build, double *render, double *present);
void reaktor_process_memory(size_t *rss, size_t *priv);
double reaktor_process_cpu_ms(void);
#endif
+275
View File
@@ -0,0 +1,275 @@
#ifndef REAKTOR_WIDGETS_H
#define REAKTOR_WIDGETS_H
#include "reaktor/nuklear.h"
enum {
REAKTOR_LAY_ROW = 0,
REAKTOR_LAY_COLUMN,
REAKTOR_LAY_FREE
};
enum {
REAKTOR_LAY_FILL_X = 1u << 0,
REAKTOR_LAY_FILL_Y = 1u << 1,
REAKTOR_LAY_WRAP = 1u << 2,
REAKTOR_LAY_CENTER_X = 1u << 3,
REAKTOR_LAY_CENTER_Y = 1u << 4,
REAKTOR_LAY_PACK_CENTER = 1u << 5,
REAKTOR_LAY_PACK_END = 1u << 6,
REAKTOR_LAY_PACK_SPREAD = 1u << 7
};
typedef struct reaktor_box {
unsigned char dir;
const char *name;
float w, h;
float weight;
float gap;
float ml, mt, mr, mb;
unsigned flags;
} reaktor_box;
void reaktor_box_open(unsigned char dir, const reaktor_box *b);
void reaktor_box_close(void);
#define REAKTOR_BOX_SCOPE_(axis, ...) \
for (int reaktor_box_scope_ = \
(reaktor_box_open((unsigned char)(axis), \
&(reaktor_box){ 0, __VA_ARGS__ }), 1); \
reaktor_box_scope_; \
reaktor_box_scope_ = (reaktor_box_close(), 0))
int reaktor_box_rect(struct nk_rect *out);
unsigned reaktor_box_id(void);
#define REAKTOR_ROW(...) REAKTOR_BOX_SCOPE_(REAKTOR_LAY_ROW, __VA_ARGS__)
#define REAKTOR_COLUMN(...) REAKTOR_BOX_SCOPE_(REAKTOR_LAY_COLUMN, __VA_ARGS__)
#define REAKTOR_FREE(...) REAKTOR_BOX_SCOPE_(REAKTOR_LAY_FREE, __VA_ARGS__)
void reaktor_gap(float w, float h);
void reaktor_soak(void);
typedef void (*reaktor_action)(void *user);
typedef struct reaktor_handler {
reaktor_action fn;
void *user;
} reaktor_handler;
enum { REAKTOR_LEFT = 0, REAKTOR_CENTRE, REAKTOR_RIGHT };
typedef struct reaktor_button_spec {
const char *label;
const char *icon;
const char *name;
const char *style;
const char *keys;
reaktor_box box;
reaktor_handler on_press;
unsigned char accent;
unsigned char disabled;
unsigned char repeat;
unsigned char fit_content;
} reaktor_button_spec;
int reaktor_button(const reaktor_button_spec *s);
typedef struct reaktor_label_spec {
const char *text;
const char *name;
const char *value;
const char *style;
const char *color;
reaktor_box box;
unsigned char align;
unsigned char wrap;
unsigned char silent;
} reaktor_label_spec;
void reaktor_label(const reaktor_label_spec *s);
typedef struct reaktor_swatch_spec {
const char *name;
struct nk_color fill;
const char *style;
reaktor_box box;
reaktor_handler on_press;
} reaktor_swatch_spec;
int reaktor_swatch(const reaktor_swatch_spec *s);
typedef struct reaktor_icon_spec {
const char *name;
const char *style;
reaktor_box box;
unsigned char accent;
} reaktor_icon_spec;
void reaktor_icon(const reaktor_icon_spec *s);
typedef struct reaktor_field_spec {
char *buf;
int *len;
int cap;
const char *hint;
const char *name;
const char *style;
float pad_x, pad_y;
nk_plugin_filter filter;
reaktor_box box;
unsigned char multiline;
} reaktor_field_spec;
void reaktor_field(const reaktor_field_spec *s);
typedef struct reaktor_check_spec {
const char *label;
const char *name;
nk_bool *on;
unsigned *flags;
unsigned bit;
const char *style;
reaktor_box box;
unsigned char box_right;
} reaktor_check_spec;
int reaktor_check(const reaktor_check_spec *s);
typedef struct reaktor_radio_spec {
const char *label;
const char *name;
int *choice;
int value;
const char *style;
reaktor_box box;
} reaktor_radio_spec;
int reaktor_radio(const reaktor_radio_spec *s);
typedef struct reaktor_select_spec {
const char *label;
const char *name;
nk_bool *on;
const char *icon;
unsigned char disc;
const char *style;
reaktor_box box;
unsigned char centered;
} reaktor_select_spec;
int reaktor_select(const reaktor_select_spec *s);
typedef struct reaktor_slider_spec {
const char *name;
const char *text;
float *value;
int *ivalue;
float lo, hi, step;
const char *style;
reaktor_box box;
} reaktor_slider_spec;
void reaktor_slider(const reaktor_slider_spec *s);
typedef struct reaktor_progress_spec {
const char *name;
nk_size *value;
nk_size max;
const char *style;
reaktor_box box;
unsigned char modifiable;
} reaktor_progress_spec;
void reaktor_progress(const reaktor_progress_spec *s);
typedef struct reaktor_knob_spec {
const char *name;
float *value;
float lo, hi;
const char *style;
reaktor_box box;
} reaktor_knob_spec;
void reaktor_knob(const reaktor_knob_spec *s);
typedef struct reaktor_property_spec {
const char *label;
const char *name;
int *ivalue;
float *fvalue;
double *dvalue;
double lo, hi, step;
float grain;
const char *style;
reaktor_box box;
} reaktor_property_spec;
void reaktor_property(const reaktor_property_spec *s);
typedef struct reaktor_combo_spec {
const char *label;
const char *name;
float body_h;
const char *style;
reaktor_box box;
unsigned char disc;
const struct nk_color *swatch;
} reaktor_combo_spec;
int reaktor_combo_open(const reaktor_combo_spec *s);
void reaktor_combo_close(void);
#define REAKTOR_COMBO(...) \
for (int reaktor_combo_scope_ = \
reaktor_combo_open(&(reaktor_combo_spec){ __VA_ARGS__ }); \
reaktor_combo_scope_; \
reaktor_combo_scope_ = (reaktor_combo_close(), 0))
int reaktor_combo_item(const char *label, int chosen);
typedef struct reaktor_colour_spec {
const char *name;
struct nk_colorf *value;
const char *style;
reaktor_box box;
} reaktor_colour_spec;
void reaktor_colour_pick(const reaktor_colour_spec *s);
typedef struct reaktor_link_spec {
const char *text;
const char *name;
const char *style;
reaktor_box box;
reaktor_handler on_press;
unsigned char active;
} reaktor_link_spec;
int reaktor_link(const reaktor_link_spec *s);
enum { REAKTOR_NAV_PAGES, REAKTOR_NAV_CHOICE, REAKTOR_NAV_ACTIONS };
typedef struct reaktor_nav_spec {
const char *const *items;
const char *const *icons;
const char *const *keys;
int count;
int *chosen;
const char *name;
const char *list_keys;
const char *style;
reaktor_box box;
unsigned char kind;
unsigned char narrow;
} reaktor_nav_spec;
typedef reaktor_nav_spec reaktor_sidebar_spec;
typedef reaktor_nav_spec reaktor_tabs_spec;
int reaktor_sidebar(const reaktor_sidebar_spec *s);
int reaktor_tabs(const reaktor_tabs_spec *s);
#endif
+279 -20
View File
@@ -18,8 +18,8 @@ effective_dark(const App *app)
return reaktor_prefers_dark() > 0;
}
size_t reaktor_rss[RSS_STEPS];
size_t reaktor_priv[RSS_STEPS];
size_t reaktor_rss[REAKTOR_RSS_STEPS];
size_t reaktor_priv[REAKTOR_RSS_STEPS];
static reaktor_launch g_launch;
static App *g_app;
@@ -517,7 +517,7 @@ app_init(void **appstate, int argc, char *argv[])
{
App *app;
reaktor_rss_mark(RSS_ENTRY);
reaktor_rss_mark(REAKTOR_RSS_ENTRY);
app = (App *)SDL_calloc(1, sizeof(App));
if (!app) return SDL_APP_FAILURE;
*appstate = app;
@@ -546,7 +546,7 @@ app_init(void **appstate, int argc, char *argv[])
if (g_launch.console == REAKTOR_CONSOLE_DEBUG)
SDL_SetLogPriorities(SDL_LOG_PRIORITY_DEBUG);
reaktor_rss_mark(RSS_SDL);
reaktor_rss_mark(REAKTOR_RSS_SDL);
take_assets(app);
if (app->renderer_pref && SDL_strcmp(app->renderer_pref, "software") != 0) {
@@ -645,21 +645,21 @@ app_init(void **appstate, int argc, char *argv[])
if (app->borderless && g_launch.window.hit_test)
SDL_SetWindowHitTest(app->win, g_launch.window.hit_test, app);
reaktor_rss_mark(RSS_WINDOW);
reaktor_rss_mark(REAKTOR_RSS_WINDOW);
reaktor_set_window_icon(app->win, reaktor_launch_icon());
reaktor_set_scale(reaktor_dpi_query_scale(app->win));
apply_render_scale(app);
reaktor_rss_mark(RSS_ICON);
reaktor_rss_mark(REAKTOR_RSS_ICON);
app->ctx = nk_sdl_init(app->win, app->ren, nk_sdl_allocator());
if (!app->ctx) return fail(app, "The interface could not start");
reaktor_rss_mark(RSS_NUKLEAR);
reaktor_rss_mark(REAKTOR_RSS_NUKLEAR);
/* Before the atlas, which bakes what the catalogs need. */
reaktor_locale_start(app->lang_pref);
rebuild_font(app);
reaktor_rss_mark(RSS_FONT);
reaktor_rss_mark(REAKTOR_RSS_FONT);
app->cur_default = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_DEFAULT);
app->cur_pointer = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_POINTER);
@@ -678,7 +678,7 @@ app_init(void **appstate, int argc, char *argv[])
take_pending(app);
load_theme(app);
reaktor_rss_mark(RSS_STYLE);
reaktor_rss_mark(REAKTOR_RSS_STYLE);
app->dirty = 1;
@@ -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);
}
@@ -1486,7 +1680,6 @@ app_iterate(void *appstate)
SDL_SyncWindow(app->win);
SDL_GetWindowSize(app->win, &w, &h);
SDL_SetWindowSize(app->win, w, h);
app->ctl_n = 0;
app->dirty = 1;
app->borderless_lock_frames = 3;
}
@@ -1539,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;
@@ -1714,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)
{
@@ -1726,3 +1928,60 @@ reaktor_user(App *app)
(void)app;
return g_launch.user;
}
SDL_Window *
reaktor_sdl_window(App *app)
{
return app ? app->win : NULL;
}
SDL_Renderer *
reaktor_sdl_renderer(App *app)
{
return app ? app->ren : NULL;
}
int
reaktor_dark(App *app)
{
return app && app->dark;
}
reaktor_theme
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)
{
if (!app || !app->win || app->secondary || !on == !app->borderless) return;
#ifdef __APPLE__
if (app->borderless_lock_frames == 0) {
app->borderless_pending = 1;
app->dirty = 1;
}
#else
app->borderless = on != 0;
SDL_SetWindowBordered(app->win, app->borderless ? false : true);
SDL_SetWindowHitTest(app->win,
app->borderless ? g_launch.window.hit_test : NULL,
app->borderless ? app : NULL);
app->dirty = 1;
#endif
}
int
reaktor_borderless(App *app)
{
return app && app->borderless;
}
+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)
{
+7 -9
View File
@@ -1,8 +1,5 @@
#include "internal.h"
#include "declare.h"
#include "reaktor/launch.h"
#include "reaktor/reaktor.h"
#include "reaktor/main.h"
#include "keys.h"
#include <math.h>
#include <stdio.h>
@@ -28,19 +25,21 @@ page_shell(App *app, struct nk_context *ctx, int win_w, int win_h)
{
struct nk_command_buffer *cv = nk_window_get_canvas(ctx);
double now_ms;
double build, render, present;
float t;
int i;
if (!g_started) {
g_started = 1;
if (g_no_vsync) SDL_SetRenderVSync(app->ren, 0);
if (g_no_vsync) SDL_SetRenderVSync(reaktor_sdl_renderer(app), 0);
g_t0 = SDL_GetTicks();
g_cpu0 = reaktor_process_cpu_ms();
}
g_build_ms += app->build_ms_x100 / 100.0;
g_render_ms += app->render_ms_x100 / 100.0;
g_present_ms += app->present_ms_x100 / 100.0;
reaktor_frame_ms(app, &build, &render, &present);
g_build_ms += build;
g_render_ms += render;
g_present_ms += present;
g_work_ms = g_build_ms + g_render_ms + g_present_ms;
t = (float)(SDL_GetTicks() - g_t0) / 1000.0f;
@@ -101,7 +100,6 @@ page_shell(App *app, struct nk_context *ctx, int win_w, int win_h)
else g_due_ns = now;
}
app->dirty = 1;
reaktor_wake(app);
}
+5 -8
View File
@@ -1,9 +1,6 @@
#include <stdio.h>
#include "internal.h"
#include "declare.h"
#include "keys.h"
#include "reaktor/launch.h"
#include "reaktor/reaktor.h"
#include "reaktor/main.h"
#define TEXT_CAP 65536
@@ -11,7 +8,7 @@
static struct {
char text[TEXT_CAP];
int len;
char path[SC_PATH_CAP];
char path[520];
unsigned saved_hash;
int saved_len;
char status[160];
@@ -66,7 +63,7 @@ static void
load(const char *path)
{
size_t n = 0;
char *body = reaktor_read_file(path, &n);
char *body = (char *)SDL_LoadFile(path, &n);
if (!body) {
SDL_snprintf(g.status, sizeof(g.status), "Could not read %s", path);
@@ -76,13 +73,13 @@ load(const char *path)
SDL_snprintf(g.status, sizeof(g.status),
"%s is %.0f KB, and this editor holds %d KB",
path, (double)n / 1024.0, TEXT_CAP / 1024);
reaktor_free(body);
SDL_free(body);
return;
}
SDL_memcpy(g.text, body, n);
g.text[n] = '\0';
g.len = (int)n;
reaktor_free(body);
SDL_free(body);
SDL_strlcpy(g.path, path, sizeof(g.path));
g.saved_hash = hash_of(g.text, g.len);
+138 -93
View File
@@ -1,12 +1,48 @@
#include "internal.h"
#include "showcase.h"
#include "declare.h"
#include "reaktor/main.h"
#define TITLE_PX 16
#define GLYPH_STROKE 2.0f
#define BODY_PAD_X 20.0f
typedef struct shell_style { int items, colors, floats, vec2s, fonts; } shell_style;
static struct nk_rect g_ctl[3];
static int g_ctl_n;
static int g_show_contact;
static void
pop_style(struct nk_context *ctx, shell_style f)
{
int i;
for (i = 0; i < f.fonts; i++) nk_style_pop_font(ctx);
for (i = 0; i < f.vec2s; i++) nk_style_pop_vec2(ctx);
for (i = 0; i < f.floats; i++) nk_style_pop_float(ctx);
for (i = 0; i < f.colors; i++) nk_style_pop_color(ctx);
for (i = 0; i < f.items; i++) nk_style_pop_style_item(ctx);
}
static void
image_centered(struct nk_context *ctx, struct nk_image im, int px)
{
struct nk_rect b = nk_widget_bounds(ctx);
float s = (float)px;
struct nk_rect r = nk_rect(b.x + (b.w - s) * 0.5f,
b.y + (b.h - s) * 0.5f, s, s);
nk_draw_image(nk_window_get_canvas(ctx), r, &im, nk_rgb(255, 255, 255));
nk_spacing(ctx, 1);
}
static struct nk_color
text_main(void)
{
return reaktor_token("--text-main", nk_rgb(51, 51, 51));
}
static SDL_HitTestResult SDLCALL
window_hit_test(SDL_Window *win, const SDL_Point *pt, void *data)
{
App *app = (App *)data;
int w = 0, h = 0, i;
int left, right, top, bottom;
@@ -28,9 +64,10 @@ window_hit_test(SDL_Window *win, const SDL_Point *pt, void *data)
if (right) return SDL_HITTEST_RESIZE_RIGHT;
}
(void)data;
if (pt->y < TITLEBAR_H) {
for (i = 0; i < app->ctl_n; i++) {
struct nk_rect r = app->ctl[i];
for (i = 0; i < g_ctl_n; i++) {
struct nk_rect r = g_ctl[i];
const int m = 4;
if (pt->x >= r.x - m && pt->x <= r.x + r.w + m &&
pt->y >= r.y - m && pt->y <= r.y + r.h + m)
@@ -83,7 +120,7 @@ set_tab(App *app, int tab)
{
if (tab == sample_tab()) return;
g_tab = tab;
app->dirty = 1;
reaktor_wake(app);
}
static int
@@ -91,19 +128,19 @@ titlebar_button(App *app, struct nk_context *ctx, const char *glyph,
const char *name, int px)
{
struct nk_rect b = nk_widget_bounds(ctx);
style_frame f = { 0, 0, 0, 0, 0 };
shell_style f = { 0, 0, 0, 0, 0 };
unsigned char c[4];
struct nk_color clear = nk_rgba(0, 0, 0, 0);
struct nk_color wash = reaktor_style_token("--background-hover", c)
? col_of(c) : nk_rgba(255, 255, 255, 26);
? reaktor_col(c) : nk_rgba(255, 255, 255, 26);
char src[176];
float pad_x, pad_y;
int clicked;
hot_push(app, b, 1, 1);
reaktor_hot(app, b, 1, 1);
reaktor_note(app, REAKTOR_A11Y_BUTTON, name, NULL, 0, b);
if (app->ctl_n < (int)(sizeof(app->ctl) / sizeof(app->ctl[0])))
app->ctl[app->ctl_n++] = b;
if (g_ctl_n < (int)(sizeof(g_ctl) / sizeof(g_ctl[0])))
g_ctl[g_ctl_n++] = b;
nk_style_push_style_item(ctx, &ctx->style.button.normal,
nk_style_item_color(clear));
@@ -127,19 +164,21 @@ titlebar_button(App *app, struct nk_context *ctx, const char *glyph,
nk_vec2(pad_x, pad_y));
f.vec2s = 2;
if (app->dark) {
SDL_snprintf(src, sizeof(src),
"external/ionicons/src/svg/%s.svg?stroke=%s&sw=%.2f",
glyph, app->icon_hex, (double)GLYPH_STROKE);
if (reaktor_dark(app)) {
if (!reaktor_style_token("--text-muted", c)) {
c[0] = 0x6a; c[1] = 0x6a; c[2] = 0x6a;
}
} else {
SDL_snprintf(src, sizeof(src),
"external/ionicons/src/svg/%s.svg"
"?stroke=#%02x%02x%02x&sw=%.2f",
glyph, app->text.r, app->text.g, app->text.b,
(double)GLYPH_STROKE);
}
struct nk_color t = text_main();
clicked = nk_button_image_label(ctx, icon(app, src, px), "",
c[0] = t.r; c[1] = t.g; c[2] = t.b;
}
SDL_snprintf(src, sizeof(src),
"external/ionicons/src/svg/%s.svg"
"?stroke=#%02x%02x%02x&sw=%.2f",
glyph, c[0], c[1], c[2], (double)GLYPH_STROKE);
clicked = nk_button_image_label(ctx, reaktor_svg(app, src, px), "",
NK_TEXT_CENTERED);
pop_style(ctx, f);
return clicked;
@@ -149,10 +188,11 @@ static void
titlebar(App *app, struct nk_context *ctx, int win_w)
{
unsigned char c[4];
int maximised = (SDL_GetWindowFlags(app->win) & SDL_WINDOW_MAXIMIZED) != 0;
SDL_Window *win = reaktor_sdl_window(app);
int maximised = (SDL_GetWindowFlags(win) & SDL_WINDOW_MAXIMIZED) != 0;
struct nk_rect bar;
app->ctl_n = 0;
g_ctl_n = 0;
bar = nk_widget_bounds(ctx);
if (!nk_group_begin(ctx, "titlebar", NK_WINDOW_NO_SCROLLBAR)) return;
reaktor_note_push(app, REAKTOR_A11Y_GROUP, "Title bar", NULL, 0, bar);
@@ -163,16 +203,16 @@ titlebar(App *app, struct nk_context *ctx, int win_w)
nk_spacing(ctx, 1);
nk_layout_row_push(ctx, (float)MARK_SIZE);
image_centred(ctx, icon(app, REAKTOR_MARK, MARK_SIZE), MARK_SIZE);
image_centered(ctx, reaktor_svg(app, REAKTOR_MARK, MARK_SIZE), MARK_SIZE);
nk_layout_row_push(ctx, (float)(win_w - TITLE_PAD - MARK_SIZE -
3 * CTL_SIZE - 2 * 4 - 5 * 4));
{
nk_style_push_font(ctx, pick_font(app, TITLE_PX, 1));
if (app->dark && reaktor_style_token("--text-muted", c))
nk_style_push_color(ctx, &ctx->style.text.color, col_of(c));
nk_style_push_font(ctx, reaktor_font(app, TITLE_PX, 1));
if (reaktor_dark(app) && reaktor_style_token("--text-muted", c))
nk_style_push_color(ctx, &ctx->style.text.color, reaktor_col(c));
else
nk_style_push_color(ctx, &ctx->style.text.color, app->text);
nk_style_push_color(ctx, &ctx->style.text.color, text_main());
nk_style_push_vec2(ctx, &ctx->style.text.padding, nk_vec2(3.0f, 0.0f));
reaktor_note_here(app, ctx, REAKTOR_A11Y_LABEL, "Reaktor", 0);
nk_label(ctx, "Reaktor", NK_TEXT_LEFT);
@@ -183,15 +223,15 @@ titlebar(App *app, struct nk_context *ctx, int win_w)
nk_layout_row_push(ctx, (float)CTL_SIZE);
if (titlebar_button(app, ctx, "remove-outline", "Minimize", GLYPH_MINIMISE))
SDL_MinimizeWindow(app->win);
SDL_MinimizeWindow(win);
nk_layout_row_push(ctx, (float)CTL_SIZE);
if (titlebar_button(app, ctx,
maximised ? "copy-outline" : "square-outline",
maximised ? "Restore" : "Maximize",
GLYPH_MAXIMISE)) {
if (maximised) SDL_RestoreWindow(app->win);
else SDL_MaximizeWindow(app->win);
if (maximised) SDL_RestoreWindow(win);
else SDL_MaximizeWindow(win);
}
nk_layout_row_push(ctx, (float)CTL_SIZE);
@@ -231,28 +271,28 @@ login_card(App *app, struct nk_context *ctx, float body_x, float body_w,
float body_y, float body_h)
{
struct nk_rect at;
float card_h = card_height(app->show_contact);
float side = body_x + (body_w - (float)CARD_W) * 0.5f;
float card_h = card_height(g_show_contact);
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);
reaktor_fill_round(app, nk_window_get_canvas(ctx), at,
ctx->style.button.rounding, app->card_bg);
ctx->style.button.rounding,
reaktor_token("--background", nk_rgb(226, 226, 226)));
nk_style_push_style_item(ctx, &ctx->style.window.fixed_background,
nk_style_item_color(nk_rgba(0, 0, 0, 0)));
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){
@@ -292,13 +332,13 @@ login_card(App *app, struct nk_context *ctx, float body_x, float body_w,
.ml = CARD_PAD_X, .mr = CARD_PAD_X } });
if (reaktor_link(&(reaktor_link_spec){
.text = app->show_contact ? "hide contact" : "contact",
.text = g_show_contact ? "hide contact" : "contact",
.style = ".card-link",
.box = { .h = ROW_SMALL, .flags = REAKTOR_LAY_FILL_X,
.ml = CARD_PAD_X, .mr = CARD_PAD_X } }))
app->show_contact = !app->show_contact;
g_show_contact = !g_show_contact;
if (app->show_contact) {
if (g_show_contact) {
static const char *const lines[CONTACT_ROWS] = {
"support@reaktor.example",
"+44 20 7946 0958",
@@ -319,7 +359,7 @@ login_card(App *app, struct nk_context *ctx, float body_x, float body_w,
nk_style_pop_style_item(ctx);
}
static style_frame
static shell_style
push_strip_look(struct nk_context *ctx, struct nk_color fg, struct nk_color wash)
{
nk_style_push_style_item(ctx, &ctx->style.button.normal,
@@ -333,7 +373,7 @@ push_strip_look(struct nk_context *ctx, struct nk_color fg, struct nk_color wash
nk_style_push_color(ctx, &ctx->style.button.text_active, fg);
nk_style_push_float(ctx, &ctx->style.button.border, 0.0f);
nk_style_push_float(ctx, &ctx->style.button.rounding, 4.0f);
return (style_frame){ 3, 3, 2, 0, 0 };
return (shell_style){ 3, 3, 2, 0, 0 };
}
static struct nk_color
@@ -346,9 +386,9 @@ int
sample_option(App *app, struct nk_context *ctx, const char *label, float w,
int on)
{
struct nk_color fg = reaktor_token(on ? "--links" : "--text-muted", app->text);
struct nk_color fg = reaktor_token(on ? "--links" : "--text-muted", text_main());
struct nk_rect b;
style_frame look;
shell_style look;
unsigned id;
int hit;
@@ -359,7 +399,7 @@ sample_option(App *app, struct nk_context *ctx, const char *label, float w,
}
nk_layout_row_push(ctx, w);
b = nk_widget_bounds(ctx);
hot_push(app, b, 1, 1);
reaktor_hot(app, b, 1, 1);
look = push_strip_look(ctx, fg, strip_wash());
id = reaktor_note(app, REAKTOR_A11Y_RADIO, label, NULL,
@@ -374,19 +414,8 @@ sample_option(App *app, struct nk_context *ctx, const char *label, float w,
static void
toggle_titlebar(App *app)
{
#ifdef __APPLE__
if (app->borderless_lock_frames == 0) {
app->borderless_pending = 1;
app->dirty = 1;
}
#else
app->borderless = !app->borderless;
SDL_SetWindowBordered(app->win, app->borderless ? false : true);
SDL_SetWindowHitTest(app->win, app->borderless ? window_hit_test : NULL,
app->borderless ? app : NULL);
app->ctl_n = 0;
app->dirty = 1;
#endif
reaktor_set_borderless(app, !reaktor_borderless(app));
g_ctl_n = 0;
}
#endif
@@ -407,7 +436,7 @@ nav(App *app, float w, float h)
const char *key_of[TAB_COUNT];
char all[160];
unsigned char narrow = w < (float)NAV_W;
int tab = sample_tab(), scheme = app->theme_mode, i;
int tab = sample_tab(), scheme = (int)reaktor_get_theme(app), i;
for (i = 0; i < TAB_COUNT; i++) {
sample_tab_keys(i, keys[i], (int)sizeof(keys[i]));
@@ -437,7 +466,7 @@ nav(App *app, float w, float h)
const char *bar[1];
int pick = -1;
bar[0] = app->borderless ? "Native titlebar" : "Custom titlebar";
bar[0] = reaktor_borderless(app) ? "Native titlebar" : "Custom titlebar";
if (reaktor_sidebar(&(reaktor_sidebar_spec){
.items = bar, .icons = bar_icon, .count = 1, .chosen = &pick,
.name = "Window", .kind = REAKTOR_NAV_ACTIONS,
@@ -460,8 +489,8 @@ static void
tray_show(App *app, int checked, void *user)
{
(void)checked; (void)user;
SDL_RestoreWindow(app->win);
SDL_RaiseWindow(app->win);
SDL_RestoreWindow(reaktor_sdl_window(app));
SDL_RaiseWindow(reaktor_sdl_window(app));
}
static void
@@ -519,37 +548,57 @@ showcase_tray_show(App *app, int on)
}
}
static void
body_metrics_push(struct nk_context *ctx, float pad_x)
{
nk_style_push_vec2(ctx, &ctx->style.window.group_padding,
nk_vec2(pad_x, 12.0f));
nk_style_push_vec2(ctx, &ctx->style.window.scrollbar_size,
nk_vec2(ctx->style.window.scrollbar_size.x, 0.0f));
}
static void
body_metrics_pop(struct nk_context *ctx)
{
nk_style_pop_vec2(ctx);
nk_style_pop_vec2(ctx);
}
static void
page_shell(App *app, struct nk_context *ctx, int win_w, int win_h)
{
float top = app->borderless ? (float)TITLEBAR_H : 0.0f;
int framed = reaktor_borderless(app);
float top = framed ? (float)TITLEBAR_H : 0.0f;
float nav_w = win_w < NAV_WIDE_MIN ? (float)NAV_W_NARROW : (float)NAV_W;
float body_h = (float)win_h - top;
struct nk_rect panel = nk_rect(nav_w, top + (app->borderless ? 0.0f : PANEL_GAP),
struct nk_rect panel = nk_rect(nav_w, top + (framed ? 0.0f : PANEL_GAP),
(float)win_w - nav_w - PANEL_GAP, 0.0f);
struct nk_rect body;
struct nk_rect body, reveal;
struct nk_color card = reaktor_token("--background", nk_rgb(226, 226, 226));
reaktor_theme scheme = reaktor_get_theme(app);
panel.h = (float)win_h - panel.y - PANEL_GAP;
if (panel.w < 1.0f) panel.w = 1.0f;
if (panel.h < 1.0f) panel.h = 1.0f;
if (body_h < 1.0f) body_h = 1.0f;
body = nk_rect(panel.x, panel.y + PANEL_R * 0.5f, panel.w, panel.h - PANEL_R);
reaktor_tray_check(app, TRAY_SYSTEM, app->theme_mode == REAKTOR_THEME_SYSTEM);
reaktor_tray_check(app, TRAY_LIGHT, app->theme_mode == REAKTOR_THEME_LIGHT);
reaktor_tray_check(app, TRAY_DARK, app->theme_mode == REAKTOR_THEME_DARK);
reaktor_tray_check(app, TRAY_SYSTEM, scheme == REAKTOR_THEME_SYSTEM);
reaktor_tray_check(app, TRAY_LIGHT, scheme == REAKTOR_THEME_LIGHT);
reaktor_tray_check(app, TRAY_DARK, scheme == REAKTOR_THEME_DARK);
{
struct nk_command_buffer *cv = nk_window_get_canvas(ctx);
nk_fill_rect(cv, nk_rect(0.0f, 0.0f, (float)win_w, (float)win_h), 0.0f,
app->card_bg);
reaktor_fill_round(app, cv, panel, PANEL_R, app->page);
card);
reaktor_fill_round(app, cv, panel, PANEL_R,
reaktor_token("--background-body", nk_rgb(247, 247, 247)));
}
nk_layout_space_begin(ctx, NK_STATIC, (float)win_h, 3);
if (app->borderless) {
if (framed) {
nk_style_push_style_item(ctx, &ctx->style.window.fixed_background,
nk_style_item_color(app->card_bg));
nk_style_item_color(card));
nk_layout_space_push(ctx, nk_rect(0, 0, (float)win_w,
(float)TITLEBAR_H));
titlebar(app, ctx, win_w);
@@ -557,7 +606,7 @@ page_shell(App *app, struct nk_context *ctx, int win_w, int win_h)
}
nk_style_push_style_item(ctx, &ctx->style.window.fixed_background,
nk_style_item_color(app->card_bg));
nk_style_item_color(card));
nk_style_push_vec2(ctx, &ctx->style.window.group_padding, nk_vec2(0, 0));
nk_layout_space_push(ctx, nk_rect(0, top, nav_w, body_h));
if (nk_group_begin(ctx, "nav", NK_WINDOW_NO_SCROLLBAR)) {
@@ -588,10 +637,9 @@ page_shell(App *app, struct nk_context *ctx, int win_w, int win_h)
reaktor_wake(app);
}
}
app->body_rect = body;
if (app->focus_scroll) {
if (reaktor_focus_scroll(app, &reveal)) {
const float air = 12.0f;
struct nk_rect r = app->focus_scroll_rect;
struct nk_rect r = reveal;
nk_uint sx, sy;
float dy = 0.0f;
@@ -602,16 +650,12 @@ page_shell(App *app, struct nk_context *ctx, int win_w, int win_h)
dy = r.y + r.h - (body.y + body.h - air);
if ((float)sy + dy < 0.0f) dy = -(float)sy;
nk_group_set_scroll(ctx, "body", sx, (nk_uint)((float)sy + dy));
app->focus_scroll = 0;
app->dirty = 1;
reaktor_wake(app);
}
nk_style_push_style_item(ctx, &ctx->style.window.fixed_background,
nk_style_item_hide());
nk_style_push_vec2(ctx, &ctx->style.window.group_padding,
nk_vec2(20.0f, 12.0f));
nk_style_push_vec2(ctx, &ctx->style.window.scrollbar_size,
nk_vec2(ctx->style.window.scrollbar_size.x, 0.0f));
body_metrics_push(ctx, BODY_PAD_X);
if (nk_group_begin(ctx, "body", 0)) {
struct nk_vec2 sz = nk_window_get_content_region_size(ctx);
@@ -622,22 +666,23 @@ page_shell(App *app, struct nk_context *ctx, int win_w, int win_h)
nk_push_scissor(cv, nk_rect(c.x - 2.0f, c.y, c.w + 4.0f, c.h));
}
nk_style_pop_vec2(ctx);
nk_style_pop_vec2(ctx);
body_metrics_pop(ctx);
nk_style_pop_style_item(ctx);
hot_push(app, app->body_rect, 0, 0);
reaktor_hot(app, body, 0, 0);
app->page_node =
reaktor_note_push(app, REAKTOR_A11Y_GROUP,
reaktor_tab_names[sample_tab()], NULL, 0,
app->body_rect);
reaktor_focus_area(app, body,
reaktor_note_push(app, REAKTOR_A11Y_GROUP,
reaktor_tab_names[sample_tab()],
NULL, 0, body));
reaktor_showcase_page(app, ctx, sample_tab(), sz.x, sz.y);
reaktor_note_pop(app);
/* nk_group_end sets the bar this far past the content: mid-gutter. */
body_metrics_push(ctx, BODY_PAD_X * 0.5f);
nk_group_end(ctx);
body_metrics_pop(ctx);
} else {
nk_style_pop_vec2(ctx);
nk_style_pop_vec2(ctx);
body_metrics_pop(ctx);
nk_style_pop_style_item(ctx);
}
-2
View File
@@ -1,6 +1,4 @@
#include "internal.h"
#include "showcase.h"
#include "keys.h"
enum {
ACT_NEXT_PAGE = 1,
+631 -37
View File
@@ -5,20 +5,14 @@
#include <SDL3/SDL.h>
#include "nk_common.h"
#include "ui.h"
#include "showcase.h"
#include "declare.h"
#include "anim.h"
#include "locale.h"
#include "style.h"
#define ROW 30.0f
#define ROW_TALL 34.0f
#define ROW_SMALL 22.0f
const char *const reaktor_rss_names[RSS_STEPS] = {
static const char *const rss_names[REAKTOR_RSS_STEPS] = {
"before any of it", "SDL_Init(VIDEO)", "window and renderer",
"window icon", "Nuklear context", "font atlas", "stylesheets"
};
@@ -233,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);
@@ -679,11 +674,12 @@ page_inputs(App *app, struct nk_context *ctx, showcase_state *s)
int i;
REAKTOR_COLUMN(.gap = ctx->style.window.spacing.y) {
REAKTOR_ROW(.h = ROW_TALL, .gap = ctx->style.window.spacing.x) {
REAKTOR_ROW(.h = ROW_TALL, .gap = ctx->style.window.spacing.x,
.flags = REAKTOR_LAY_FILL_X) {
REAKTOR_COMBO(.label = sizes[s->combo_size], .name = "Size",
.body_h = 130.0f,
.box = { .w = 440.0f,
.flags = REAKTOR_LAY_FILL_Y }) {
.box = { .flags = REAKTOR_LAY_FILL_X |
REAKTOR_LAY_FILL_Y }) {
nk_layout_row_dynamic(ctx, 26.0f, 1);
for (i = 0; i < 3; i++)
if (reaktor_combo_item(sizes[i], i == s->combo_size))
@@ -692,21 +688,22 @@ page_inputs(App *app, struct nk_context *ctx, showcase_state *s)
REAKTOR_COMBO(.label = sizes[s->combo_symbol],
.name = "Size, with a symbol",
.body_h = 130.0f, .disc = 1,
.box = { .w = 440.0f,
.flags = REAKTOR_LAY_FILL_Y }) {
.box = { .flags = REAKTOR_LAY_FILL_X |
REAKTOR_LAY_FILL_Y }) {
nk_layout_row_dynamic(ctx, 26.0f, 1);
for (i = 0; i < 3; i++)
if (reaktor_combo_item(sizes[i], i == s->combo_symbol))
s->combo_symbol = i;
}
}
REAKTOR_ROW(.h = ROW_TALL, .gap = ctx->style.window.spacing.x) {
REAKTOR_ROW(.h = ROW_TALL, .gap = ctx->style.window.spacing.x,
.flags = REAKTOR_LAY_FILL_X) {
struct nk_color tint = nk_rgb_cf(s->tint);
REAKTOR_COMBO(.name = "Tint", .body_h = 150.0f,
.swatch = &tint,
.box = { .w = 440.0f,
.flags = REAKTOR_LAY_FILL_Y }) {
.box = { .flags = REAKTOR_LAY_FILL_X |
REAKTOR_LAY_FILL_Y }) {
nk_layout_row_dynamic(ctx, 26.0f, 1);
reaktor_hot_follow(app, nk_widget_bounds(ctx), 0);
nk_property_float(ctx, "R:", 0.0f, &s->tint.r, 1.0f,
@@ -720,8 +717,8 @@ page_inputs(App *app, struct nk_context *ctx, showcase_state *s)
}
REAKTOR_COMBO(.label = "Anything at all",
.name = "Anything at all", .body_h = 130.0f,
.box = { .w = 440.0f,
.flags = REAKTOR_LAY_FILL_Y }) {
.box = { .flags = REAKTOR_LAY_FILL_X |
REAKTOR_LAY_FILL_Y }) {
nk_layout_row_dynamic(ctx, 26.0f, 1);
nk_label(ctx, "A combo is just a popup", NK_TEXT_LEFT);
reaktor_slider_bar(app, ctx, 0, &s->slider_f, 0.0f, 1.0f,
@@ -1865,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++)
@@ -1920,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",
@@ -1934,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);
@@ -1944,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),
@@ -1962,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) {
@@ -1987,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);
}
@@ -2262,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);
}
@@ -2445,16 +3039,16 @@ page_diagnostics(App *app, struct nk_context *ctx, showcase_state *st)
int i;
SDL_snprintf(v, sizeof(v), "%.1f MB private, %.1f MB resident",
d.priv_at[RSS_ENTRY] / 1048576.0,
d.rss_at[RSS_ENTRY] / 1048576.0);
d.priv_at[REAKTOR_RSS_ENTRY] / 1048576.0,
d.rss_at[REAKTOR_RSS_ENTRY] / 1048576.0);
DIAG_ROWS(ctx) {
diag_row(app, ctx, reaktor_rss_names[RSS_ENTRY], v);
for (i = RSS_ENTRY + 1; i < RSS_STEPS; i++) {
diag_row(app, ctx, rss_names[REAKTOR_RSS_ENTRY], v);
for (i = REAKTOR_RSS_ENTRY + 1; i < REAKTOR_RSS_STEPS; i++) {
double dp = (d.priv_at[i] - (double)d.priv_at[i - 1]) / 1048576.0;
double dr = (d.rss_at[i] - (double)d.rss_at[i - 1]) / 1048576.0;
SDL_snprintf(v, sizeof(v), "%+.1f MB private %+.1f MB resident",
dp, dr);
diag_row(app, ctx, reaktor_rss_names[i], v);
diag_row(app, ctx, rss_names[i], v);
}
}
}
+16 -1
View File
@@ -1,7 +1,16 @@
#ifndef REAKTOR_SHOWCASE_H
#define REAKTOR_SHOWCASE_H
#include "reaktor/launch.h"
#include "reaktor/reaktor.h"
#define SC_TEXT_CAP 64
#define SC_BOX_CAP 512
#define SC_SERIES_N 32
#define SC_LIST_N 64
#define SC_PATH_CAP 520
#define WINDOW_WIDTH 1100
#define WINDOW_HEIGHT 680
enum {
TAB_LOGIN = 0,
@@ -75,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];
+1 -4
View File
@@ -1,8 +1,5 @@
#include "internal.h"
#include "declare.h"
#include "reaktor/launch.h"
#include "reaktor/reaktor.h"
#include "reaktor/main.h"
#include "keys.h"
static void
page_shell(App *app, struct nk_context *ctx, int win_w, int win_h)
+12 -16
View File
@@ -41,8 +41,8 @@ enum {
KEY_CLICK_AGAIN
};
extern size_t reaktor_rss[RSS_STEPS];
extern size_t reaktor_priv[RSS_STEPS];
extern size_t reaktor_rss[REAKTOR_RSS_STEPS];
extern size_t reaktor_priv[REAKTOR_RSS_STEPS];
void reaktor_rss_mark(int step);
#define GLYPH_STROKE 2.0f
@@ -124,14 +124,19 @@ 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__
int borderless_pending;
int borderless_lock_frames;
#endif
struct nk_rect ctl[3];
int ctl_n;
const char *shot_path;
const char *dump_path;
@@ -151,7 +156,7 @@ struct App {
int ime_valid;
SDL_AtomicInt file_ready, file_done;
char file_answer[SC_PATH_CAP];
char file_answer[520];
int file_pending;
int theme_mode;
@@ -172,7 +177,6 @@ struct App {
unsigned char hot_last_repaint;
int dirty;
int show_contact;
struct input_queue {
SDL_Event *ev;
@@ -222,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;
@@ -242,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]);
@@ -321,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);
@@ -362,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);
@@ -373,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"
@@ -398,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);
+1 -126
View File
@@ -3,131 +3,6 @@
#include "nk_common.h"
#include "a11y.h"
#ifndef REAKTOR_APP_FWD
#define REAKTOR_APP_FWD
typedef struct App App;
#endif
enum {
RSS_ENTRY,
RSS_SDL,
RSS_WINDOW,
RSS_ICON,
RSS_NUKLEAR,
RSS_FONT,
RSS_STYLE,
RSS_STEPS
};
extern const char *const reaktor_rss_names[RSS_STEPS];
#define SC_TEXT_CAP 64
#define SC_BOX_CAP 512
#define SC_SERIES_N 32
#define SC_LIST_N 64
#define SC_PATH_CAP 520
struct nk_color reaktor_col(const unsigned char rgba[4]);
struct nk_color reaktor_token(const char *name,
struct nk_color def);
struct nk_color reaktor_visible(struct nk_color want,
struct nk_color behind,
struct nk_color fallback);
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);
void reaktor_fill_round(App *app, struct nk_command_buffer *cv,
struct nk_rect b, float rounding, struct nk_color col);
void reaktor_edge_round(App *app, struct nk_command_buffer *cv,
struct nk_rect b, float rounding, float width,
struct nk_color col);
struct nk_color reaktor_on(struct nk_color bg);
void reaktor_hot(App *app, struct nk_rect r, int cursor, int repaint);
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);
void reaktor_slider_bar(App *app, struct nk_context *ctx, unsigned id,
float *val, float lo, float hi, float step);
void reaktor_progress_bar(App *app, struct nk_context *ctx, nk_size *cur,
nk_size max, int modifiable);
void reaktor_chevron_at(App *app, struct nk_context *ctx, struct nk_rect slot,
const char *name, struct nk_color col);
int reaktor_button_accent(App *app, struct nk_context *ctx, const char *label);
const struct nk_user_font *reaktor_style_font(App *app,
const char *selector,
int px, int bold);
float reaktor_popup_rounding(void);
#define REAKTOR_MENU_ROW 22.0f
#define REAKTOR_MENU_GAP 2.0f
void reaktor_menu_style_push(struct nk_context *ctx);
void reaktor_menu_style_pop(struct nk_context *ctx);
float reaktor_menu_height(int rows);
void reaktor_menu_edge(App *app, struct nk_context *ctx);
typedef struct reaktor_toast_spec {
const char *text;
const char *icon;
const char *action;
void (*on_action)(App *app, void *user);
void (*content)(App *app, struct nk_context *ctx, void *user);
float content_w;
void *user;
int timeout_ms;
int no_close;
} reaktor_toast_spec;
/* Main thread; hooks get the main window's App. */
void reaktor_toast(App *app, const reaktor_toast_spec *spec);
int reaktor_menu_item(App *app, struct nk_context *ctx, const char *label,
const char *accel, int contextual);
unsigned reaktor_note(App *app, unsigned char role, const char *name,
const char *value, unsigned state,
struct nk_rect bounds);
unsigned reaktor_note_push(App *app, unsigned char role, const char *name,
const char *value, unsigned state,
struct nk_rect bounds);
void reaktor_note_pop(App *app);
int reaktor_focus_activated(App *app, unsigned id);
void reaktor_note_keys(App *app, unsigned id, const char *keys);
void reaktor_note_value(App *app, unsigned id, const char *value);
void reaktor_note_bounds(App *app, unsigned id, struct nk_rect r);
unsigned reaktor_note_here(App *app, struct nk_context *ctx,
unsigned char role, const char *name,
unsigned state);
int reaktor_file_open(App *app);
typedef struct reaktor_diag {
const char *renderer;
const char *mode;
const char *frame_rate;
const char *drag_rate;
const char *font;
int vsync, dark, sheets;
const char *aa;
float scale, style_ms, build_ms, render_ms, present_ms;
float frame_gap_ms;
float cpu_ms_per_frame;
int hover_gap_ms;
unsigned long nk_bytes, nk_used, icon_bytes;
unsigned long rss_bytes, private_bytes;
int icons;
int atlas_w, atlas_h, atlas_bpp;
unsigned long rss_at[RSS_STEPS];
unsigned long priv_at[RSS_STEPS];
} reaktor_diag;
void reaktor_diagnostics(App *app, reaktor_diag *out);
#include "reaktor/ui.h"
#endif
+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
+4
View File
@@ -0,0 +1,4 @@
execute_process(COMMAND "${AR}" -M INPUT_FILE "${MRI}" RESULT_VARIABLE _rc)
if(_rc)
message(FATAL_ERROR "merging the archives failed: ${_rc}")
endif()
+9
View File
@@ -0,0 +1,9 @@
prefix=${pcfiledir}/../..
includedir=${prefix}/include
libdir=${prefix}/lib
Name: reaktor
Description: A Nuklear-powered GUI library for C
Version: @PROJECT_VERSION@
Cflags: -I${includedir}
Libs: -L${libdir} -lreaktor @REAKTOR_PC_LIBS@
+12
View File
@@ -0,0 +1,12 @@
get_filename_component(_reaktor_prefix "${CMAKE_CURRENT_LIST_DIR}/../../.." ABSOLUTE)
if(NOT TARGET reaktor::reaktor)
add_library(reaktor::reaktor STATIC IMPORTED)
set_target_properties(reaktor::reaktor PROPERTIES
IMPORTED_LOCATION "${_reaktor_prefix}/lib/@REAKTOR_LIB_NAME@"
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
INTERFACE_INCLUDE_DIRECTORIES "${_reaktor_prefix}/include"
INTERFACE_LINK_LIBRARIES "@REAKTOR_LINK_LIBS@"
INTERFACE_LINK_DIRECTORIES "@REAKTOR_LINK_DIRS@"
INTERFACE_LINK_OPTIONS "@REAKTOR_LINK_OPTIONS@")
endif()
unset(_reaktor_prefix)
-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;