Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50463e6067 | ||
|
|
02e960d7d1 | ||
|
|
46abd60e66 | ||
|
|
1b1741a5d7 | ||
|
|
3d1fbd4318 | ||
|
|
c9ba436510 | ||
|
|
19bd89b17b | ||
|
|
38cba09d94 | ||
|
|
bdb12797d2 | ||
|
|
32239f722e | ||
|
|
d8dfc972e2 | ||
|
|
3a38d59805 | ||
|
|
df86d94d23 | ||
|
|
4971409d8b | ||
|
|
169e1756c1 | ||
|
|
5f59fb775c | ||
|
|
9468a0afe9 | ||
|
|
1f5190397d | ||
|
|
67852da9e9 | ||
|
|
7875551ec5 | ||
|
|
8aa4a10ace | ||
|
|
8025c726fd | ||
|
|
bd78a107d2 | ||
|
|
0b8ff16b3a | ||
|
|
145ca650ed | ||
|
|
9db3ae438e | ||
|
|
5445de7c00 | ||
|
|
4d7979ac51 | ||
|
|
a5b6f30429 | ||
|
|
6a85509733 | ||
|
|
7e61f03012 |
@@ -47,6 +47,16 @@ jobs:
|
||||
submodules: recursive
|
||||
persist-credentials: false
|
||||
|
||||
# The build folder keeps CMake's checks, which ccache cannot: they link.
|
||||
- name: Restore the build cache
|
||||
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
|
||||
with:
|
||||
path: |
|
||||
.ccache
|
||||
build
|
||||
key: build-${{ matrix.os }}-${{ matrix.version }}-${{ matrix.arch }}-${{ github.run_id }}
|
||||
restore-keys: build-${{ matrix.os }}-${{ matrix.version }}-${{ matrix.arch }}-
|
||||
|
||||
- name: Start VM
|
||||
id: vm
|
||||
uses: cross-platform-actions/action@e0b9770014ba65d5e0815f15b74031c3a635f641 # v1.6.0
|
||||
@@ -66,16 +76,16 @@ jobs:
|
||||
case "$(uname -s)" in
|
||||
FreeBSD)
|
||||
sudo env IGNORE_OSVERSION=yes pkg install -y \
|
||||
cmake-core ninja pkgconf dbus xorg-vfbserver xorgproto \
|
||||
cmake-core ninja ccache pkgconf dbus xorg-vfbserver xorgproto \
|
||||
libX11 libXext libXcursor libXi libXfixes libXrandr libXrender libXtst \
|
||||
libxkbcommon wayland wayland-protocols libglvnd </dev/null
|
||||
;;
|
||||
OpenBSD)
|
||||
sudo pkg_add -I cmake-core ninja dbus libxkbcommon wayland wayland-protocols </dev/null
|
||||
sudo pkg_add -I cmake-core ninja ccache dbus libxkbcommon wayland wayland-protocols </dev/null
|
||||
;;
|
||||
NetBSD)
|
||||
sudo -E pkgin -y update </dev/null
|
||||
sudo -E pkgin -y install cmake ninja-build pkgconf dbus libxkbcommon wayland wayland-protocols </dev/null
|
||||
sudo -E pkgin -y install cmake ninja-build ccache pkgconf dbus libxkbcommon wayland wayland-protocols </dev/null
|
||||
;;
|
||||
esac
|
||||
|
||||
@@ -90,7 +100,11 @@ jobs:
|
||||
uname -a
|
||||
cc --version
|
||||
cmake --version
|
||||
./build.sh </dev/null
|
||||
CCACHE_DIR=$PWD/.ccache CCACHE_BASEDIR=$PWD CCACHE_MAXSIZE=1G
|
||||
export CCACHE_DIR CCACHE_BASEDIR CCACHE_MAXSIZE
|
||||
ccache -z
|
||||
./build.sh -- -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache </dev/null
|
||||
ccache -s
|
||||
|
||||
- name: Console tests
|
||||
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
|
||||
@@ -226,7 +240,15 @@ jobs:
|
||||
for f in build/CMakeCache.txt build/CMakeFiles/CMakeConfigureLog.yaml; do
|
||||
if [ -f "$f" ]; then cp "$f" smoke/; fi
|
||||
done
|
||||
rm -rf build
|
||||
|
||||
- name: Save the build cache
|
||||
if: ${{ always() && steps.build.outcome == 'success' }}
|
||||
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
|
||||
with:
|
||||
path: |
|
||||
.ccache
|
||||
build
|
||||
key: build-${{ matrix.os }}-${{ matrix.version }}-${{ matrix.arch }}-${{ github.run_id }}
|
||||
|
||||
- name: Upload the package
|
||||
if: ${{ !cancelled() && steps.package.outcome == 'success' }}
|
||||
|
||||
@@ -54,7 +54,7 @@ jobs:
|
||||
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 external/bamboocss/LICENSE "dist/$name/licenses/bamboocss.txt"
|
||||
cp assets/fonts/Aileron-Notice.txt assets/fonts/MPLUS1p-Notice.txt \
|
||||
"dist/$name/licenses/"
|
||||
cp docs/NOTICE.md "dist/$name/"
|
||||
|
||||
@@ -13,12 +13,6 @@
|
||||
[submodule "external/lcui"]
|
||||
path = external/lcui
|
||||
url = https://github.com/lc-soft/LCUI.git
|
||||
[submodule "external/tinycss"]
|
||||
path = external/tinycss
|
||||
url = https://github.com/ihsan6133/tiny.css.git
|
||||
[submodule "external/simplecss"]
|
||||
path = external/simplecss
|
||||
url = https://github.com/kevquirk/simple.css
|
||||
[submodule "external/onlay"]
|
||||
path = external/onlay
|
||||
url = https://github.com/Alpaq92/Onlay.git
|
||||
@@ -34,3 +28,12 @@
|
||||
[submodule "external/mglibs"]
|
||||
path = external/mglibs
|
||||
url = https://github.com/mattiasgustavsson/libs.git
|
||||
[submodule "external/libharu"]
|
||||
path = external/libharu
|
||||
url = https://github.com/libharu/libharu.git
|
||||
[submodule "external/watercss"]
|
||||
path = external/watercss
|
||||
url = https://github.com/kognise/water.css
|
||||
[submodule "external/bamboocss"]
|
||||
path = external/bamboocss
|
||||
url = https://github.com/rilwis/bamboo
|
||||
|
||||
@@ -109,11 +109,11 @@ regression oracle for every layout or style change.
|
||||
|
||||
- Dependencies are git submodules under `external/`, read as they ship. Never
|
||||
transcribe a value out of one, and never generate a header from one. The one
|
||||
exception is `REAKTOR_BUILTINS` in CMakeLists.txt: tiny.css's three sheets
|
||||
and the seven Ionicons the widgets draw (three chevrons, three discs, the
|
||||
exception is `REAKTOR_BUILTINS` in CMakeLists.txt: Water.css's two palettes
|
||||
and its `src/parts/`, and the seven Ionicons the widgets draw (three chevrons, three discs, the
|
||||
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.
|
||||
rest of Ionicons, not Bamboo.
|
||||
- Applications see only `include/reaktor/`. The samples include
|
||||
`reaktor/reaktor.h` and `reaktor/main.h`, nothing from `core/`, and
|
||||
`App` is opaque to them; what a sample needs becomes a public call there.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(reaktor VERSION 0.5.1 LANGUAGES C CXX)
|
||||
project(reaktor VERSION 0.6.0 LANGUAGES C CXX)
|
||||
|
||||
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
||||
set(_reaktor_top ON)
|
||||
@@ -149,9 +149,17 @@ set(REAKTOR_BUILTINS
|
||||
external/ionicons/src/svg/radio-button-off.svg
|
||||
external/ionicons/src/svg/close-outline.svg
|
||||
assets/css/reaktor.css
|
||||
external/tinycss/src/core.css
|
||||
external/tinycss/src/variables-light.css
|
||||
external/tinycss/src/variables-dark.css)
|
||||
external/watercss/src/parts/_core.css
|
||||
external/watercss/src/parts/_base.css
|
||||
external/watercss/src/parts/_typography.css
|
||||
external/watercss/src/parts/_forms.css
|
||||
external/watercss/src/parts/_range.css
|
||||
external/watercss/src/parts/_links.css
|
||||
external/watercss/src/parts/_code.css
|
||||
external/watercss/src/parts/_misc.css
|
||||
external/watercss/src/parts/_print.css
|
||||
external/watercss/src/variables-light.css
|
||||
external/watercss/src/variables-dark.css)
|
||||
set(_gen "/* Generated by CMakeLists.txt from REAKTOR_BUILTINS. */\n#include \"util.h\"\n\n")
|
||||
set(_rows "")
|
||||
set(_n 0)
|
||||
@@ -423,6 +431,106 @@ else()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
option(REAKTOR_SETTINGS "Settings kept between runs, in settings.conf" ON)
|
||||
option(REAKTOR_TRAY "A tray icon with a menu" ON)
|
||||
option(REAKTOR_POPUP_WINDOWS "Menus in windows of their own, past the main window's edge" ON)
|
||||
option(REAKTOR_INSPECTOR "The Inspector: tree, box, style, frame and log of a running app" ON)
|
||||
|
||||
foreach(_m settings:REAKTOR_SETTINGS:settings tray:REAKTOR_TRAY:tray
|
||||
popups:REAKTOR_POPUP_WINDOWS:popup inspector:REAKTOR_INSPECTOR:inspector)
|
||||
string(REPLACE ":" ";" _m "${_m}")
|
||||
list(GET _m 0 _name)
|
||||
list(GET _m 1 _opt)
|
||||
list(GET _m 2 _file)
|
||||
add_library(reaktor_${_name}_none INTERFACE)
|
||||
target_sources(reaktor_${_name}_none INTERFACE
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/runtime/${_file}_none.c")
|
||||
add_library(reaktor_${_name} INTERFACE)
|
||||
if(${_opt})
|
||||
target_sources(reaktor_${_name} INTERFACE
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/runtime/${_file}.c")
|
||||
else()
|
||||
target_link_libraries(reaktor_${_name} INTERFACE reaktor_${_name}_none)
|
||||
message(STATUS "${_name}: off")
|
||||
endif()
|
||||
endforeach()
|
||||
if(REAKTOR_SETTINGS)
|
||||
target_include_directories(reaktor_settings INTERFACE "${TP}/mglibs")
|
||||
if(EMSCRIPTEN)
|
||||
target_link_options(reaktor_settings INTERFACE -lidbfs.js
|
||||
"SHELL:--pre-js ${CMAKE_CURRENT_SOURCE_DIR}/tools/web-pre.js")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
option(REAKTOR_NOTIFY "System notifications: a toast, a D-Bus notification, the browser's" ON)
|
||||
|
||||
set(_notify "${CMAKE_CURRENT_SOURCE_DIR}/platform/notify")
|
||||
add_library(reaktor_notify_none INTERFACE)
|
||||
target_sources(reaktor_notify_none INTERFACE "${_notify}/notify_none.c")
|
||||
add_library(reaktor_notify INTERFACE)
|
||||
if(NOT REAKTOR_NOTIFY)
|
||||
target_link_libraries(reaktor_notify INTERFACE reaktor_notify_none)
|
||||
message(STATUS "notify: off")
|
||||
else()
|
||||
target_sources(reaktor_notify INTERFACE "${_notify}/notify.c")
|
||||
if(WIN32 AND NOT EMSCRIPTEN)
|
||||
target_link_libraries(reaktor_notify INTERFACE shell32)
|
||||
elseif(APPLE)
|
||||
enable_language(OBJC)
|
||||
add_library(reaktor_notify_macos OBJECT "${_notify}/notify_macos.m")
|
||||
target_compile_options(reaktor_notify_macos PRIVATE -fobjc-arc)
|
||||
target_sources(reaktor_notify INTERFACE "$<TARGET_OBJECTS:reaktor_notify_macos>")
|
||||
target_link_libraries(reaktor_notify INTERFACE
|
||||
"-framework Foundation" "-framework UserNotifications")
|
||||
elseif(NOT EMSCRIPTEN)
|
||||
find_package(PkgConfig QUIET)
|
||||
if(PkgConfig_FOUND AND NOT TARGET PkgConfig::REAKTOR_DBUS)
|
||||
pkg_check_modules(REAKTOR_DBUS QUIET IMPORTED_TARGET dbus-1)
|
||||
endif()
|
||||
if(TARGET PkgConfig::REAKTOR_DBUS)
|
||||
target_compile_definitions(reaktor_notify INTERFACE REAKTOR_HAVE_DBUS)
|
||||
target_link_libraries(reaktor_notify INTERFACE PkgConfig::REAKTOR_DBUS)
|
||||
else()
|
||||
message(STATUS "notify: no dbus-1; notifications are not sent")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
option(REAKTOR_PRINT "Printing and PDF export, through libHaru" ON)
|
||||
|
||||
add_library(reaktor_print_none INTERFACE)
|
||||
target_sources(reaktor_print_none INTERFACE
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/runtime/print_none.c")
|
||||
add_library(reaktor_print INTERFACE)
|
||||
if(NOT REAKTOR_PRINT OR EMSCRIPTEN)
|
||||
target_link_libraries(reaktor_print INTERFACE reaktor_print_none)
|
||||
message(STATUS "print: off")
|
||||
else()
|
||||
file(GLOB _hpdf_src CONFIGURE_DEPENDS "${TP}/libharu/src/hpdf_*.c")
|
||||
configure_file("${TP}/libharu/include/hpdf_config.h.cmake"
|
||||
"${CMAKE_BINARY_DIR}/hpdf/hpdf_config.h")
|
||||
add_library(hpdf STATIC ${_hpdf_src})
|
||||
target_include_directories(hpdf PUBLIC "${TP}/libharu/include" "${CMAKE_BINARY_DIR}/hpdf")
|
||||
if(MSVC)
|
||||
target_compile_options(hpdf PRIVATE /w)
|
||||
target_compile_definitions(hpdf PRIVATE _CRT_SECURE_NO_WARNINGS)
|
||||
else()
|
||||
target_compile_options(hpdf PRIVATE -w)
|
||||
target_link_libraries(hpdf PUBLIC m)
|
||||
endif()
|
||||
target_sources(reaktor_print INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/runtime/print.c")
|
||||
target_link_libraries(reaktor_print INTERFACE hpdf plutovg)
|
||||
if(WIN32)
|
||||
target_link_libraries(reaktor_print INTERFACE comdlg32 gdi32)
|
||||
elseif(APPLE)
|
||||
enable_language(OBJC)
|
||||
add_library(reaktor_print_macos OBJECT "${CMAKE_CURRENT_SOURCE_DIR}/runtime/print_macos.m")
|
||||
target_compile_options(reaktor_print_macos PRIVATE -fobjc-arc)
|
||||
target_sources(reaktor_print INTERFACE "$<TARGET_OBJECTS:reaktor_print_macos>")
|
||||
target_link_libraries(reaktor_print INTERFACE "-framework Cocoa" "-framework PDFKit")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_library(reaktor_runtime STATIC
|
||||
core/a11y/a11y.c
|
||||
core/anim/anim.c
|
||||
@@ -434,6 +542,7 @@ add_library(reaktor_runtime STATIC
|
||||
core/ui/declare.c
|
||||
core/ui/controls.c
|
||||
core/ui/views.c
|
||||
core/ui/picker.c
|
||||
core/ui/focus.c
|
||||
core/ui/keys.c
|
||||
core/ui/layout.c
|
||||
@@ -446,11 +555,10 @@ add_library(reaktor_runtime STATIC
|
||||
runtime/app.c
|
||||
runtime/input.c
|
||||
runtime/services.c
|
||||
runtime/tray.c
|
||||
runtime/undo.c
|
||||
runtime/window.c)
|
||||
target_compile_definitions(reaktor_runtime PRIVATE
|
||||
REAKTOR_VERSION_STRING="${PROJECT_VERSION}")
|
||||
target_include_directories(reaktor_runtime PRIVATE "${TP}/mglibs")
|
||||
|
||||
if(EMSCRIPTEN)
|
||||
target_sources(reaktor_runtime PRIVATE platform/web/keyboard_web.c)
|
||||
@@ -486,8 +594,8 @@ endif()
|
||||
set(REAKTOR_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" CACHE INTERNAL "")
|
||||
|
||||
foreach(_lic SDL/LICENSE.txt lcui/LICENSE.TXT plutosvg/LICENSE nuklear/LICENSE
|
||||
nukanim/LICENSE onlay/LICENSE tinycss/LICENSE ionicons/LICENSE mojibake/LICENSE
|
||||
kb/LICENSE)
|
||||
nukanim/LICENSE onlay/LICENSE watercss/LICENSE.md ionicons/LICENSE mojibake/LICENSE
|
||||
kb/LICENSE libharu/LICENSE)
|
||||
string(REGEX REPLACE "/.*" "" _who "${_lic}")
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/external/${_lic}"
|
||||
"${CMAKE_BINARY_DIR}/licenses/${_who}.txt" COPYONLY)
|
||||
@@ -508,10 +616,10 @@ function(reaktor_add_app name)
|
||||
add_executable(${name} WIN32 ${RA_SOURCES} ${REAKTOR_APP_RESOURCES})
|
||||
endif()
|
||||
if(NOT RA_MODULES AND NOT "MODULES" IN_LIST RA_KEYWORDS_MISSING_VALUES)
|
||||
set(RA_MODULES a11y locale text)
|
||||
set(RA_MODULES a11y locale text settings tray popups notify print inspector)
|
||||
endif()
|
||||
set(_mods "")
|
||||
foreach(_m a11y locale text)
|
||||
foreach(_m a11y locale text settings tray popups notify print inspector)
|
||||
if(_m IN_LIST RA_MODULES)
|
||||
list(APPEND _mods reaktor_${_m})
|
||||
else()
|
||||
@@ -551,8 +659,6 @@ function(reaktor_add_app name)
|
||||
-sEXIT_RUNTIME=0
|
||||
-Oz
|
||||
--closure 1
|
||||
-lidbfs.js
|
||||
"SHELL:--pre-js ${REAKTOR_SOURCE_DIR}/tools/web-pre.js"
|
||||
"SHELL:--shell-file ${REAKTOR_SOURCE_DIR}/tools/shell.html")
|
||||
set_property(TARGET ${name} APPEND PROPERTY LINK_DEPENDS
|
||||
"${REAKTOR_SOURCE_DIR}/tools/shell.html"
|
||||
@@ -577,10 +683,10 @@ reaktor_add_app(showcase SOURCES
|
||||
target_include_directories(showcase PRIVATE samples/showcase)
|
||||
|
||||
reaktor_add_app(simple MODULES none SOURCES samples/simple/simple.c)
|
||||
reaktor_add_app(notepad MODULES none SOURCES samples/notepad/notepad.c)
|
||||
reaktor_add_app(notepad MODULES settings popups print SOURCES samples/notepad/notepad.c)
|
||||
if(NOT EMSCRIPTEN)
|
||||
reaktor_add_app(bench MODULES none SOURCES samples/bench/bench.c)
|
||||
reaktor_add_app(launchtest MODULES none SOURCES tests/launchtest.c)
|
||||
reaktor_add_app(launchtest MODULES settings popups print SOURCES tests/launchtest.c)
|
||||
set_target_properties(launchtest PROPERTIES EXCLUDE_FROM_ALL ON)
|
||||
endif()
|
||||
|
||||
@@ -717,11 +823,13 @@ if(MSVC)
|
||||
endif()
|
||||
|
||||
add_library(reaktor_modules STATIC)
|
||||
target_link_libraries(reaktor_modules PRIVATE reaktor_runtime reaktor_a11y reaktor_locale reaktor_text)
|
||||
target_link_libraries(reaktor_modules PRIVATE reaktor_runtime reaktor_a11y reaktor_locale reaktor_text
|
||||
reaktor_settings reaktor_tray reaktor_popups reaktor_notify reaktor_print
|
||||
reaktor_inspector)
|
||||
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)
|
||||
foreach(_t mojibake_lib kb_text_shape hpdf)
|
||||
if(TARGET ${_t})
|
||||
list(APPEND _parts ${_t})
|
||||
endif()
|
||||
|
||||
@@ -30,13 +30,15 @@ How, and on what, is in [PERFORMANCE.md](docs/PERFORMANCE.md).
|
||||
|
||||
## Features
|
||||
|
||||
- **19 declared widgets** — buttons, fields, checks, radios, sliders, knobs,
|
||||
combos, a color picker, sidebar, tabs, tables and a splitter, with tooltips;
|
||||
all of Nuklear underneath, under Reaktor's names.
|
||||
- **Layers** — in-window dialogs, questions, toasts, more windows, and a tray
|
||||
icon with a menu.
|
||||
- **24 declared widgets** — buttons, fields, checks, radios, sliders, knobs,
|
||||
spinners, combos, a color picker, date and time pickers, sidebar, tabs, a
|
||||
menu bar, tables, trees and a splitter, with tooltips; rows drag between
|
||||
lists; all of Nuklear underneath, under Reaktor's names.
|
||||
- **Layers** — menus in windows of their own, in-window dialogs, questions,
|
||||
toasts, more windows, and a tray icon with a menu.
|
||||
- **Services** — system open, save and folder pickers, timers, main-thread
|
||||
posting, and settings that persist, window position included.
|
||||
posting, settings that persist, an undo stack, system notifications, and
|
||||
printing and PDF export.
|
||||
- **Styled by CSS** read at run time: color, type, borders, radii, spacing,
|
||||
`:hover` and `:active`, light and dark. Swap the sheet and the app changes.
|
||||
- **Accessible with no code** — UI Automation, NSAccessibility, AT-SPI and a
|
||||
@@ -49,9 +51,9 @@ How, and on what, is in [PERFORMANCE.md](docs/PERFORMANCE.md).
|
||||
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, idle once everything settles.
|
||||
- **Modular** — accessibility, localization and text shaping each swap for a
|
||||
stub at build time, and only what they drew stops being drawn; every other
|
||||
pixel stays.
|
||||
- **Modular** — accessibility, localization, text shaping, settings, the tray,
|
||||
popup windows, notifications and printing each swap for a stub at build
|
||||
time, and only what they drew stops being drawn; every other pixel stays.
|
||||
- **Windows, macOS, Linux, the BSDs and WebAssembly** from one set of sources,
|
||||
on one software rasterizer, at any display scale: x86 and ARM everywhere,
|
||||
and RISC-V on Linux ([Platforms](docs/DOCUMENTATION.md#platforms)).
|
||||
@@ -129,6 +131,7 @@ Every dependency is a submodule, used as it ships; the full list is in
|
||||
|
||||
- [DOCUMENTATION.md](docs/DOCUMENTATION.md) — the whole of it: every widget,
|
||||
layout and layer, styling, then how it works inside.
|
||||
- [FAQ.md](docs/FAQ.md) — short answers to common questions.
|
||||
- [DEMO.md](docs/DEMO.md) — the four programs in this repository.
|
||||
- [PERFORMANCE.md](docs/PERFORMANCE.md) — what it costs, measured.
|
||||
- [BENCHMARKS.md](benchmarks/BENCHMARKS.md) — the comparison, as runnable
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
:root {
|
||||
--background-hover: var(--button-hover);
|
||||
--table: var(--links);
|
||||
--table-bg: var(--background-body);
|
||||
--table-bg-alt: var(--background-alt);
|
||||
}
|
||||
|
||||
h4 {
|
||||
font-size: 19px;
|
||||
font-weight: 700;
|
||||
@@ -120,10 +127,6 @@ dialog {
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
:root {
|
||||
--button-hover: var(--background);
|
||||
}
|
||||
|
||||
.sidebar-item:hover {
|
||||
background-color: color-mix(in srgb, var(--text-main) 12%, var(--background));
|
||||
}
|
||||
|
||||
@@ -24,6 +24,13 @@ time.short = h:mm a
|
||||
time.ampm = AM | PM
|
||||
date.months = January | February | March | April | May | June | July | August | September | October | November | December
|
||||
date.months.short = Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec
|
||||
date.day = day
|
||||
date.month = month
|
||||
date.year = year
|
||||
time.hour = hour
|
||||
time.minute = minute
|
||||
button.ok = OK
|
||||
button.cancel = Cancel
|
||||
date.days = Sunday | Monday | Tuesday | Wednesday | Thursday | Friday | Saturday
|
||||
date.days.short = Sun | Mon | Tue | Wed | Thu | Fri | Sat
|
||||
locale.story = It was lovely summer weather in the country, and the golden corn, the green oats, and the haystacks piled up in the meadows looked beautiful. The stork walking about on his long red legs chattered in the Egyptian language, which he had learnt from his mother. The corn-fields and meadows were surrounded by large forests, in the midst of which were deep pools. It was, indeed, delightful to walk about in the country. In a sunny spot stood a pleasant old farm-house close by a deep river, and from the house down to the water side grew great burdock leaves, so high, that under the tallest of them a little child could stand upright. The spot was as wild as the centre of a thick wood. In this snug retreat sat a duck on her nest, watching for her young brood to hatch; she was beginning to get tired of her task, for the little ones were a long time coming out of their shells, and she seldom had any visitors. The other ducks liked much better to swim about in the river than to climb the slippery banks, and sit under a burdock leaf, to have a gossip with her.
|
||||
|
||||
@@ -24,6 +24,13 @@ time.short = H:mm
|
||||
time.ampm = 午前 | 午後
|
||||
date.months = 1月 | 2月 | 3月 | 4月 | 5月 | 6月 | 7月 | 8月 | 9月 | 10月 | 11月 | 12月
|
||||
date.months.short = 1月 | 2月 | 3月 | 4月 | 5月 | 6月 | 7月 | 8月 | 9月 | 10月 | 11月 | 12月
|
||||
date.day = 日
|
||||
date.month = 月
|
||||
date.year = 年
|
||||
time.hour = 時
|
||||
time.minute = 分
|
||||
button.ok = OK
|
||||
button.cancel = キャンセル
|
||||
date.days = 日曜日 | 月曜日 | 火曜日 | 水曜日 | 木曜日 | 金曜日 | 土曜日
|
||||
date.days.short = 日 | 月 | 火 | 水 | 木 | 金 | 土
|
||||
locale.story = それは田舎の夏のいいお天気の日の事でした。もう黄金色になった小麦や、まだ青い燕麦や、牧場に積み上げられた乾草堆など、みんなきれいな眺めに見える日でした。こうのとりは長い赤い脚で歩きまわりながら、母親から教わった妙な言葉でお喋りをしていました。\n 麦畑と牧場とは大きな森に囲まれ、その真ん中が深い水溜りになっています。全く、こういう田舎を散歩するのは愉快な事でした。\n その中でも殊に日当りのいい場所に、川近く、気持のいい古い百姓家が立っていました。そしてその家からずっと水際の辺りまで、大きな牛蒡の葉が茂っているのです。それは実際ずいぶん丈が高くて、その一番高いのなどは、下に子供がそっくり隠れる事が出来るくらいでした。人気がまるで無くて、全く深い林の中みたいです。この工合のいい隠れ場に一羽の家鴨がその時巣について卵がかえるのを守っていました。けれども、もうだいぶ時間が経っているのに卵はいっこう殻の破れる気配もありませんし、訪ねてくれる仲間もあまりないので、この家鴨は、そろそろ退屈しかけて来ました。他の家鴨達は、こんな、足の滑りそうな土堤を上って、牛蒡の葉の下に坐って、この親家鴨とお喋りするより、川で泳ぎ廻る方がよっぽど面白いのです。
|
||||
|
||||
@@ -21,7 +21,15 @@ date.long = d MMMM y
|
||||
date.full = EEEE, d MMMM y
|
||||
time.short = HH:mm
|
||||
date.months = stycznia | lutego | marca | kwietnia | maja | czerwca | lipca | sierpnia | września | października | listopada | grudnia
|
||||
date.months.standalone = styczeń | luty | marzec | kwiecień | maj | czerwiec | lipiec | sierpień | wrzesień | październik | listopad | grudzień
|
||||
date.months.short = sty | lut | mar | kwi | maj | cze | lip | sie | wrz | paź | lis | gru
|
||||
date.day = dzień
|
||||
date.month = miesiąc
|
||||
date.year = rok
|
||||
time.hour = godzina
|
||||
time.minute = minuta
|
||||
button.ok = OK
|
||||
button.cancel = Anuluj
|
||||
date.days = niedziela | poniedziałek | wtorek | środa | czwartek | piątek | sobota
|
||||
date.days.short = niedz. | pon. | wt. | śr. | czw. | pt. | sob.
|
||||
locale.story = Prześlicznie było na wsi. Lato gorące, pogodne, żółte zboża na polach, owies jeszcze zielony, na łąkach wielkie stogi pachnącego siana, a bociany przechadzają się powoli na wysokich czerwonych nogach i klekocą po egipsku, bo takim językiem nauczyły się mówić od matek. Dokoła wielkie lasy, cieniste, szumiące, a w nich głębokie i ciche jeziora. Prześlicznie i cudownie było na wsi.\nNa pochyłości wzgórza jasne słońce oświetlało stary zamek z wieżycami i gankami, otoczony murem i szeroką wstęgą wolno płynącej wody. Z muru zwieszały się pnące rośliny, a wielkie liście łopianu schylały się aż do wody. I było pod nimi cicho i ciemno, jak w cienistym lesie. Pod jednym z takich liści młoda kaczka usłała sobie gniazdo i siedziała na jajach. Nudziło jej się bardzo, bo żadna z sąsiadek nie miała chęci w tak piękną pogodę rozmawiać z nią o tem, co słychać na świecie. Każda wolała pływać po przejrzystej wodzie, pluskać się i osuszać na ciepłem słoneczku, a ona tylko jedna, jak przykuta siedzi w cieniu na gnieździe.
|
||||
|
||||
|
Before Width: | Height: | Size: 58 KiB After Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 50 KiB After Width: | Height: | Size: 59 KiB |
|
Before Width: | Height: | Size: 73 KiB After Width: | Height: | Size: 76 KiB |
|
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 48 KiB |
|
Before Width: | Height: | Size: 6.2 KiB After Width: | Height: | Size: 6.8 KiB |
@@ -671,7 +671,7 @@ static int is_theme_selector(const char *s, size_t len, const char *theme)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* tiny.css declares its dialog's properties on ::backdrop. */
|
||||
/* A sheet may declare its dialog's properties on ::backdrop. */
|
||||
static int is_vars_selector(const char *s, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
@@ -795,6 +795,7 @@ typedef struct emit_ctx {
|
||||
buf *out;
|
||||
int wrote;
|
||||
float rem_px, em_px;
|
||||
size_t token_max;
|
||||
} emit_ctx;
|
||||
|
||||
static void emit_one(void *c, const char *p, size_t plen,
|
||||
@@ -823,6 +824,13 @@ static void emit_one(void *c, const char *p, size_t plen,
|
||||
resolve_pixel_calcs(&conv);
|
||||
}
|
||||
|
||||
/* The engine ends a value at any ';', even one inside url(). */
|
||||
if (plen >= ctx->token_max || conv.len >= ctx->token_max ||
|
||||
(conv.p && memchr(conv.p, ';', conv.len))) {
|
||||
free(tmp.p);
|
||||
free(conv.p);
|
||||
return;
|
||||
}
|
||||
buf_add(ctx->out, p, plen);
|
||||
buf_str(ctx->out, ": ");
|
||||
buf_add(ctx->out, conv.p ? conv.p : "", conv.len);
|
||||
@@ -885,7 +893,8 @@ unwrap_color_scheme(char *src, const char *theme)
|
||||
}
|
||||
}
|
||||
|
||||
static char *flatten(char *src, const char *theme, reaktor_cssvars **out_vars)
|
||||
static char *flatten(char *src, const char *theme, size_t token_max,
|
||||
reaktor_cssvars **out_vars)
|
||||
{
|
||||
reaktor_cssvars *m = (reaktor_cssvars *)calloc(1, sizeof(*m));
|
||||
buf out;
|
||||
@@ -1003,7 +1012,7 @@ static char *flatten(char *src, const char *theme, reaktor_cssvars **out_vars)
|
||||
t = rw;
|
||||
if (!tn) continue;
|
||||
}
|
||||
if (selector_repeats(t, tn)) continue;
|
||||
if (tn >= token_max || selector_repeats(t, tn)) continue;
|
||||
if (n_emitted) buf_str(&sel, ", ");
|
||||
buf_add(&sel, t, tn);
|
||||
}
|
||||
@@ -1013,6 +1022,7 @@ static char *flatten(char *src, const char *theme, reaktor_cssvars **out_vars)
|
||||
|
||||
ctx.m = m;
|
||||
ctx.out = &out;
|
||||
ctx.token_max = token_max;
|
||||
ctx.wrote = 0;
|
||||
ctx.rem_px = root.px;
|
||||
ctx.em_px = root.em;
|
||||
@@ -1021,6 +1031,7 @@ static char *flatten(char *src, const char *theme, reaktor_cssvars **out_vars)
|
||||
emit_ctx bctx;
|
||||
memset(&body, 0, sizeof(body));
|
||||
bctx.m = m; bctx.out = &body; bctx.wrote = 0;
|
||||
bctx.token_max = token_max;
|
||||
bctx.rem_px = root.px;
|
||||
bctx.em_px = root.em;
|
||||
each_decl(src, body_s, body_e, emit_one, &bctx);
|
||||
@@ -1041,25 +1052,103 @@ static char *flatten(char *src, const char *theme, reaktor_cssvars **out_vars)
|
||||
return out.p;
|
||||
}
|
||||
|
||||
char *reaktor_css_flatten(const char *const *paths, int count,
|
||||
const char *theme, reaktor_cssvars **out_vars)
|
||||
#define IMPORT_DEPTH 8
|
||||
|
||||
/* `to` resolved against the folder of `from`, with "." and ".." folded away. */
|
||||
static char *import_path(const char *from, const char *to, size_t n)
|
||||
{
|
||||
const char *slash = strrchr(from, '/');
|
||||
size_t dir = slash ? (size_t)(slash - from) + 1 : 0;
|
||||
char *p = (char *)malloc(dir + n + 1), *w, *r;
|
||||
|
||||
if (!p) return NULL;
|
||||
memcpy(p, from, dir);
|
||||
memcpy(p + dir, to, n);
|
||||
p[dir + n] = 0;
|
||||
for (w = r = p; *r;) {
|
||||
if (strncmp(r, "./", 2) == 0) { r += 2; continue; }
|
||||
if (strncmp(r, "../", 3) == 0) {
|
||||
if (w > p) {
|
||||
w--;
|
||||
while (w > p && w[-1] != '/') w--;
|
||||
}
|
||||
r += 3;
|
||||
continue;
|
||||
}
|
||||
while (*r && *r != '/') *w++ = *r++;
|
||||
if (*r) *w++ = *r++;
|
||||
}
|
||||
*w = 0;
|
||||
return p;
|
||||
}
|
||||
|
||||
static int load_sheet(const char *path, int depth, buf *all)
|
||||
{
|
||||
char *t = reaktor_asset_load(path, NULL);
|
||||
size_t i = 0, from = 0, n;
|
||||
int ok = 1;
|
||||
|
||||
if (!t) {
|
||||
fprintf(stderr, "css: cannot read %s; skipped\n", path);
|
||||
return 1;
|
||||
}
|
||||
n = strlen(t);
|
||||
while (i < n && ok) {
|
||||
size_t s, e, q_s, q_e;
|
||||
char end = 0, *to;
|
||||
|
||||
if (t[i] == '/' && t[i + 1] == '*') {
|
||||
const char *c = strstr(t + i + 2, "*/");
|
||||
i = c ? (size_t)(c - t) + 2 : n;
|
||||
continue;
|
||||
}
|
||||
if (t[i] != '@' || strncmp(t + i, "@import", 7) != 0) { i++; continue; }
|
||||
s = i + 7;
|
||||
while (s < n && isspace((unsigned char)t[s])) s++;
|
||||
if (strncmp(t + s, "url(", 4) == 0) { s += 4; end = ')'; }
|
||||
while (s < n && isspace((unsigned char)t[s])) s++;
|
||||
if (t[s] == '\'' || t[s] == '"') end = t[s++];
|
||||
e = s;
|
||||
while (e < n && (end ? t[e] != end : !isspace((unsigned char)t[e]) && t[e] != ';')) e++;
|
||||
q_s = e < n && end ? e + 1 : e;
|
||||
if (end == '\'' || end == '"') {
|
||||
while (q_s < n && isspace((unsigned char)t[q_s])) q_s++;
|
||||
if (strncmp(t + q_s, ")", 1) == 0) q_s++;
|
||||
}
|
||||
q_e = q_s;
|
||||
while (q_e < n && t[q_e] != ';') q_e++;
|
||||
|
||||
ok = buf_add(all, t + from, i - from);
|
||||
from = i = q_e < n ? q_e + 1 : n;
|
||||
if (!ok || depth >= IMPORT_DEPTH || e == s) continue;
|
||||
if (!(to = import_path(path, t + s, e - s))) { ok = 0; continue; }
|
||||
trim(t, &q_s, &q_e);
|
||||
if (q_e > q_s) {
|
||||
ok = buf_str(all, "@media ") && buf_add(all, t + q_s, q_e - q_s) &&
|
||||
buf_str(all, " {\n") && load_sheet(to, depth + 1, all) &&
|
||||
buf_str(all, "}\n");
|
||||
} else {
|
||||
ok = load_sheet(to, depth + 1, all);
|
||||
}
|
||||
free(to);
|
||||
}
|
||||
ok = ok && buf_add(all, t + from, n - from) && buf_str(all, "\n");
|
||||
reaktor_free(t);
|
||||
return ok;
|
||||
}
|
||||
|
||||
char *reaktor_css_flatten(const char *const *paths, int count, const char *theme,
|
||||
size_t token_max, reaktor_cssvars **out_vars)
|
||||
{
|
||||
buf all;
|
||||
int i;
|
||||
|
||||
memset(&all, 0, sizeof(all));
|
||||
for (i = 0; i < count; i++) {
|
||||
char *t = reaktor_asset_load(paths[i], NULL);
|
||||
if (!t) {
|
||||
fprintf(stderr, "css: cannot read %s; skipped\n", paths[i]);
|
||||
continue;
|
||||
}
|
||||
if (!buf_str(&all, t) || !buf_str(&all, "\n")) {
|
||||
reaktor_free(t); free(all.p);
|
||||
for (i = 0; i < count; i++)
|
||||
if (!load_sheet(paths[i], 0, &all)) {
|
||||
free(all.p);
|
||||
return NULL;
|
||||
}
|
||||
reaktor_free(t);
|
||||
}
|
||||
if (!all.p) all.p = (char *)calloc(1, 1);
|
||||
return flatten(all.p, theme, out_vars);
|
||||
return flatten(all.p, theme, token_max ? token_max : (size_t)-1, out_vars);
|
||||
}
|
||||
|
||||
@@ -5,8 +5,9 @@
|
||||
|
||||
typedef struct reaktor_cssvars reaktor_cssvars;
|
||||
|
||||
char *reaktor_css_flatten(const char *const *paths, int count,
|
||||
const char *theme, reaktor_cssvars **out_vars);
|
||||
/* A declaration or selector of token_max bytes or more is dropped; 0 keeps all. */
|
||||
char *reaktor_css_flatten(const char *const *paths, int count, const char *theme,
|
||||
size_t token_max, reaktor_cssvars **out_vars);
|
||||
|
||||
const char *reaktor_cssvars_get(const reaktor_cssvars *vars, const char *name);
|
||||
|
||||
|
||||
@@ -117,7 +117,9 @@ static int style_load(const char *const *css_paths, int count,
|
||||
|
||||
reaktor_cssvars_free(g.vars);
|
||||
g.vars = NULL;
|
||||
flat = reaktor_css_flatten(css_paths, count, theme, &g.vars);
|
||||
/* The parser copies each token into a buffer this size without a bound. */
|
||||
flat = reaktor_css_flatten(css_paths, count, theme, CSS_PARSER_BUFFER_SIZE - 1,
|
||||
&g.vars);
|
||||
if (!flat) return 0;
|
||||
|
||||
parser = css_parser_create("reaktor");
|
||||
|
||||
@@ -49,7 +49,7 @@ void reaktor_rss_mark(int step);
|
||||
#define GLYPH_STROKE 2.0f
|
||||
|
||||
#define SHEET_MAX 12
|
||||
#define CORE_SHEET "external/tinycss/src/core.css"
|
||||
#define CORE_SHEET "external/watercss/src/parts/_core.css"
|
||||
#define APP_SHEET "assets/css/reaktor.css"
|
||||
#define FONT_FILE "assets/fonts/Aileron-Regular.otf"
|
||||
#define FONT_BOLD_FILE "assets/fonts/Aileron-Bold.otf"
|
||||
@@ -87,6 +87,12 @@ struct field_undo {
|
||||
int n, top;
|
||||
};
|
||||
|
||||
typedef struct undo_stack {
|
||||
struct reaktor_undo_step *step;
|
||||
unsigned *group, next, open;
|
||||
int n, top, cap, saved, depth;
|
||||
} undo_stack;
|
||||
|
||||
struct App {
|
||||
SDL_Window *win;
|
||||
SDL_Renderer *ren;
|
||||
@@ -175,6 +181,10 @@ struct App {
|
||||
unsigned char hot_last_repaint;
|
||||
|
||||
int dirty;
|
||||
/* The last rounded surface filled this frame, which a field may sit on. */
|
||||
struct nk_rect surface_at;
|
||||
struct nk_color surface;
|
||||
unsigned why;
|
||||
|
||||
struct input_queue {
|
||||
SDL_Event *ev;
|
||||
@@ -211,6 +221,13 @@ struct App {
|
||||
struct nk_rect body_rect;
|
||||
unsigned page_node;
|
||||
int focus_scroll;
|
||||
int popup_open, popups_inline;
|
||||
undo_stack undo;
|
||||
int want_capture;
|
||||
SDL_Surface *capture;
|
||||
struct { const char *buf; int from, to, asked; } field_pick;
|
||||
struct { char kind[32], from[64], label[96]; int item, armed, active; struct nk_vec2 at; } drag;
|
||||
SDL_Keycode popup_key;
|
||||
struct nk_rect focus_scroll_rect;
|
||||
int focus_layer;
|
||||
const struct nk_window *focus_win;
|
||||
@@ -255,11 +272,44 @@ enum { HOLD_NONE, HOLD_ALL, HOLD_FRESH };
|
||||
int focus_key(App *app, const SDL_Event *event);
|
||||
void focus_ring(App *app, struct nk_context *ctx, struct nk_command_buffer *cv);
|
||||
void reaktor_overlay(App *app, struct nk_context *ctx, int ring);
|
||||
|
||||
enum {
|
||||
REAKTOR_WHY_INPUT = 1u << 0,
|
||||
REAKTOR_WHY_RESIZE = 1u << 1,
|
||||
REAKTOR_WHY_MOTION = 1u << 2,
|
||||
REAKTOR_WHY_STYLE = 1u << 3
|
||||
};
|
||||
|
||||
/* The Inspector module, or its _none twin. */
|
||||
struct reaktor_inspector_spec;
|
||||
void reaktor_inspector_early(void);
|
||||
void reaktor_inspector_start(App *app, const struct reaktor_inspector_spec *spec, int flag);
|
||||
void reaktor_inspector_stop(App *app);
|
||||
int reaktor_inspector_event(App *app, const SDL_Event *e);
|
||||
void reaktor_inspector_frame(App *app);
|
||||
int reaktor_inspector_marks(App *app);
|
||||
void reaktor_inspector_mark(App *app, struct nk_context *ctx,
|
||||
struct nk_command_buffer *o);
|
||||
const char *reaktor_inspector_sheet(void);
|
||||
void reaktor_restyle(void);
|
||||
void reaktor_tip_draw(App *app, struct nk_context *ctx,
|
||||
struct nk_command_buffer *cv);
|
||||
void focus_resolve(App *app);
|
||||
void reaktor_key_click_ask(App *app);
|
||||
int reaktor_focus_covered(App *app);
|
||||
void reaktor_focus_take(App *app, unsigned id, struct nk_rect b);
|
||||
float reaktor_cap_offset(const struct nk_user_font *f);
|
||||
int reaktor_flyout_begin(struct nk_context *ctx, const char *name, struct nk_rect r);
|
||||
void reaktor_flyout_end(struct nk_context *ctx);
|
||||
int reaktor_window_popup(struct nk_rect r,
|
||||
void (*page)(App *, struct nk_context *, int, int, void *),
|
||||
void *user);
|
||||
int reaktor_window_bounds(struct nk_rect *out);
|
||||
struct reaktor_window;
|
||||
int reaktor_window_spawn(const struct reaktor_window *spec, const struct nk_rect *popup);
|
||||
void reaktor_window_move(int id, struct nk_rect r);
|
||||
float reaktor_window_points(void);
|
||||
App *reaktor_window_app(int id);
|
||||
|
||||
extern Uint64 g_hover_gap_ms;
|
||||
|
||||
@@ -271,6 +321,8 @@ void a11y_dump_once(App *app);
|
||||
void hot_push(App *app, struct nk_rect r, int cursor, int repaint);
|
||||
int css_button_accent(App *app, struct nk_context *ctx, const char *selector,
|
||||
const char *label);
|
||||
int reaktor_css_button_flat(App *app, struct nk_context *ctx, const char *icon,
|
||||
const char *name, int accent);
|
||||
int reaktor_css_button_image(App *app, struct nk_context *ctx, const char *selector,
|
||||
struct nk_image im, float px, const char *name);
|
||||
void reaktor_toasts_draw(App *app, struct nk_context *ctx, int win_w,
|
||||
@@ -350,7 +402,7 @@ int css_button_icon(App *app, struct nk_context *ctx, const char *selector,
|
||||
|
||||
struct nk_color readable_on(const unsigned char bg[4], const char *preferred,
|
||||
const char *fallback);
|
||||
reaktor_style_frame push_edit_style(struct nk_context *ctx, reaktor_style *out, int inset,
|
||||
reaktor_style_frame push_edit_style(struct nk_context *ctx, reaktor_style *out,
|
||||
const char *sel);
|
||||
nk_flags reaktor_field_text_as(App *app, struct nk_context *ctx, const char *sel,
|
||||
nk_flags flags, char *buf, int *len, int cap,
|
||||
@@ -408,8 +460,8 @@ void reaktor_knob_dial(App *app, struct nk_context *ctx, float *val,
|
||||
|
||||
void reaktor_property_push(struct nk_context *ctx);
|
||||
void reaktor_property_pop(struct nk_context *ctx);
|
||||
void reaktor_property_chrome(App *app, struct nk_context *ctx,
|
||||
struct nk_rect b);
|
||||
void reaktor_property_chrome(App *app, struct nk_context *ctx, struct nk_rect b,
|
||||
struct nk_rect *steps);
|
||||
|
||||
struct nk_rect reaktor_combo_content(struct nk_context *ctx, struct nk_rect h);
|
||||
void reaktor_combo_chrome(App *app, struct nk_context *ctx, struct nk_rect h,
|
||||
|
||||
@@ -243,14 +243,22 @@ reaktor_format_date(char *buf, size_t cap, const struct tm *t, int style)
|
||||
static const char *const english[] = {
|
||||
"M/d/yy", "MMMM d, y", "EEEE, MMMM d, y", "h:mm a"
|
||||
};
|
||||
|
||||
if (buf && cap) buf[0] = '\0';
|
||||
if (style < REAKTOR_DATE_SHORT || style > REAKTOR_TIME_SHORT) return buf;
|
||||
return reaktor_format_pattern(buf, cap, t, conv(keys[style], english[style]));
|
||||
}
|
||||
|
||||
const char *
|
||||
reaktor_format_pattern(char *buf, size_t cap, const struct tm *t, const char *pattern)
|
||||
{
|
||||
const char *p;
|
||||
int year, month, day, hour, minute, wd;
|
||||
out o;
|
||||
|
||||
if (!buf || cap == 0) return buf;
|
||||
o = start(buf, cap);
|
||||
if (!t || style < REAKTOR_DATE_SHORT || style > REAKTOR_TIME_SHORT)
|
||||
return buf;
|
||||
if (!t || !pattern) return buf;
|
||||
|
||||
year = t->tm_year + 1900;
|
||||
month = t->tm_mon + 1;
|
||||
@@ -260,7 +268,7 @@ reaktor_format_date(char *buf, size_t cap, const struct tm *t, int style)
|
||||
wd = SDL_GetDayOfWeek(year, month, day);
|
||||
if (wd < 0) return buf;
|
||||
|
||||
for (p = conv(keys[style], english[style]); *p; ) {
|
||||
for (p = pattern; *p; ) {
|
||||
char c = *p;
|
||||
int run = 1;
|
||||
|
||||
@@ -284,6 +292,12 @@ reaktor_format_date(char *buf, size_t cap, const struct tm *t, int style)
|
||||
while (p[run] == c) run++;
|
||||
switch (c) {
|
||||
case 'd': putf(&o, run > 1 ? "%02d" : "%d", day); break;
|
||||
case 'L':
|
||||
if (run >= 4)
|
||||
name(&o, "date.months.standalone", conv("date.months", MONTHS), month - 1);
|
||||
else
|
||||
putf(&o, run > 1 ? "%02d" : "%d", month);
|
||||
break;
|
||||
case 'M':
|
||||
if (run >= 4) name(&o, "date.months", MONTHS, month - 1);
|
||||
else if (run == 3) name(&o, "date.months.short", MONTHS_SHORT,
|
||||
|
||||
@@ -41,6 +41,48 @@ reaktor_format_money(char *buf, size_t cap, double amount, const char *currency)
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* English names and numbers: the letters reaktor_format_pattern knows. */
|
||||
const char *
|
||||
reaktor_format_pattern(char *buf, size_t cap, const struct tm *t, const char *pattern)
|
||||
{
|
||||
static const char *const months[12] = {
|
||||
"January", "February", "March", "April", "May", "June", "July",
|
||||
"August", "September", "October", "November", "December"
|
||||
};
|
||||
size_t n = 0;
|
||||
|
||||
if (!buf || !cap) return buf;
|
||||
buf[0] = '\0';
|
||||
if (!t || !pattern) return buf;
|
||||
for (; *pattern && n + 1 < cap; ) {
|
||||
char c = *pattern;
|
||||
int run = 1, w;
|
||||
|
||||
while (pattern[run] == c) run++;
|
||||
switch (c) {
|
||||
case 'd': w = snprintf(buf + n, cap - n, run > 1 ? "%02d" : "%d", t->tm_mday); break;
|
||||
case 'L':
|
||||
case 'M': w = run >= 3 ? snprintf(buf + n, cap - n, run == 3 ? "%.3s" : "%s",
|
||||
months[t->tm_mon % 12])
|
||||
: snprintf(buf + n, cap - n, run > 1 ? "%02d" : "%d",
|
||||
t->tm_mon + 1);
|
||||
break;
|
||||
case 'y': w = snprintf(buf + n, cap - n, "%04d", t->tm_year + 1900); break;
|
||||
case 'H': w = snprintf(buf + n, cap - n, run > 1 ? "%02d" : "%d", t->tm_hour); break;
|
||||
case 'h': w = snprintf(buf + n, cap - n, run > 1 ? "%02d" : "%d",
|
||||
t->tm_hour % 12 ? t->tm_hour % 12 : 12);
|
||||
break;
|
||||
case 'm': w = snprintf(buf + n, cap - n, "%02d", t->tm_min); break;
|
||||
case 'a': w = snprintf(buf + n, cap - n, "%s", t->tm_hour >= 12 ? "PM" : "AM"); break;
|
||||
default: w = snprintf(buf + n, cap - n, "%.*s", run, pattern); break;
|
||||
}
|
||||
n += w > 0 ? (size_t)w : 0;
|
||||
if (n >= cap) n = cap - 1;
|
||||
pattern += run;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
const char *
|
||||
reaktor_format_date(char *buf, size_t cap, const struct tm *t, int style)
|
||||
{
|
||||
|
||||
@@ -500,6 +500,10 @@ reaktor_fill_round(App *app, struct nk_command_buffer *cv, struct nk_rect b,
|
||||
int r, m;
|
||||
|
||||
if (b.w <= 0.0f || b.h <= 0.0f || !col.a) return;
|
||||
if (app) {
|
||||
app->surface_at = b;
|
||||
app->surface = col;
|
||||
}
|
||||
b = whole_px(b);
|
||||
if (b.w <= 0.0f || b.h <= 0.0f) return;
|
||||
r = corner_px(b, rounding);
|
||||
|
||||
@@ -93,7 +93,10 @@ reaktor_button(const reaktor_button_spec *s)
|
||||
}
|
||||
fitted = reaktor_fit_label(g_frame_app, g_frame_ctx, r);
|
||||
reaktor_note_mute(g_frame_app, 1);
|
||||
if (s->icon && !s->label) {
|
||||
if (s->flat && s->icon && !s->label) {
|
||||
hit = reaktor_css_button_flat(g_frame_app, g_frame_ctx, s->icon, s->name,
|
||||
s->accent);
|
||||
} else if (s->icon && !s->label) {
|
||||
float px = (float)(int)(r.h * 0.6f);
|
||||
|
||||
hit = reaktor_css_button_image(g_frame_app, g_frame_ctx, sel,
|
||||
@@ -288,6 +291,11 @@ reaktor_label(const reaktor_label_spec *s)
|
||||
: NK_TEXT_LEFT;
|
||||
struct nk_color c = reaktor_token(s->color, g_frame_ctx->style.text.color);
|
||||
|
||||
/* A sheet can repaint the page without redefining the token. */
|
||||
if (s->color)
|
||||
c = reaktor_visible(c, reaktor_page_color(g_frame_app),
|
||||
g_frame_ctx->style.text.color);
|
||||
|
||||
styled = decl_push_font(s->style);
|
||||
if (s->wrap) wrap_draw(f, s->text, c, lines);
|
||||
else nk_label_colored(g_frame_ctx, s->text, a, c);
|
||||
@@ -320,13 +328,93 @@ reaktor_icon(const reaktor_icon_spec *s)
|
||||
else reaktor_image_centered(g_frame_ctx, im, px);
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_field_select(App *app, const char *buf, int from, int to)
|
||||
{
|
||||
app->field_pick.buf = buf;
|
||||
app->field_pick.from = from;
|
||||
app->field_pick.to = to;
|
||||
app->field_pick.asked = 0;
|
||||
app->dirty = 1;
|
||||
reaktor_wake(app);
|
||||
}
|
||||
|
||||
/* Room for what is typed or pasted this frame: Nuklear never writes past cap. */
|
||||
static char *
|
||||
field_room(const reaktor_field_spec *s, int *cap)
|
||||
{
|
||||
int need = *s->len + 256;
|
||||
|
||||
if (nk_input_is_key_pressed(&g_frame_ctx->input, NK_KEY_PASTE)) {
|
||||
char *clip = SDL_GetClipboardText();
|
||||
|
||||
if (clip) need += (int)SDL_strlen(clip);
|
||||
SDL_free(clip);
|
||||
}
|
||||
if (!*s->heap || need > *s->heap_cap) {
|
||||
int room = NK_MAX(need, *s->heap_cap * 2);
|
||||
char *more = (char *)SDL_realloc(*s->heap, (size_t)room);
|
||||
|
||||
if (!more) return *s->heap;
|
||||
if (!*s->heap) more[0] = '\0';
|
||||
*s->heap = more;
|
||||
*s->heap_cap = room;
|
||||
}
|
||||
*cap = *s->heap_cap;
|
||||
return *s->heap;
|
||||
}
|
||||
|
||||
static float
|
||||
field_gutter(const char *buf, int len, int *lines)
|
||||
{
|
||||
const struct nk_user_font *f = g_frame_ctx->style.font;
|
||||
int i, n = 1, digits = 1, k;
|
||||
|
||||
for (i = 0; i < len; i++) n += buf[i] == '\n';
|
||||
for (k = n; k >= 10; k /= 10) digits++;
|
||||
*lines = n;
|
||||
return (float)(int)(f->width(f->userdata, f->height, "0000000000", NK_MAX(digits, 3)) +
|
||||
16.0f);
|
||||
}
|
||||
|
||||
static void
|
||||
field_numbers(struct nk_rect b, float gutter, int lines, int active)
|
||||
{
|
||||
struct nk_context *ctx = g_frame_ctx;
|
||||
const struct nk_user_font *f = ctx->style.font;
|
||||
const struct nk_style_edit *st = &ctx->style.edit;
|
||||
struct nk_command_buffer *cv = nk_window_get_canvas(ctx);
|
||||
struct nk_color fg = reaktor_token("--text-muted", nk_rgb(150, 150, 150));
|
||||
float row = f->height + st->row_padding;
|
||||
float top = b.y + st->border + st->padding.y;
|
||||
float scroll = active ? ctx->current->edit.scrollbar.y : 0.0f;
|
||||
struct nk_rect keep = cv->clip;
|
||||
char num[16];
|
||||
int i;
|
||||
|
||||
nk_push_scissor(cv, nk_rect(b.x, top, gutter, b.h - 2.0f * (st->border + st->padding.y)));
|
||||
for (i = (int)(scroll / row); i < lines && top + (float)i * row - scroll < b.y + b.h; i++) {
|
||||
int n = SDL_snprintf(num, sizeof num, "%d", i + 1);
|
||||
float w = f->width(f->userdata, f->height, num, n);
|
||||
|
||||
nk_draw_text(cv, nk_rect(b.x + gutter - 8.0f - w, top + (float)i * row - scroll, w, f->height),
|
||||
num, n, f, nk_rgba(0, 0, 0, 0), fg);
|
||||
}
|
||||
nk_push_scissor(cv, keep);
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_field(const reaktor_field_spec *s)
|
||||
{
|
||||
reaktor_box box;
|
||||
unsigned id = 0;
|
||||
char *buf;
|
||||
int cap, lines = 0;
|
||||
float gutter = 0.0f, pad_x;
|
||||
struct nk_rect r;
|
||||
nk_flags state;
|
||||
|
||||
if (!g_frame_app || !s || !s->buf || !s->len) return;
|
||||
if (!g_frame_app || !s || (!s->buf && !(s->heap && s->heap_cap)) || !s->len) return;
|
||||
box = s->box;
|
||||
decl_box_from_style(&box, NULL, s->style ? s->style : "input.type-text", "input",
|
||||
0.0f, 10.0f);
|
||||
@@ -334,13 +422,28 @@ reaktor_field(const reaktor_field_spec *s)
|
||||
if (!decl_place(REAKTOR_A11Y_TEXTBOX, s->name ? s->name : s->hint,
|
||||
NULL, 0u, NULL, &box, &id))
|
||||
return;
|
||||
cap = s->cap;
|
||||
buf = s->heap ? field_room(s, &cap) : s->buf;
|
||||
if (!buf) return;
|
||||
r = nk_widget_bounds(g_frame_ctx);
|
||||
if (g_frame_app->field_pick.buf == buf && !g_frame_app->field_pick.asked) {
|
||||
g_frame_app->field_pick.asked = 1;
|
||||
reaktor_focus_take(g_frame_app, id, r);
|
||||
reaktor_key_click_ask(g_frame_app);
|
||||
}
|
||||
pad_x = s->pad_x;
|
||||
if (s->multiline && s->line_numbers) {
|
||||
gutter = field_gutter(buf, *s->len, &lines);
|
||||
pad_x = (s->pad_x > 0.0f ? s->pad_x : g_frame_ctx->style.edit.padding.x) + gutter;
|
||||
}
|
||||
reaktor_note_mute(g_frame_app, 1);
|
||||
(void)reaktor_field_text_as(g_frame_app, g_frame_ctx, s->style,
|
||||
s->multiline ? NK_EDIT_BOX : NK_EDIT_FIELD,
|
||||
s->buf, s->len, s->cap, s->hint, s->filter,
|
||||
s->pad_x, s->pad_y);
|
||||
state = reaktor_field_text_as(g_frame_app, g_frame_ctx, s->style,
|
||||
s->multiline ? NK_EDIT_BOX : NK_EDIT_FIELD,
|
||||
buf, s->len, cap, s->hint, s->filter,
|
||||
pad_x, s->pad_y);
|
||||
reaktor_note_mute(g_frame_app, 0);
|
||||
reaktor_note_value(g_frame_app, id, s->buf[0] ? s->buf : NULL);
|
||||
if (gutter > 0.0f) field_numbers(r, gutter, lines, (state & NK_EDIT_ACTIVE) != 0);
|
||||
reaktor_note_value(g_frame_app, id, buf[0] ? buf : NULL);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -653,10 +756,66 @@ reaktor_property(const reaktor_property_spec *s)
|
||||
nk_property_double(g_frame_ctx, s->label, s->lo, s->dvalue, s->hi,
|
||||
s->step, s->grain);
|
||||
reaktor_property_pop(g_frame_ctx);
|
||||
reaktor_property_chrome(g_frame_app, g_frame_ctx, r);
|
||||
reaktor_property_chrome(g_frame_app, g_frame_ctx, r, NULL);
|
||||
reaktor_note_mute(g_frame_app, 0);
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_spinner(const reaktor_spinner_spec *s)
|
||||
{
|
||||
struct nk_context *ctx = g_frame_ctx;
|
||||
const struct nk_style_property *st;
|
||||
const struct nk_user_font *f;
|
||||
struct nk_command_buffer *cv;
|
||||
struct nk_rect r, step[2];
|
||||
struct nk_style_item bg;
|
||||
const char *value;
|
||||
reaktor_box box;
|
||||
unsigned id = 0;
|
||||
float y, w;
|
||||
int d = 0, at;
|
||||
|
||||
if (!g_frame_app || !s || !s->items || s->count <= 0 || !s->chosen) return 0;
|
||||
at = *s->chosen < 0 ? 0 : *s->chosen >= s->count ? s->count - 1 : *s->chosen;
|
||||
value = s->items[at] ? s->items[at] : "";
|
||||
box = s->box;
|
||||
decl_box_from_style(&box, NULL, s->style ? s->style : "input.type-text", "input",
|
||||
0.0f, 7.0f);
|
||||
if (!decl_place(REAKTOR_A11Y_SPINBUTTON, s->name ? s->name : s->label, value, 0u, NULL,
|
||||
&box, &id))
|
||||
return 0;
|
||||
st = &ctx->style.property;
|
||||
f = ctx->style.font;
|
||||
cv = nk_window_get_canvas(ctx);
|
||||
nk_widget(&r, ctx);
|
||||
bg = nk_input_is_mouse_hovering_rect(&ctx->input, r) ? st->hover : st->normal;
|
||||
if (bg.type == NK_STYLE_ITEM_COLOR)
|
||||
reaktor_fill_round(g_frame_app, cv, r, st->rounding, bg.data.color);
|
||||
if (st->border > 0.0f)
|
||||
reaktor_edge_round(g_frame_app, cv, r, st->rounding, st->border, st->border_color);
|
||||
reaktor_property_chrome(g_frame_app, ctx, r, step);
|
||||
y = (float)(int)(r.y + (r.h - f->height) * 0.5f);
|
||||
if (s->label)
|
||||
nk_draw_text(cv, nk_rect(step[0].x + step[0].w + 8.0f, y, r.w * 0.5f, f->height),
|
||||
s->label, (int)strlen(s->label), f, nk_rgba(0, 0, 0, 0), st->label_normal);
|
||||
w = f->width(f->userdata, f->height, value, (int)strlen(value));
|
||||
nk_draw_text(cv, nk_rect(step[1].x - 8.0f - w, y, w, f->height), value,
|
||||
(int)strlen(value), f, nk_rgba(0, 0, 0, 0), st->label_normal);
|
||||
if (nk_input_mouse_clicked(&ctx->input, NK_BUTTON_LEFT, step[0])) d = -1;
|
||||
if (nk_input_mouse_clicked(&ctx->input, NK_BUTTON_LEFT, step[1])) d = 1;
|
||||
if (!d) {
|
||||
int k = reaktor_focus_step(g_frame_app, id);
|
||||
|
||||
d = k > 0 ? 1 : k < 0 ? -1 : 0;
|
||||
}
|
||||
if (!d) return 0;
|
||||
at += d;
|
||||
if (s->wrap) at = (at + s->count) % s->count;
|
||||
else if (at < 0 || at >= s->count) return 0;
|
||||
*s->chosen = at;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_combo_open(const reaktor_combo_spec *s)
|
||||
{
|
||||
|
||||
@@ -109,8 +109,10 @@ reaktor_box_open(unsigned char dir, const reaktor_box *b)
|
||||
if (g_depth == 0) {
|
||||
float room = nk_window_get_content_region_size(g_frame_ctx).x;
|
||||
|
||||
if (box.w <= 0.0f || ((box.flags & REAKTOR_LAY_FILL_X) && box.w < room))
|
||||
if (box.w <= 0.0f || ((box.flags & REAKTOR_LAY_FILL_X) && box.w < room)) {
|
||||
box.w = room;
|
||||
box.flags |= REAKTOR_LAY_SIZED_W;
|
||||
}
|
||||
box.flags &= ~(unsigned)REAKTOR_LAY_FILL_X;
|
||||
}
|
||||
|
||||
@@ -322,6 +324,7 @@ decl_box_from_style(reaktor_box *box, const char *text, const char *selector,
|
||||
if (w < st.min_width) w = st.min_width;
|
||||
if (st.max_width > 0.0f && w > st.max_width) w = st.max_width;
|
||||
box->w = w;
|
||||
box->flags |= REAKTOR_LAY_SIZED_W;
|
||||
}
|
||||
if (box->h <= 0.0f && !(box->flags & REAKTOR_LAY_FILL_Y)) {
|
||||
float line = st.line_height > 0.0f ? st.line_height : f->height;
|
||||
@@ -329,6 +332,7 @@ decl_box_from_style(reaktor_box *box, const char *text, const char *selector,
|
||||
if (h < st.min_height) h = st.min_height;
|
||||
if (st.max_height > 0.0f && h > st.max_height) h = st.max_height;
|
||||
box->h = h;
|
||||
box->flags |= REAKTOR_LAY_SIZED_H;
|
||||
}
|
||||
|
||||
if (st.matched) {
|
||||
|
||||
@@ -33,6 +33,7 @@ focusable(const reaktor_a11y_node *n)
|
||||
case REAKTOR_A11Y_SLIDER: case REAKTOR_A11Y_SPINBUTTON:
|
||||
case REAKTOR_A11Y_COMBOBOX: case REAKTOR_A11Y_LISTITEM:
|
||||
case REAKTOR_A11Y_TREEITEM: case REAKTOR_A11Y_MENUITEM:
|
||||
case REAKTOR_A11Y_MENU:
|
||||
return !(n->state & REAKTOR_A11Y_DISABLED);
|
||||
default:
|
||||
return 0;
|
||||
@@ -121,8 +122,9 @@ focus_resolve(App *app)
|
||||
reaktor_a11y_set_focus(&app->a11y, 0);
|
||||
}
|
||||
|
||||
/* 1 when every arrow steps the focused widget, 2 when only Left and Right do. */
|
||||
static int
|
||||
focus_is_range(App *app)
|
||||
focus_steps(App *app)
|
||||
{
|
||||
int n, i;
|
||||
const reaktor_a11y_node *t = reaktor_a11y_tree(&app->a11y, &n);
|
||||
@@ -131,7 +133,8 @@ focus_is_range(App *app)
|
||||
for (i = 0; i < n; i++)
|
||||
if (t[i].id == app->focus_id)
|
||||
return t[i].role == REAKTOR_A11Y_SLIDER ||
|
||||
t[i].role == REAKTOR_A11Y_SPINBUTTON;
|
||||
t[i].role == REAKTOR_A11Y_SPINBUTTON ? 1
|
||||
: t[i].role == REAKTOR_A11Y_TREEITEM ? 2 : 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -140,6 +143,12 @@ focus_key(App *app, const SDL_Event *event)
|
||||
{
|
||||
int editing = app->editing;
|
||||
|
||||
if (!editing && (event->key.mod & (SDL_KMOD_CTRL | SDL_KMOD_GUI)) &&
|
||||
(event->key.key == SDLK_Z || event->key.key == SDLK_Y)) {
|
||||
if (event->key.key == SDLK_Y || (event->key.mod & SDL_KMOD_SHIFT)) reaktor_redo(app);
|
||||
else reaktor_undo(app);
|
||||
return 1;
|
||||
}
|
||||
if (event->key.key == SDLK_TAB) {
|
||||
if (editing) app->stop_editing = 1;
|
||||
focus_move(app, (event->key.mod & SDL_KMOD_SHIFT) ? FOCUS_PREV
|
||||
@@ -161,15 +170,37 @@ focus_key(App *app, const SDL_Event *event)
|
||||
}
|
||||
}
|
||||
|
||||
if (app->popup_open) {
|
||||
switch (event->key.key) {
|
||||
case SDLK_UP: case SDLK_DOWN: case SDLK_LEFT: case SDLK_RIGHT:
|
||||
case SDLK_HOME: case SDLK_END: case SDLK_RETURN: case SDLK_KP_ENTER:
|
||||
case SDLK_SPACE: case SDLK_ESCAPE:
|
||||
app->popup_key = event->key.key;
|
||||
app->dirty = 1;
|
||||
return 1;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
switch (event->key.key) {
|
||||
case SDLK_RIGHT: case SDLK_KP_6: case SDLK_UP: case SDLK_KP_8:
|
||||
if (focus_is_range(app)) { app->focus_step++; break; }
|
||||
if (focus_steps(app) == 1 ||
|
||||
(focus_steps(app) == 2 && (event->key.key == SDLK_RIGHT ||
|
||||
event->key.key == SDLK_KP_6))) {
|
||||
app->focus_step++;
|
||||
break;
|
||||
}
|
||||
focus_move(app, (event->key.key == SDLK_UP ||
|
||||
event->key.key == SDLK_KP_8) ? FOCUS_SIB_PREV
|
||||
: FOCUS_SIB_NEXT);
|
||||
break;
|
||||
case SDLK_LEFT: case SDLK_KP_4: case SDLK_DOWN: case SDLK_KP_2:
|
||||
if (focus_is_range(app)) { app->focus_step--; break; }
|
||||
if (focus_steps(app) == 1 ||
|
||||
(focus_steps(app) == 2 && (event->key.key == SDLK_LEFT ||
|
||||
event->key.key == SDLK_KP_4))) {
|
||||
app->focus_step--;
|
||||
break;
|
||||
}
|
||||
focus_move(app, (event->key.key == SDLK_DOWN ||
|
||||
event->key.key == SDLK_KP_2) ? FOCUS_SIB_NEXT
|
||||
: FOCUS_SIB_PREV);
|
||||
@@ -330,5 +361,6 @@ reaktor_overlay(App *app, struct nk_context *ctx, int ring)
|
||||
o->begin = o->end = o->last = ctx->memory.allocated;
|
||||
if (ring) focus_ring(app, ctx, o);
|
||||
if (app->tip) reaktor_tip_draw(app, ctx, o);
|
||||
reaktor_inspector_mark(app, ctx, o);
|
||||
o->end = ctx->memory.allocated;
|
||||
}
|
||||
|
||||
@@ -58,7 +58,12 @@ declare(reaktor_layout *l, unsigned id, const reaktor_box *b)
|
||||
if (l->count >= REAKTOR_LAY_MAX) { l->overflow_boxes++; return LAY_INVALID_ID; }
|
||||
|
||||
it = lay_item(&l->ctx);
|
||||
if (it < REAKTOR_LAY_MAX) { l->flags[it] = b->flags; l->dir[it] = b->dir; }
|
||||
if (it < REAKTOR_LAY_MAX) {
|
||||
l->flags[it] = b->flags;
|
||||
l->dir[it] = b->dir;
|
||||
l->w[it] = b->w;
|
||||
l->h[it] = b->h;
|
||||
}
|
||||
lay_set_size_xy(&l->ctx, it, (lay_scalar)b->w, (lay_scalar)b->h);
|
||||
lay_set_contain(&l->ctx, it, contain_of(b));
|
||||
lay_set_behave(&l->ctx, it, behave_of(b));
|
||||
@@ -237,6 +242,25 @@ reaktor_layout_rect(const reaktor_layout *l, unsigned id, struct nk_rect *out)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_layout_info(const reaktor_layout *l, unsigned id, unsigned *flags,
|
||||
unsigned char *dir, float *w, float *h)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < l->count; i++) {
|
||||
lay_id it = l->item[i];
|
||||
|
||||
if (l->id[i] != id || it >= REAKTOR_LAY_MAX) continue;
|
||||
*flags = l->flags[it];
|
||||
*dir = l->dir[it];
|
||||
*w = l->w[it];
|
||||
*h = l->h[it];
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_layout_free(reaktor_layout *l)
|
||||
{
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#define REAKTOR_LAY_DEPTH 32
|
||||
#define REAKTOR_LAY_SLOTS 512
|
||||
|
||||
#define REAKTOR_LAY_SIZED_W (1u << 26)
|
||||
#define REAKTOR_LAY_SIZED_H (1u << 27)
|
||||
#define REAKTOR_LAY_SHEET_L (1u << 28)
|
||||
#define REAKTOR_LAY_SHEET_T (1u << 29)
|
||||
#define REAKTOR_LAY_SHEET_R (1u << 30)
|
||||
@@ -30,6 +32,7 @@ typedef struct reaktor_layout {
|
||||
|
||||
unsigned flags[REAKTOR_LAY_MAX];
|
||||
unsigned char dir[REAKTOR_LAY_MAX];
|
||||
float w[REAKTOR_LAY_MAX], h[REAKTOR_LAY_MAX];
|
||||
|
||||
lay_id stack[REAKTOR_LAY_DEPTH];
|
||||
int depth;
|
||||
@@ -43,6 +46,8 @@ typedef struct reaktor_layout {
|
||||
} reaktor_layout;
|
||||
|
||||
void reaktor_layout_begin(reaktor_layout *l, struct nk_rect root);
|
||||
int reaktor_layout_info(const reaktor_layout *l, unsigned id, unsigned *flags,
|
||||
unsigned char *dir, float *w, float *h);
|
||||
|
||||
void reaktor_layout_open(reaktor_layout *l, unsigned id, const reaktor_box *b);
|
||||
void reaktor_layout_leaf(reaktor_layout *l, unsigned id, const reaktor_box *b);
|
||||
|
||||
@@ -0,0 +1,421 @@
|
||||
#include <time.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "declare.h"
|
||||
#include "reaktor/locale.h"
|
||||
|
||||
#define PICK_COLS 3
|
||||
#define PICK_ROWS 9
|
||||
#define PICK_GAP 8.0f
|
||||
|
||||
enum { PICK_DAY, PICK_MONTH, PICK_YEAR, PICK_HOUR, PICK_MINUTE, PICK_HALF };
|
||||
|
||||
typedef struct pick_col {
|
||||
int kind, lo, hi, at, loop, clock12;
|
||||
float w;
|
||||
} pick_col;
|
||||
|
||||
/* One picker is open at a time; its wheels hold the value until it is set. */
|
||||
static struct {
|
||||
const void *owner;
|
||||
pick_col col[PICK_COLS];
|
||||
int n, key, fresh;
|
||||
struct nk_rect field;
|
||||
} g_pick;
|
||||
|
||||
static const char *
|
||||
tr_or(const char *key, const char *english)
|
||||
{
|
||||
const char *s = reaktor_tr(key);
|
||||
|
||||
return s && SDL_strcmp(s, key) != 0 ? s : english;
|
||||
}
|
||||
|
||||
static float
|
||||
text_w(const struct nk_user_font *f, const char *s)
|
||||
{
|
||||
return f->width(f->userdata, f->height, s, (int)SDL_strlen(s));
|
||||
}
|
||||
|
||||
static const char *
|
||||
pick_label(const pick_col *c, int v, char *buf, size_t cap)
|
||||
{
|
||||
struct tm t;
|
||||
|
||||
SDL_zero(t);
|
||||
t.tm_year = 2000 - 1900;
|
||||
t.tm_mday = 1;
|
||||
switch (c->kind) {
|
||||
case PICK_MONTH: t.tm_mon = v - 1; return reaktor_format_pattern(buf, cap, &t, "LLLL");
|
||||
case PICK_HOUR: SDL_snprintf(buf, cap, "%d", c->clock12 ? (v % 12 ? v % 12 : 12) : v);
|
||||
return buf;
|
||||
case PICK_MINUTE: SDL_snprintf(buf, cap, "%02d", v); return buf;
|
||||
case PICK_HALF: t.tm_hour = v * 12; return reaktor_format_pattern(buf, cap, &t, "a");
|
||||
default: SDL_snprintf(buf, cap, "%d", v); return buf;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
pick_wrap(const pick_col *c, int v)
|
||||
{
|
||||
int n = c->hi - c->lo + 1;
|
||||
|
||||
if (c->loop) return c->lo + ((v - c->lo) % n + n) % n;
|
||||
return v < c->lo ? c->lo : v > c->hi ? c->hi : v;
|
||||
}
|
||||
|
||||
static void
|
||||
pick_days(void)
|
||||
{
|
||||
int k, y = 2000, m = 1;
|
||||
|
||||
for (k = 0; k < g_pick.n; k++) {
|
||||
if (g_pick.col[k].kind == PICK_YEAR) y = g_pick.col[k].at;
|
||||
if (g_pick.col[k].kind == PICK_MONTH) m = g_pick.col[k].at;
|
||||
}
|
||||
for (k = 0; k < g_pick.n; k++)
|
||||
if (g_pick.col[k].kind == PICK_DAY) {
|
||||
g_pick.col[k].hi = SDL_GetDaysInMonth(y, m);
|
||||
g_pick.col[k].at = pick_wrap(&g_pick.col[k], g_pick.col[k].at);
|
||||
}
|
||||
}
|
||||
|
||||
/* The segments, in the order the language writes a short date. */
|
||||
static int
|
||||
date_order(int *kinds)
|
||||
{
|
||||
struct tm t;
|
||||
char probe[64];
|
||||
const char *p;
|
||||
int n = 0;
|
||||
|
||||
SDL_zero(t);
|
||||
t.tm_year = 2033 - 1900;
|
||||
t.tm_mon = 10;
|
||||
t.tm_mday = 22;
|
||||
reaktor_format_date(probe, sizeof probe, &t, REAKTOR_DATE_SHORT);
|
||||
for (p = probe; *p && n < 3; p++) {
|
||||
int kind = SDL_strncmp(p, "22", 2) == 0 ? PICK_DAY
|
||||
: SDL_strncmp(p, "11", 2) == 0 ? PICK_MONTH
|
||||
: SDL_strncmp(p, "33", 2) == 0 ? PICK_YEAR : -1;
|
||||
|
||||
if (kind >= 0) { kinds[n++] = kind; p++; while (p[1] >= '0' && p[1] <= '9') p++; }
|
||||
}
|
||||
if (n != 3) { kinds[0] = PICK_MONTH; kinds[1] = PICK_DAY; kinds[2] = PICK_YEAR; n = 3; }
|
||||
return n;
|
||||
}
|
||||
|
||||
static void
|
||||
pick_draw_wheels(App *app, struct nk_context *ctx, struct nk_rect body, float row)
|
||||
{
|
||||
struct nk_command_buffer *cv = nk_window_get_canvas(ctx);
|
||||
const struct nk_user_font *f = ctx->style.font;
|
||||
struct nk_color fg = app->text, dim = reaktor_token("--text-muted", nk_rgb(150, 150, 150));
|
||||
struct nk_rect band = nk_rect(body.x, body.y + row * (PICK_ROWS / 2), body.w, row);
|
||||
float x = body.x;
|
||||
char buf[64];
|
||||
int k, i;
|
||||
|
||||
reaktor_fill_round(app, cv, band, 0.0f, app->accent);
|
||||
for (k = 0; k < g_pick.n; k++) {
|
||||
pick_col *c = &g_pick.col[k];
|
||||
struct nk_rect col = nk_rect(x, body.y, c->w, row * PICK_ROWS);
|
||||
unsigned id;
|
||||
|
||||
reaktor_hot(app, col, 1, 1);
|
||||
if (!g_pick.fresh && nk_input_is_mouse_hovering_rect(&ctx->input, col) &&
|
||||
ctx->input.mouse.scroll_delta.y != 0.0f) {
|
||||
c->at = pick_wrap(c, c->at - (ctx->input.mouse.scroll_delta.y > 0.0f ? 1 : -1));
|
||||
g_pick.key = k;
|
||||
}
|
||||
for (i = 0; i < PICK_ROWS; i++) {
|
||||
int v = c->at + i - PICK_ROWS / 2, shown = c->loop || (v >= c->lo && v <= c->hi);
|
||||
struct nk_rect r = nk_rect(x, body.y + row * (float)i, c->w, row);
|
||||
const char *t;
|
||||
float w;
|
||||
|
||||
v = pick_wrap(c, v);
|
||||
if (!shown) continue;
|
||||
if (!g_pick.fresh && i != PICK_ROWS / 2 &&
|
||||
nk_input_mouse_clicked(&ctx->input, NK_BUTTON_LEFT, r)) {
|
||||
c->at = v;
|
||||
g_pick.key = k;
|
||||
}
|
||||
t = pick_label(c, v, buf, sizeof buf);
|
||||
w = f->width(f->userdata, f->height, t, (int)SDL_strlen(t));
|
||||
nk_draw_text(cv, nk_rect(r.x + (r.w - w) * 0.5f,
|
||||
(float)(int)(r.y + (r.h - f->height) * 0.5f), w, f->height),
|
||||
t, (int)SDL_strlen(t), f, nk_rgba(0, 0, 0, 0),
|
||||
i == PICK_ROWS / 2 ? reaktor_on(app->accent) : i == 0 || i == PICK_ROWS - 1 ? dim : fg);
|
||||
}
|
||||
id = reaktor_note(app, REAKTOR_A11Y_SPINBUTTON, NULL,
|
||||
pick_label(c, c->at, buf, sizeof buf), 0u,
|
||||
nk_rect(x, band.y, c->w, row));
|
||||
if (k == g_pick.key) {
|
||||
app->focus_id = id;
|
||||
reaktor_a11y_set_focus(&app->a11y, id);
|
||||
}
|
||||
if (k) nk_fill_rect(cv, nk_rect(x, body.y, 1.0f, row * PICK_ROWS), 0.0f,
|
||||
reaktor_token("--background-hover", dim));
|
||||
x += c->w;
|
||||
}
|
||||
pick_days();
|
||||
}
|
||||
|
||||
static int
|
||||
pick_key(App *app)
|
||||
{
|
||||
SDL_Keycode key = app->popup_key;
|
||||
pick_col *c = &g_pick.col[g_pick.key];
|
||||
|
||||
app->popup_key = 0;
|
||||
switch (key) {
|
||||
case SDLK_UP: c->at = pick_wrap(c, c->at - 1); break;
|
||||
case SDLK_DOWN: c->at = pick_wrap(c, c->at + 1); break;
|
||||
case SDLK_LEFT: g_pick.key = (g_pick.key + g_pick.n - 1) % g_pick.n; break;
|
||||
case SDLK_RIGHT: g_pick.key = (g_pick.key + 1) % g_pick.n; break;
|
||||
case SDLK_RETURN: case SDLK_KP_ENTER: case SDLK_SPACE: return 1;
|
||||
case SDLK_ESCAPE: return -1;
|
||||
default: return 0;
|
||||
}
|
||||
pick_days();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* 1 when set, -1 when dismissed, 0 while open. */
|
||||
static int
|
||||
pick_flyout(App *app, struct nk_context *ctx, float row)
|
||||
{
|
||||
struct nk_rect r = g_pick.field, body;
|
||||
float w = 0.0f, h = row * PICK_ROWS + row + 16.0f;
|
||||
int k, done;
|
||||
|
||||
const char *no = tr_or("button.cancel", "Cancel"), *ok = tr_or("button.ok", "OK");
|
||||
reaktor_style btn;
|
||||
float need;
|
||||
|
||||
reaktor_style_get("button", &btn);
|
||||
need = 2.0f * (NK_MAX(text_w(ctx->style.font, no), text_w(ctx->style.font, ok)) +
|
||||
2.0f * (btn.pad_x + btn.border)) + 3.0f * PICK_GAP;
|
||||
|
||||
for (k = 0; k < g_pick.n; k++) w += g_pick.col[k].w;
|
||||
if (w < need) {
|
||||
for (k = 0; k < g_pick.n; k++) g_pick.col[k].w = (float)(int)(g_pick.col[k].w * need / w);
|
||||
for (w = 0.0f, k = 0; k < g_pick.n; k++) w += g_pick.col[k].w;
|
||||
}
|
||||
r.x += (r.w - w) * 0.5f;
|
||||
r.w = w;
|
||||
r.y = g_pick.field.y + g_pick.field.h * 0.5f - row * (PICK_ROWS / 2 + 0.5f);
|
||||
r.h = h;
|
||||
if (r.y + r.h > (float)app->laid_h) r.y = (float)app->laid_h - r.h;
|
||||
if (r.y < 0.0f) r.y = 0.0f;
|
||||
if (r.x + r.w > (float)app->laid_w) r.x = (float)app->laid_w - r.w;
|
||||
if (r.x < 0.0f) r.x = 0.0f;
|
||||
|
||||
done = pick_key(app);
|
||||
if (!done && !g_pick.fresh && nk_input_is_mouse_released(&ctx->input, NK_BUTTON_LEFT) &&
|
||||
!nk_input_is_mouse_hovering_rect(&ctx->input, r) &&
|
||||
!nk_input_is_mouse_hovering_rect(&ctx->input, g_pick.field))
|
||||
done = -1;
|
||||
if (reaktor_flyout_begin(ctx, "reaktor-picker", r)) {
|
||||
struct nk_command_buffer *cv = nk_window_get_canvas(ctx);
|
||||
reaktor_style dlg;
|
||||
reaktor_surface s;
|
||||
struct nk_rect foot;
|
||||
|
||||
reaktor_style_get("dialog", &dlg);
|
||||
s = reaktor_rule_surface(&dlg, reaktor_popup_rounding());
|
||||
reaktor_paint_surface(app, cv, r, &s);
|
||||
body = nk_rect(r.x, r.y + 4.0f, r.w, row * PICK_ROWS);
|
||||
nk_push_scissor(cv, body);
|
||||
pick_draw_wheels(app, ctx, body, row);
|
||||
nk_push_scissor(cv, r);
|
||||
foot = nk_rect(r.x + PICK_GAP, r.y + h - row - 6.0f, (r.w - 3.0f * PICK_GAP) * 0.5f, row);
|
||||
nk_layout_space_begin(ctx, NK_STATIC, h, 2);
|
||||
nk_layout_space_push(ctx, nk_layout_space_rect_to_local(ctx, foot));
|
||||
if (reaktor_button_label(app, ctx, no) && !g_pick.fresh) done = -1;
|
||||
foot.x += foot.w + PICK_GAP;
|
||||
nk_layout_space_push(ctx, nk_layout_space_rect_to_local(ctx, foot));
|
||||
if (reaktor_button_accent(app, ctx, ok) && !g_pick.fresh) done = 1;
|
||||
nk_layout_space_end(ctx);
|
||||
reaktor_flyout_end(ctx);
|
||||
}
|
||||
if (!done) app->popup_open = 1;
|
||||
g_pick.fresh = 0;
|
||||
return done;
|
||||
}
|
||||
|
||||
/* The field is an input like any other: the value as the language writes it, or a hint. */
|
||||
static int
|
||||
pick_field(const void *owner, const char *name, const reaktor_box *spec_box,
|
||||
pick_col *cols, int n, const char *hint, const char *value)
|
||||
{
|
||||
App *app = g_frame_app;
|
||||
struct nk_context *ctx = g_frame_ctx;
|
||||
const struct nk_user_font *f = ctx->style.font;
|
||||
reaktor_style in;
|
||||
reaktor_style_frame sf;
|
||||
reaktor_box box = *spec_box;
|
||||
struct nk_rect r;
|
||||
float row;
|
||||
char buf[64];
|
||||
unsigned id;
|
||||
int k, v, done = 0;
|
||||
|
||||
/* The padding a text field resolves, so the hint sits where a field's does. */
|
||||
sf = push_edit_style(ctx, &in, NULL);
|
||||
reaktor_style_frame_pop(ctx, sf);
|
||||
decl_box_from_style(&box, NULL, "input.type-text", "input", 0.0f, 7.0f);
|
||||
if (box.w <= 0.0f && !(box.flags & REAKTOR_LAY_FILL_X))
|
||||
box.w = (float)(int)(text_w(f, value ? value : hint) + 2.0f * in.pad_x + 0.5f);
|
||||
if (!decl_place(REAKTOR_A11Y_BUTTON, name, value,
|
||||
g_pick.owner == owner ? REAKTOR_A11Y_EXPANDED : 0u, NULL, &box, &id))
|
||||
return 0;
|
||||
nk_widget(&r, ctx);
|
||||
reaktor_edit_edge(app, ctx, r, &in);
|
||||
reaktor_hot(app, r, REAKTOR_CURSOR_POINTER, 1);
|
||||
if (value)
|
||||
nk_draw_text(nk_window_get_canvas(ctx),
|
||||
nk_rect(r.x + in.pad_x, (float)(int)(r.y + (r.h - f->height) * 0.5f),
|
||||
r.w - 2.0f * in.pad_x, f->height),
|
||||
value, (int)SDL_strlen(value), f, nk_rgba(0, 0, 0, 0),
|
||||
ctx->style.edit.text_normal);
|
||||
else
|
||||
draw_hint(ctx, r, hint, &in);
|
||||
row = (float)(int)(f->height + 14.0f);
|
||||
if (g_pick.owner != owner &&
|
||||
(nk_input_mouse_clicked(&ctx->input, NK_BUTTON_LEFT, r) ||
|
||||
reaktor_focus_activated(app, id))) {
|
||||
g_pick.owner = owner;
|
||||
g_pick.n = n;
|
||||
g_pick.key = 0;
|
||||
g_pick.fresh = 1;
|
||||
SDL_memcpy(g_pick.col, cols, sizeof(pick_col) * (size_t)n);
|
||||
for (k = 0; k < n; k++) {
|
||||
float w = 0.0f;
|
||||
|
||||
for (v = cols[k].lo; v <= cols[k].hi; v++)
|
||||
w = NK_MAX(w, text_w(f, pick_label(&cols[k], v, buf, sizeof buf)));
|
||||
g_pick.col[k].w = (float)(int)(w + 32.0f);
|
||||
}
|
||||
pick_days();
|
||||
}
|
||||
if (g_pick.owner == owner) {
|
||||
g_pick.field = r;
|
||||
done = pick_flyout(app, ctx, row);
|
||||
if (done) {
|
||||
if (done > 0) SDL_memcpy(cols, g_pick.col, sizeof(pick_col) * (size_t)n);
|
||||
g_pick.owner = NULL;
|
||||
reaktor_focus_take(app, id, r);
|
||||
app->dirty = 1;
|
||||
reaktor_wake(app);
|
||||
}
|
||||
}
|
||||
return done > 0;
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_date_pick(const reaktor_date_spec *s)
|
||||
{
|
||||
pick_col cols[3];
|
||||
const char *hints[3];
|
||||
struct tm tm;
|
||||
char hint[96], value[64];
|
||||
int kinds[3], k, n, set, today = 1;
|
||||
|
||||
if (!g_frame_app || !s || !s->year || !s->month || !s->day) return 0;
|
||||
set = *s->day > 0;
|
||||
if (!set) {
|
||||
SDL_Time now;
|
||||
SDL_DateTime dt;
|
||||
|
||||
SDL_zero(dt);
|
||||
if (SDL_GetCurrentTime(&now)) SDL_TimeToDateTime(now, &dt, true);
|
||||
*s->year = dt.year ? dt.year : 2000;
|
||||
*s->month = dt.month ? dt.month : 1;
|
||||
today = dt.day ? dt.day : 1;
|
||||
}
|
||||
n = date_order(kinds);
|
||||
for (k = 0; k < n; k++) {
|
||||
pick_col *c = &cols[k];
|
||||
|
||||
SDL_zero(*c);
|
||||
c->kind = kinds[k];
|
||||
if (c->kind == PICK_DAY) {
|
||||
c->lo = 1; c->hi = SDL_GetDaysInMonth(*s->year, *s->month); c->loop = 1;
|
||||
c->at = set ? *s->day : today;
|
||||
hints[k] = tr_or("date.day", "day");
|
||||
} else if (c->kind == PICK_MONTH) {
|
||||
c->lo = 1; c->hi = 12; c->loop = 1; c->at = *s->month;
|
||||
hints[k] = tr_or("date.month", "month");
|
||||
} else {
|
||||
c->lo = s->min_year ? s->min_year : 1900;
|
||||
c->hi = s->max_year ? s->max_year : 2100;
|
||||
c->at = *s->year;
|
||||
hints[k] = tr_or("date.year", "year");
|
||||
}
|
||||
}
|
||||
SDL_snprintf(hint, sizeof hint, "%s / %s / %s", hints[0], hints[1], hints[2]);
|
||||
SDL_zero(tm);
|
||||
tm.tm_year = *s->year - 1900;
|
||||
tm.tm_mon = *s->month - 1;
|
||||
tm.tm_mday = set ? *s->day : 1;
|
||||
reaktor_format_date(value, sizeof value, &tm, REAKTOR_DATE_SHORT);
|
||||
if (!pick_field(s->day, s->name ? s->name : "Date", &s->box, cols, n, hint,
|
||||
set ? value : NULL))
|
||||
return 0;
|
||||
for (k = 0; k < n; k++) {
|
||||
if (cols[k].kind == PICK_DAY) *s->day = cols[k].at;
|
||||
if (cols[k].kind == PICK_MONTH) *s->month = cols[k].at;
|
||||
if (cols[k].kind == PICK_YEAR) *s->year = cols[k].at;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_time_pick(const reaktor_time_spec *s)
|
||||
{
|
||||
static char half[16];
|
||||
pick_col cols[3];
|
||||
const char *hints[3];
|
||||
struct tm tm;
|
||||
char hint[96], value[32];
|
||||
int n = 2, set;
|
||||
|
||||
if (!g_frame_app || !s || !s->hour || !s->minute) return 0;
|
||||
set = *s->hour >= 0;
|
||||
SDL_zero(cols);
|
||||
cols[0].kind = PICK_HOUR;
|
||||
cols[0].lo = s->clock12 ? 1 : 0;
|
||||
cols[0].hi = s->clock12 ? 12 : 23;
|
||||
cols[0].loop = 1;
|
||||
cols[0].clock12 = s->clock12;
|
||||
cols[0].at = !set ? cols[0].lo : s->clock12 ? (*s->hour % 12 ? *s->hour % 12 : 12) : *s->hour;
|
||||
cols[1].kind = PICK_MINUTE;
|
||||
cols[1].lo = 0;
|
||||
cols[1].hi = 59;
|
||||
cols[1].loop = 1;
|
||||
cols[1].at = set ? *s->minute : 0;
|
||||
hints[0] = tr_or("time.hour", "hour");
|
||||
hints[1] = tr_or("time.minute", "minute");
|
||||
if (s->clock12) {
|
||||
cols[2].kind = PICK_HALF;
|
||||
cols[2].lo = 0;
|
||||
cols[2].hi = 1;
|
||||
cols[2].at = set && *s->hour >= 12;
|
||||
hints[2] = pick_label(&cols[2], 0, half, sizeof half);
|
||||
n = 3;
|
||||
}
|
||||
SDL_snprintf(hint, sizeof hint, n == 3 ? "%s:%s %s" : "%s:%s", hints[0], hints[1],
|
||||
n == 3 ? hints[2] : "");
|
||||
SDL_zero(tm);
|
||||
tm.tm_hour = set ? *s->hour : 0;
|
||||
tm.tm_min = set ? *s->minute : 0;
|
||||
reaktor_format_pattern(value, sizeof value, &tm, s->clock12 ? "h:mm a" : "HH:mm");
|
||||
if (!pick_field(s->hour, s->name ? s->name : "Time", &s->box, cols, n, hint,
|
||||
set ? value : NULL))
|
||||
return 0;
|
||||
*s->minute = cols[1].at;
|
||||
*s->hour = s->clock12 ? cols[0].at % 12 + (cols[2].at ? 12 : 0) : cols[0].at;
|
||||
return 1;
|
||||
}
|
||||
@@ -376,7 +376,10 @@ icon_place(struct nk_context *ctx, struct nk_rect b, float pad_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);
|
||||
if (b.w >= text + 2.0f * (3.0f * pad_x + s->image_padding.x + at->w)) return 1;
|
||||
/* A wide padding still leaves room once the icon moves to the edge. */
|
||||
at->x = b.x + pad_x + s->image_padding.x;
|
||||
return b.w >= text + 2.0f * (1.5f * pad_x + s->image_padding.x + at->w);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -412,6 +415,48 @@ css_button_icon(App *app, struct nk_context *ctx, const char *selector,
|
||||
return clicked;
|
||||
}
|
||||
|
||||
static int
|
||||
press_blank(struct nk_context *ctx)
|
||||
{
|
||||
int clicked;
|
||||
|
||||
reaktor_button_arm(ctx);
|
||||
clicked = nk_button_text(ctx, "", 0);
|
||||
reaktor_chrome_disarm();
|
||||
return clicked;
|
||||
}
|
||||
|
||||
static void
|
||||
image_centered(struct nk_context *ctx, struct nk_rect b, struct nk_image im, float px)
|
||||
{
|
||||
nk_draw_image(nk_window_get_canvas(ctx),
|
||||
nk_rect((float)(int)(b.x + (b.w - px) * 0.5f),
|
||||
(float)(int)(b.y + (b.h - px) * 0.5f), px, px),
|
||||
&im, nk_rgb(255, 255, 255));
|
||||
}
|
||||
|
||||
/* An icon alone: no fill or edge until the pointer is over it, then the sheet's hover. */
|
||||
int
|
||||
reaktor_css_button_flat(App *app, struct nk_context *ctx, const char *icon,
|
||||
const char *name, int accent)
|
||||
{
|
||||
struct nk_rect b = nk_widget_bounds(ctx);
|
||||
float px = (float)(int)(b.h * 0.6f);
|
||||
int clicked;
|
||||
|
||||
hot_push(app, b, 1, 1);
|
||||
reaktor_note_here(app, ctx, REAKTOR_A11Y_BUTTON, name, 0);
|
||||
nk_style_push_style_item(ctx, &ctx->style.button.normal,
|
||||
nk_style_item_color(nk_rgba(0, 0, 0, 0)));
|
||||
nk_style_push_float(ctx, &ctx->style.button.border, 0.0f);
|
||||
clicked = press_blank(ctx);
|
||||
nk_style_pop_float(ctx);
|
||||
nk_style_pop_style_item(ctx);
|
||||
image_centered(ctx, b, reaktor_ionicon_col(app, icon, (int)px,
|
||||
accent ? app->accent : app->text), px);
|
||||
return clicked;
|
||||
}
|
||||
|
||||
/* Nuklear shrinks an image button by its rounding too, so it is drawn here. */
|
||||
int
|
||||
reaktor_css_button_image(App *app, struct nk_context *ctx, const char *selector,
|
||||
@@ -424,24 +469,17 @@ reaktor_css_button_image(App *app, struct nk_context *ctx, const char *selector,
|
||||
hot_push(app, b, 1, 1);
|
||||
reaktor_note_here(app, ctx, REAKTOR_A11Y_BUTTON, name, 0);
|
||||
f = push_button_style(app, ctx, selector);
|
||||
reaktor_button_arm(ctx);
|
||||
clicked = nk_button_text(ctx, "", 0);
|
||||
reaktor_chrome_disarm();
|
||||
clicked = press_blank(ctx);
|
||||
reaktor_style_frame_pop(ctx, f);
|
||||
nk_draw_image(nk_window_get_canvas(ctx),
|
||||
nk_rect((float)(int)(b.x + (b.w - px) * 0.5f),
|
||||
(float)(int)(b.y + (b.h - px) * 0.5f), px, px),
|
||||
&im, nk_rgb(255, 255, 255));
|
||||
image_centered(ctx, b, im, px);
|
||||
return clicked;
|
||||
}
|
||||
|
||||
reaktor_style_frame
|
||||
push_edit_style(struct nk_context *ctx, reaktor_style *out, int inset,
|
||||
const char *sel)
|
||||
push_edit_style(struct nk_context *ctx, reaktor_style *out, const char *sel)
|
||||
{
|
||||
reaktor_style s, foc, btn;
|
||||
reaktor_style_frame f = { 0, 0, 0, 0, 0 };
|
||||
unsigned char body[4];
|
||||
char focus[96];
|
||||
|
||||
if (!sel) sel = "input.type-text";
|
||||
@@ -452,11 +490,6 @@ push_edit_style(struct nk_context *ctx, reaktor_style *out, int inset,
|
||||
s.pad_x += s.border;
|
||||
if (btn.matched && btn.pad_x > s.pad_x) s.pad_x = btn.pad_x;
|
||||
if (s.pad_x < 16.0f) s.pad_x = 16.0f;
|
||||
if (inset && reaktor_style_token("--background-body", body)) {
|
||||
int k;
|
||||
for (k = 0; k < 3; k++)
|
||||
s.bg[k] = (unsigned char)((s.bg[k] * 3 + body[k] * 2) / 5);
|
||||
}
|
||||
*out = s;
|
||||
if (!s.matched) return f;
|
||||
|
||||
@@ -517,9 +550,18 @@ void
|
||||
reaktor_edit_edge(App *app, struct nk_context *ctx, struct nk_rect b,
|
||||
const reaktor_style *s)
|
||||
{
|
||||
struct nk_rect on = app->surface_at;
|
||||
struct nk_color fill = nk_rgba_bv(s->bg);
|
||||
|
||||
if (!s->matched) return;
|
||||
/* A sheet may fill a field like the card it sits on; it then takes the page's. */
|
||||
if (on.w > b.w && b.x >= on.x && b.y >= on.y &&
|
||||
b.x + b.w <= on.x + on.w && b.y + b.h <= on.y + on.h &&
|
||||
SDL_abs(fill.r - app->surface.r) + SDL_abs(fill.g - app->surface.g) +
|
||||
SDL_abs(fill.b - app->surface.b) <= 3)
|
||||
fill = reaktor_page_color(app);
|
||||
reaktor_paint_surface(app, nk_window_get_canvas(ctx), reaktor_rect_trunc(b),
|
||||
&(reaktor_surface){ nk_rgba_bv(s->bg), nk_rgba_bv(s->border_col),
|
||||
&(reaktor_surface){ fill, nk_rgba_bv(s->border_col),
|
||||
s->border, s->rounding });
|
||||
}
|
||||
|
||||
@@ -857,13 +899,14 @@ apply_widget_style(App *app)
|
||||
st->chart.selected_color = focus;
|
||||
st->chart.border = 1.0f;
|
||||
|
||||
st->scrollh.normal = nk_style_item_color(body);
|
||||
st->scrollh.hover = nk_style_item_color(body);
|
||||
st->scrollh.active = nk_style_item_color(body);
|
||||
/* No track: a scrollbar sits on lists and panels as well as the page. */
|
||||
st->scrollh.normal = i_none;
|
||||
st->scrollh.hover = i_none;
|
||||
st->scrollh.active = i_none;
|
||||
st->scrollh.cursor_normal = nk_style_item_color(thumb);
|
||||
st->scrollh.cursor_hover = nk_style_item_color(thumb_hi);
|
||||
st->scrollh.cursor_active = nk_style_item_color(thumb_hi);
|
||||
st->scrollh.border_color = body;
|
||||
st->scrollh.border_color = nk_rgba(0, 0, 0, 0);
|
||||
st->scrollh.rounding = 3.0f;
|
||||
st->scrollh.rounding_cursor = 3.0f;
|
||||
st->scrollh.show_buttons = nk_false;
|
||||
|
||||
@@ -128,13 +128,37 @@ reaktor_tabs(const reaktor_tabs_spec *s)
|
||||
return nav_list(s, 1);
|
||||
}
|
||||
|
||||
/* A tree is a list whose first column is indented, with a chevron on each branch. */
|
||||
typedef struct tree_rows {
|
||||
const reaktor_tree_spec *s;
|
||||
int *node, *depth, *row;
|
||||
int n, jump;
|
||||
} tree_rows;
|
||||
|
||||
static int
|
||||
tree_branch(const tree_rows *t, int node)
|
||||
{
|
||||
return node + 1 < t->s->count && t->s->parent(node + 1, t->s->user) == node;
|
||||
}
|
||||
|
||||
static const char *
|
||||
tree_cell(int r, int c, void *user)
|
||||
{
|
||||
const tree_rows *t = (const tree_rows *)user;
|
||||
|
||||
(void)c;
|
||||
return t->s->label(t->node[r], t->s->user);
|
||||
}
|
||||
|
||||
static int
|
||||
list_neighbor(const reaktor_list_spec *s, int r, struct nk_rect area, float row_h,
|
||||
float scrolled, int focused)
|
||||
float scrolled, int focused, const tree_rows *t)
|
||||
{
|
||||
struct nk_rect row = nk_rect(area.x, area.y + (float)r * row_h - scrolled,
|
||||
area.w, row_h);
|
||||
unsigned id = reaktor_note(g_frame_app, REAKTOR_A11Y_LISTITEM, s->cell(r, 0, s->user),
|
||||
unsigned id = reaktor_note(g_frame_app,
|
||||
t ? REAKTOR_A11Y_TREEITEM : REAKTOR_A11Y_LISTITEM,
|
||||
s->cell(r, 0, s->user),
|
||||
NULL, s->selected && *s->selected == r
|
||||
? REAKTOR_A11Y_SELECTED : 0u, row);
|
||||
|
||||
@@ -168,8 +192,164 @@ list_follow(const reaktor_list_spec *s, int focused, struct nk_rect area, float
|
||||
return changed;
|
||||
}
|
||||
|
||||
/* Row r's first column in a tree; 1 when the selection should move to t->jump. */
|
||||
static int
|
||||
tree_first(tree_rows *t, int r, unsigned id, struct nk_color fg, float pad)
|
||||
{
|
||||
struct nk_context *ctx = g_frame_ctx;
|
||||
const struct nk_user_font *f = ctx->style.font;
|
||||
const reaktor_tree_spec *s = t->s;
|
||||
int node = t->node[r], branch = tree_branch(t, node), step;
|
||||
struct nk_rect b, chev;
|
||||
const char *label = s->label(node, s->user);
|
||||
const char *icon = s->icon ? s->icon(node, s->user) : NULL;
|
||||
float x;
|
||||
|
||||
nk_widget(&b, ctx);
|
||||
x = b.x + pad + 16.0f * (float)t->depth[node];
|
||||
chev = nk_rect(x, b.y, 16.0f, b.h);
|
||||
if (branch) {
|
||||
reaktor_chevron_at(g_frame_app, ctx, chev,
|
||||
s->open[node] ? "chevron-down-outline" : "chevron-forward-outline",
|
||||
fg);
|
||||
if (nk_input_mouse_clicked(&ctx->input, NK_BUTTON_LEFT, chev))
|
||||
s->open[node] = !s->open[node];
|
||||
}
|
||||
x += 20.0f;
|
||||
if (icon) {
|
||||
float px = (float)(int)(f->height + 0.5f);
|
||||
struct nk_image im = reaktor_ionicon_col(g_frame_app, icon, (int)px, fg);
|
||||
|
||||
nk_draw_image(nk_window_get_canvas(ctx),
|
||||
nk_rect(x, (float)(int)(b.y + (b.h - px) * 0.5f), px, px), &im,
|
||||
nk_rgb(255, 255, 255));
|
||||
x += px + 6.0f;
|
||||
}
|
||||
if (label)
|
||||
nk_draw_text(nk_window_get_canvas(ctx),
|
||||
nk_rect(x, (float)(int)(b.y + (b.h - f->height) * 0.5f),
|
||||
b.x + b.w - x, f->height),
|
||||
label, (int)strlen(label), f, nk_rgba(0, 0, 0, 0), fg);
|
||||
if (t->jump == node) {
|
||||
reaktor_focus_take(g_frame_app, id, b);
|
||||
t->jump = -1;
|
||||
}
|
||||
step = reaktor_focus_step(g_frame_app, id);
|
||||
if (step > 0 && branch && !s->open[node]) s->open[node] = 1;
|
||||
else if (step > 0 && branch && r + 1 < t->n) t->jump = t->node[r + 1];
|
||||
else if (step < 0 && branch && s->open[node]) s->open[node] = 0;
|
||||
else if (step < 0 && s->parent(node, s->user) >= 0) t->jump = s->parent(node, s->user);
|
||||
if (step) {
|
||||
g_frame_app->dirty = 1;
|
||||
reaktor_wake(g_frame_app);
|
||||
}
|
||||
return step && t->jump >= 0;
|
||||
}
|
||||
|
||||
static int list_draw(const reaktor_list_spec *s, tree_rows *t);
|
||||
|
||||
/* Rows with .drag start a drag; a list of the same kind shows where it lands. */
|
||||
static float
|
||||
list_drag(const reaktor_list_spec *s, struct nk_rect area, float row_h, int *changed)
|
||||
{
|
||||
App *app = g_frame_app;
|
||||
struct nk_context *ctx = g_frame_ctx;
|
||||
const struct nk_input *in = &ctx->input;
|
||||
const char *name = s->name ? s->name : "list";
|
||||
struct nk_vec2 m = in->mouse.pos;
|
||||
nk_uint sx = 0, sy = 0;
|
||||
int at;
|
||||
|
||||
nk_group_get_scroll(ctx, name, &sx, &sy);
|
||||
at = (int)((m.y - area.y + (float)sy) / row_h + 0.5f);
|
||||
if (nk_input_is_mouse_pressed(in, NK_BUTTON_LEFT) &&
|
||||
nk_input_is_mouse_hovering_rect(in, area) && at >= 0) {
|
||||
int r = (int)((m.y - area.y + (float)sy) / row_h);
|
||||
const char *label = r < s->count ? s->cell(r, 0, s->user) : NULL;
|
||||
|
||||
if (r < s->count) {
|
||||
SDL_strlcpy(app->drag.kind, s->drag, sizeof app->drag.kind);
|
||||
SDL_strlcpy(app->drag.from, name, sizeof app->drag.from);
|
||||
SDL_strlcpy(app->drag.label, label ? label : "", sizeof app->drag.label);
|
||||
app->drag.item = r;
|
||||
app->drag.armed = 1;
|
||||
app->drag.at = m;
|
||||
}
|
||||
}
|
||||
if (app->drag.armed && !app->drag.active && SDL_strcmp(app->drag.from, name) == 0 &&
|
||||
(SDL_fabsf(m.x - app->drag.at.x) > 4.0f || SDL_fabsf(m.y - app->drag.at.y) > 4.0f))
|
||||
app->drag.active = 1;
|
||||
if (!app->drag.active || SDL_strcmp(app->drag.kind, s->drag) != 0) return -1.0f;
|
||||
if (SDL_strcmp(app->drag.from, name) == 0) app->tip = app->drag.label;
|
||||
if (!nk_input_is_mouse_hovering_rect(in, area)) return -1.0f;
|
||||
if (at > s->count) at = s->count;
|
||||
if (nk_input_is_mouse_released(in, NK_BUTTON_LEFT) && s->dropped) {
|
||||
s->dropped(app->drag.from, app->drag.item, at, s->user);
|
||||
app->drag.active = app->drag.armed = 0;
|
||||
*changed = 1;
|
||||
return -1.0f;
|
||||
}
|
||||
return area.y + (float)at * row_h - (float)sy - 1.0f;
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_list(const reaktor_list_spec *s)
|
||||
{
|
||||
return list_draw(s, NULL);
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_tree(const reaktor_tree_spec *s)
|
||||
{
|
||||
static int *buf, cap, jump = -1;
|
||||
static const char *jump_in;
|
||||
tree_rows t;
|
||||
reaktor_list_spec l;
|
||||
int i, sel = -1, changed;
|
||||
|
||||
if (!g_frame_app || !s || s->count < 0 || !s->parent || !s->label || !s->open) return 0;
|
||||
if (s->count * 3 > cap) {
|
||||
int *more = (int *)SDL_realloc(buf, (size_t)s->count * 3 * sizeof *buf);
|
||||
|
||||
if (!more) return 0;
|
||||
buf = more;
|
||||
cap = s->count * 3;
|
||||
}
|
||||
t.s = s;
|
||||
t.node = buf;
|
||||
t.depth = buf + s->count;
|
||||
t.row = buf + 2 * s->count;
|
||||
t.n = 0;
|
||||
t.jump = jump_in == s->name ? jump : -1;
|
||||
for (i = 0; i < s->count; i++) {
|
||||
int p = s->parent(i, s->user);
|
||||
|
||||
t.depth[i] = p >= 0 && p < i ? t.depth[p] + 1 : 0;
|
||||
t.row[i] = p < 0 || (p < i && t.row[p] >= 0 && s->open[p]) ? t.n : -1;
|
||||
if (t.row[i] >= 0) t.node[t.n++] = i;
|
||||
}
|
||||
if (s->selected && *s->selected >= 0 && *s->selected < s->count)
|
||||
sel = t.row[*s->selected];
|
||||
memset(&l, 0, sizeof l);
|
||||
l.name = s->name;
|
||||
l.count = t.n;
|
||||
l.cell = tree_cell;
|
||||
l.user = &t;
|
||||
l.selected = s->selected ? &sel : NULL;
|
||||
l.row_h = s->row_h;
|
||||
l.box = s->box;
|
||||
changed = list_draw(&l, &t);
|
||||
if (s->selected && sel >= 0 && sel < t.n && t.node[sel] != *s->selected) {
|
||||
*s->selected = t.node[sel];
|
||||
changed = 1;
|
||||
}
|
||||
jump = t.jump;
|
||||
jump_in = s->name;
|
||||
return changed;
|
||||
}
|
||||
|
||||
static int
|
||||
list_draw(const reaktor_list_spec *s, tree_rows *t)
|
||||
{
|
||||
const struct nk_user_font *head_f, *cell_f;
|
||||
struct nk_list_view view;
|
||||
@@ -240,12 +420,14 @@ reaktor_list(const reaktor_list_spec *s)
|
||||
nk_style_push_vec2(g_frame_ctx, &g_frame_ctx->style.window.group_padding, nk_vec2(0.0f, 0.0f));
|
||||
nk_style_push_vec2(g_frame_ctx, &g_frame_ctx->style.text.padding, nk_vec2(pad, 0.0f));
|
||||
nk_style_push_font(g_frame_ctx, cell_f);
|
||||
float line = s->drag ? list_drag(s, area, row_h, &changed) : -1.0f;
|
||||
|
||||
if (nk_list_view_begin(g_frame_ctx, &view, s->name ? s->name : "list",
|
||||
s->count <= shown ? NK_WINDOW_NO_SCROLLBAR : 0,
|
||||
(int)row_h, s->count)) {
|
||||
if (view.begin > 0)
|
||||
focused = list_neighbor(s, view.begin - 1, area, row_h,
|
||||
(float)view.scroll_value, focused);
|
||||
(float)view.scroll_value, focused, t);
|
||||
for (r = view.begin; r < view.end; r++) {
|
||||
struct nk_command_buffer *cv = nk_window_get_canvas(g_frame_ctx);
|
||||
struct nk_color fg = g_frame_ctx->style.text.color;
|
||||
@@ -258,8 +440,12 @@ reaktor_list(const reaktor_list_spec *s)
|
||||
row.w = nk_window_get_content_region(g_frame_ctx).w;
|
||||
nk_fill_rect(cv, row, 0.0f, (r & 1) ? even : odd);
|
||||
if (s->selected) reaktor_hot(g_frame_app, row, REAKTOR_CURSOR_DEFAULT, 1);
|
||||
id = reaktor_note(g_frame_app, REAKTOR_A11Y_LISTITEM, s->cell(r, 0, s->user),
|
||||
NULL, on ? REAKTOR_A11Y_SELECTED : 0u, row);
|
||||
id = reaktor_note(g_frame_app,
|
||||
t ? REAKTOR_A11Y_TREEITEM : REAKTOR_A11Y_LISTITEM,
|
||||
s->cell(r, 0, s->user), NULL,
|
||||
(on ? REAKTOR_A11Y_SELECTED : 0u) |
|
||||
(t && tree_branch(t, t->node[r]) && t->s->open[t->node[r]]
|
||||
? REAKTOR_A11Y_EXPANDED : 0u), row);
|
||||
if (id && id == g_frame_app->focus_id) focused = r;
|
||||
if (s->selected && on) {
|
||||
nk_fill_rect(cv, row, 0.0f, g_frame_app->accent);
|
||||
@@ -270,9 +456,21 @@ reaktor_list(const reaktor_list_spec *s)
|
||||
reaktor_token("--background-hover", nk_rgba(128, 128, 128, 60)));
|
||||
}
|
||||
for (c = 0; c < cols; c++) {
|
||||
const char *t = s->cell(r, c, s->user);
|
||||
const char *cell = s->cell(r, c, s->user);
|
||||
|
||||
nk_label_colored(g_frame_ctx, t ? t : "", NK_TEXT_LEFT, fg);
|
||||
if (t && c == 0) {
|
||||
if (tree_first(t, r, id, fg, pad) && s->selected) {
|
||||
int k = t->row[t->jump];
|
||||
|
||||
if (k >= 0 && *s->selected != k) {
|
||||
*s->selected = k;
|
||||
changed = 1;
|
||||
}
|
||||
}
|
||||
if (id && id == g_frame_app->focus_id) focused = r;
|
||||
continue;
|
||||
}
|
||||
nk_label_colored(g_frame_ctx, cell ? cell : "", NK_TEXT_LEFT, fg);
|
||||
}
|
||||
if (nk_input_mouse_clicked(&g_frame_ctx->input, NK_BUTTON_LEFT, row)) on = 1;
|
||||
if (s->selected && *s->selected != r &&
|
||||
@@ -283,9 +481,12 @@ reaktor_list(const reaktor_list_spec *s)
|
||||
}
|
||||
if (view.end < s->count)
|
||||
focused = list_neighbor(s, view.end, area, row_h,
|
||||
(float)view.scroll_value, focused);
|
||||
(float)view.scroll_value, focused, t);
|
||||
nk_list_view_end(&view);
|
||||
}
|
||||
if (line >= 0.0f)
|
||||
nk_fill_rect(nk_window_get_canvas(g_frame_ctx), nk_rect(area.x, line, area.w, 2.0f),
|
||||
0.0f, g_frame_app->accent);
|
||||
changed |= list_follow(s, focused, area, row_h);
|
||||
nk_style_pop_font(g_frame_ctx);
|
||||
nk_style_pop_vec2(g_frame_ctx);
|
||||
@@ -347,3 +548,511 @@ reaktor_splitter(const reaktor_splitter_spec *s)
|
||||
if (*s->value > hi) *s->value = hi;
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define MENU_DEPTH 4
|
||||
#define MENU_COLS (MENU_DEPTH + 1)
|
||||
#define MENU_TITLES 16
|
||||
#define MENU_ITEMS 32
|
||||
|
||||
/* The windows that draw a column run after the frame that declared it: they draw a copy. */
|
||||
typedef struct menu_col {
|
||||
const reaktor_menu_entry *items, *src;
|
||||
reaktor_menu_entry copy[MENU_ITEMS];
|
||||
int count;
|
||||
const char *name;
|
||||
struct nk_rect r;
|
||||
float lead;
|
||||
} menu_col;
|
||||
|
||||
/* One menu bar is open at a time; its columns are read by the windows that draw them. */
|
||||
static struct {
|
||||
int open, depth, kcol, kbd, keyed, focused;
|
||||
int path[MENU_DEPTH], hi[MENU_COLS], win[MENU_COLS];
|
||||
menu_col col[MENU_COLS];
|
||||
int n, inline_;
|
||||
unsigned tid[MENU_TITLES];
|
||||
struct nk_rect title[MENU_TITLES];
|
||||
int picked_k, picked_i;
|
||||
} g_menu = { -1 };
|
||||
|
||||
static float
|
||||
menu_text_w(const struct nk_user_font *f, const char *s)
|
||||
{
|
||||
return s ? f->width(f->userdata, f->height, s, (int)strlen(s)) : 0.0f;
|
||||
}
|
||||
|
||||
static int
|
||||
menu_rule(const reaktor_menu_entry *e)
|
||||
{
|
||||
return !e->label && !e->custom;
|
||||
}
|
||||
|
||||
static int
|
||||
menu_live(const reaktor_menu_entry *e)
|
||||
{
|
||||
return e->label && !e->disabled;
|
||||
}
|
||||
|
||||
static float
|
||||
menu_entry_h(const reaktor_menu_entry *e)
|
||||
{
|
||||
if (menu_rule(e)) return 1.0f;
|
||||
return e->custom && e->height > 0.0f ? e->height : REAKTOR_MENU_ROW;
|
||||
}
|
||||
|
||||
static float
|
||||
menu_entry_y(const menu_col *c, int k)
|
||||
{
|
||||
float y = c->r.y + g_frame_ctx->style.window.menu_padding.y;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < k; i++) y += menu_entry_h(&c->items[i]) + REAKTOR_MENU_GAP;
|
||||
return y;
|
||||
}
|
||||
|
||||
static void
|
||||
menu_measure(menu_col *c, const struct nk_user_font *f, struct nk_vec2 pad)
|
||||
{
|
||||
float w = 140.0f, h = 0.0f;
|
||||
int i;
|
||||
|
||||
c->lead = 0.0f;
|
||||
for (i = 0; i < c->count; i++)
|
||||
if (c->items[i].icon || c->items[i].checked)
|
||||
c->lead = (float)(int)(f->height + 0.5f) + 8.0f;
|
||||
for (i = 0; i < c->count; i++) {
|
||||
const reaktor_menu_entry *e = &c->items[i];
|
||||
float iw = e->width;
|
||||
|
||||
if (i) h += REAKTOR_MENU_GAP;
|
||||
h += menu_entry_h(e);
|
||||
if (!e->custom && e->label)
|
||||
iw = 28.0f + c->lead + menu_text_w(f, e->label) +
|
||||
(e->keys ? 24.0f + menu_text_w(f, e->keys) : 0.0f) +
|
||||
(e->items ? 22.0f : 0.0f);
|
||||
if (iw > w) w = iw;
|
||||
}
|
||||
c->r.w = (float)(int)w + 2.0f * pad.x;
|
||||
c->r.h = h + 2.0f * pad.y;
|
||||
}
|
||||
|
||||
static void
|
||||
menu_fit(menu_col *c, const menu_col *parent, struct nk_rect title, struct nk_rect b)
|
||||
{
|
||||
if (!parent) {
|
||||
c->r.x = title.x;
|
||||
c->r.y = title.y + title.h;
|
||||
if (c->r.y + c->r.h > b.y + b.h && title.y - c->r.h >= b.y) c->r.y = title.y - c->r.h;
|
||||
} else {
|
||||
c->r.x = parent->r.x + parent->r.w;
|
||||
if (c->r.x + c->r.w > b.x + b.w) c->r.x = parent->r.x - c->r.w;
|
||||
}
|
||||
if (c->r.x + c->r.w > b.x + b.w) c->r.x = b.x + b.w - c->r.w;
|
||||
if (c->r.x < b.x) c->r.x = b.x;
|
||||
if (c->r.y + c->r.h > b.y + b.h) c->r.y = b.y + b.h - c->r.h;
|
||||
if (c->r.y < b.y) c->r.y = b.y;
|
||||
}
|
||||
|
||||
static int
|
||||
menu_step(const reaktor_menu_entry *items, int count, int from, int d)
|
||||
{
|
||||
int i, k;
|
||||
|
||||
for (k = 1; k <= count; k++) {
|
||||
i = ((from < 0 ? (d > 0 ? -1 : 0) : from) + d * k + count * 2) % count;
|
||||
if (menu_live(&items[i])) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void
|
||||
menu_changed(void)
|
||||
{
|
||||
App *m = reaktor_main_app();
|
||||
|
||||
int k;
|
||||
|
||||
for (k = 0; k < MENU_COLS; k++) {
|
||||
App *w = g_menu.win[k] ? reaktor_window_app(g_menu.win[k]) : NULL;
|
||||
|
||||
if (w) w->dirty = 1;
|
||||
}
|
||||
if (m) { m->dirty = 1; reaktor_wake(m); }
|
||||
}
|
||||
|
||||
static void
|
||||
menu_open_at(int m, int kbd)
|
||||
{
|
||||
g_menu.open = m;
|
||||
g_menu.picked_k = -1;
|
||||
g_menu.depth = 0;
|
||||
g_menu.kcol = 0;
|
||||
g_menu.kbd = kbd;
|
||||
g_menu.keyed = kbd;
|
||||
g_menu.hi[0] = -1;
|
||||
}
|
||||
|
||||
static void
|
||||
menu_draw_entry(const reaktor_menu_entry *e, struct nk_rect b, float lead, int lit)
|
||||
{
|
||||
struct nk_context *ctx = g_frame_ctx;
|
||||
App *app = g_frame_app;
|
||||
const struct nk_user_font *f = ctx->style.font;
|
||||
struct nk_command_buffer *cv = nk_window_get_canvas(ctx);
|
||||
const struct nk_style_button *st = &ctx->style.contextual_button;
|
||||
struct nk_color fg = e->disabled ? reaktor_token("--text-muted", nk_rgb(160, 160, 160))
|
||||
: lit ? st->text_hover : st->text_normal;
|
||||
|
||||
if (lit && st->hover.type == NK_STYLE_ITEM_COLOR)
|
||||
reaktor_fill_round(app, cv, b, st->rounding, st->hover.data.color);
|
||||
if (e->icon) {
|
||||
float px = (float)(int)(f->height + 0.5f);
|
||||
struct nk_image im = reaktor_ionicon_col(app, e->icon, (int)px, fg);
|
||||
|
||||
nk_draw_image(cv, nk_rect(b.x + 8.0f + (lead - 8.0f - px) * 0.5f,
|
||||
(float)(int)(b.y + (b.h - px) * 0.5f), px, px),
|
||||
&im, nk_rgb(255, 255, 255));
|
||||
} else if (e->checked && *e->checked) {
|
||||
float px = (float)(int)(f->height * 0.45f);
|
||||
|
||||
reaktor_glyph_at(app, ctx,
|
||||
nk_rect(b.x + 8.0f + (lead - 8.0f - px) * 0.5f,
|
||||
(float)(int)(b.y + (b.h - px) * 0.5f), px, px),
|
||||
REAKTOR_DISC_ROUND, fg, (int)px, 0.0f);
|
||||
}
|
||||
nk_draw_text(cv, nk_rect(b.x + 8.0f + lead, (float)(int)(b.y + (b.h - f->height) * 0.5f),
|
||||
b.w - 16.0f - lead, f->height),
|
||||
e->label, (int)strlen(e->label), f, nk_rgba(0, 0, 0, 0), fg);
|
||||
if (e->keys) {
|
||||
float w = menu_text_w(f, e->keys);
|
||||
|
||||
nk_draw_text(cv, nk_rect(b.x + b.w - w - 8.0f,
|
||||
(float)(int)(b.y + (b.h - f->height) * 0.5f), w, f->height),
|
||||
e->keys, (int)strlen(e->keys), f, nk_rgba(0, 0, 0, 0),
|
||||
reaktor_token("--text-muted", nk_rgb(160, 160, 160)));
|
||||
}
|
||||
if (e->items)
|
||||
reaktor_chevron_at(app, ctx, nk_rect(b.x + b.w - 22.0f, b.y, 16.0f, b.h),
|
||||
"chevron-forward-outline", fg);
|
||||
}
|
||||
|
||||
/* Draws column k with its top left at `at`, in whichever window holds it. */
|
||||
static void
|
||||
menu_draw_col(int k, struct nk_vec2 at)
|
||||
{
|
||||
struct nk_context *ctx = g_frame_ctx;
|
||||
App *app = g_frame_app;
|
||||
const menu_col *c = &g_menu.col[k];
|
||||
struct nk_vec2 pad = ctx->style.window.menu_padding;
|
||||
struct nk_command_buffer *cv = nk_window_get_canvas(ctx);
|
||||
struct nk_color fill = reaktor_token("--background", nk_rgb(53, 53, 53));
|
||||
struct nk_rect panel = nk_rect(at.x, at.y, c->r.w, c->r.h);
|
||||
float y = pad.y, rr = g_menu.inline_ ? reaktor_popup_rounding() : 0.0f;
|
||||
int i;
|
||||
|
||||
reaktor_fill_round(app, cv, panel, rr, reaktor_token("--background-hover", fill));
|
||||
reaktor_fill_round(app, cv, nk_rect(panel.x + 1.0f, panel.y + 1.0f,
|
||||
panel.w - 2.0f, panel.h - 2.0f),
|
||||
rr > 1.0f ? rr - 1.0f : 0.0f, fill);
|
||||
reaktor_note_push(app, REAKTOR_A11Y_MENU, c->name, NULL, REAKTOR_A11Y_EXPANDED, panel);
|
||||
for (i = 0; i < c->count; i++) {
|
||||
const reaktor_menu_entry *e = &c->items[i];
|
||||
float eh = menu_entry_h(e);
|
||||
struct nk_rect slot = nk_rect(at.x + pad.x, at.y + y, c->r.w - 2.0f * pad.x, eh);
|
||||
int open = k < g_menu.n - 1 && g_menu.path[k] == i;
|
||||
unsigned state = 0u, id;
|
||||
|
||||
y += eh + REAKTOR_MENU_GAP;
|
||||
nk_layout_space_push(ctx, nk_layout_space_rect_to_local(ctx, slot));
|
||||
if (menu_rule(e)) {
|
||||
nk_rule_horizontal(ctx, reaktor_token("--background-hover", nk_rgb(90, 90, 90)),
|
||||
nk_false);
|
||||
continue;
|
||||
}
|
||||
if (e->custom) {
|
||||
e->custom(app, ctx, e->on_press.user);
|
||||
continue;
|
||||
}
|
||||
if (e->checked && *e->checked) state |= REAKTOR_A11Y_CHECKED;
|
||||
if (e->disabled) state |= REAKTOR_A11Y_DISABLED;
|
||||
if (open) state |= REAKTOR_A11Y_EXPANDED;
|
||||
id = reaktor_note(app, REAKTOR_A11Y_MENUITEM, e->label, NULL, state, slot);
|
||||
if (e->keys) reaktor_note_keys(app, id, e->keys);
|
||||
if (!e->disabled) {
|
||||
reaktor_hot_top(app, slot, 1, 1);
|
||||
if (nk_input_is_mouse_hovering_rect(&ctx->input, slot) &&
|
||||
nk_input_is_mouse_moved(&ctx->input) &&
|
||||
(g_menu.hi[k] != i || g_menu.kcol != k || g_menu.depth != k + !!e->items)) {
|
||||
g_menu.hi[k] = i;
|
||||
g_menu.kcol = k;
|
||||
g_menu.depth = k + !!e->items;
|
||||
if (e->items) { g_menu.path[k] = i; g_menu.hi[k + 1] = -1; }
|
||||
menu_changed();
|
||||
}
|
||||
}
|
||||
if (nk_input_is_mouse_released(&ctx->input, NK_BUTTON_LEFT) &&
|
||||
nk_input_is_mouse_hovering_rect(&ctx->input, slot) && !e->disabled && !e->items) {
|
||||
g_menu.picked_k = k;
|
||||
g_menu.picked_i = i;
|
||||
menu_changed();
|
||||
}
|
||||
nk_spacing(ctx, 1);
|
||||
if (g_menu.keyed && g_menu.kcol == k && g_menu.hi[k] == i) {
|
||||
app->focus_id = id;
|
||||
reaktor_a11y_set_focus(&app->a11y, id);
|
||||
}
|
||||
menu_draw_entry(e, slot, c->lead, open || (g_menu.hi[k] == i && g_menu.kcol >= k));
|
||||
}
|
||||
reaktor_note_pop(app);
|
||||
}
|
||||
|
||||
static void
|
||||
menu_window(App *app, struct nk_context *ctx, int w, int h, void *user)
|
||||
{
|
||||
int k = (int)(intptr_t)user;
|
||||
|
||||
struct nk_rect o;
|
||||
|
||||
(void)app; (void)w;
|
||||
if (k >= g_menu.n) return;
|
||||
nk_layout_space_begin(ctx, NK_STATIC, (float)h, g_menu.col[k].count);
|
||||
o = nk_layout_space_rect_to_screen(ctx, nk_rect(0, 0, 0, 0));
|
||||
menu_draw_col(k, nk_vec2(o.x, o.y));
|
||||
nk_layout_space_end(ctx);
|
||||
}
|
||||
|
||||
static void
|
||||
menu_key(const reaktor_menubar_spec *s, App *app)
|
||||
{
|
||||
SDL_Keycode key = app->popup_key;
|
||||
int k = g_menu.kcol, *hi = &g_menu.hi[k];
|
||||
const menu_col *c = &g_menu.col[k];
|
||||
const reaktor_menu_entry *e = *hi >= 0 ? &c->items[*hi] : NULL;
|
||||
|
||||
app->popup_key = 0;
|
||||
if (!key) return;
|
||||
g_menu.keyed = 1;
|
||||
menu_changed();
|
||||
switch (key) {
|
||||
case SDLK_UP: *hi = menu_step(c->items, c->count, *hi, -1); return;
|
||||
case SDLK_DOWN: *hi = menu_step(c->items, c->count, *hi, 1); return;
|
||||
case SDLK_HOME: *hi = menu_step(c->items, c->count, -1, 1); return;
|
||||
case SDLK_END: *hi = menu_step(c->items, c->count, -1, -1); return;
|
||||
case SDLK_RIGHT: case SDLK_RETURN: case SDLK_KP_ENTER: case SDLK_SPACE:
|
||||
if (e && e->items && k < MENU_DEPTH) {
|
||||
g_menu.path[k] = *hi;
|
||||
g_menu.depth = k + 1;
|
||||
g_menu.kcol = k + 1;
|
||||
g_menu.hi[k + 1] = menu_step(e->items, e->count, -1, 1);
|
||||
} else if (key != SDLK_RIGHT && e) {
|
||||
g_menu.picked_k = k;
|
||||
g_menu.picked_i = *hi;
|
||||
} else if (key == SDLK_RIGHT) {
|
||||
menu_open_at((g_menu.open + 1) % s->count, 1);
|
||||
}
|
||||
return;
|
||||
case SDLK_LEFT:
|
||||
if (k > 0) { g_menu.depth = k - 1; g_menu.kcol = k - 1; }
|
||||
else menu_open_at((g_menu.open + s->count - 1) % s->count, 1);
|
||||
return;
|
||||
case SDLK_ESCAPE:
|
||||
if (k > 0) { g_menu.depth = k - 1; g_menu.kcol = k - 1; return; }
|
||||
reaktor_focus_take(app, g_menu.tid[g_menu.open], g_menu.title[g_menu.open]);
|
||||
g_menu.open = -1;
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
menu_build(const reaktor_menubar_spec *s)
|
||||
{
|
||||
struct nk_context *ctx = g_frame_ctx;
|
||||
struct nk_vec2 pad = ctx->style.window.menu_padding;
|
||||
const reaktor_menu *menu = &s->menus[g_menu.open];
|
||||
struct nk_rect b = nk_rect(0.0f, 0.0f, (float)g_frame_app->laid_w,
|
||||
(float)g_frame_app->laid_h);
|
||||
int k;
|
||||
|
||||
g_menu.inline_ = 1;
|
||||
#ifndef __EMSCRIPTEN__
|
||||
g_menu.inline_ = !reaktor_window_bounds(&b);
|
||||
#endif
|
||||
g_menu.col[0].items = menu->items;
|
||||
g_menu.col[0].count = menu->count;
|
||||
g_menu.col[0].name = menu->label;
|
||||
g_menu.n = 1;
|
||||
for (k = 0; k < g_menu.n; k++) {
|
||||
menu_col *c = &g_menu.col[k];
|
||||
int at;
|
||||
|
||||
c->src = c->items;
|
||||
c->count = NK_MIN(c->count, MENU_ITEMS);
|
||||
SDL_memcpy(c->copy, c->src, (size_t)c->count * sizeof *c->copy);
|
||||
c->items = c->copy;
|
||||
if (k >= g_menu.depth || g_menu.n == MENU_COLS) break;
|
||||
at = g_menu.path[k];
|
||||
if (at < 0 || at >= c->count || !c->items[at].items) break;
|
||||
g_menu.col[g_menu.n].items = c->items[at].items;
|
||||
g_menu.col[g_menu.n].count = c->items[at].count;
|
||||
g_menu.col[g_menu.n].name = c->items[at].label;
|
||||
g_menu.n++;
|
||||
}
|
||||
g_menu.depth = g_menu.n - 1;
|
||||
if (g_menu.kcol > g_menu.depth) g_menu.kcol = g_menu.depth;
|
||||
for (k = 0; k < g_menu.n; k++) {
|
||||
menu_col *c = &g_menu.col[k];
|
||||
|
||||
menu_measure(c, ctx->style.font, pad);
|
||||
menu_fit(c, k ? &g_menu.col[k - 1] : NULL, g_menu.title[g_menu.open], b);
|
||||
if (k) {
|
||||
c->r.y = menu_entry_y(&g_menu.col[k - 1], g_menu.path[k - 1]) - pad.y;
|
||||
menu_fit(c, &g_menu.col[k - 1], g_menu.title[g_menu.open], b);
|
||||
if (c->r.y + c->r.h > b.y + b.h) c->r.y = b.y + b.h - c->r.h;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
menu_windows(void)
|
||||
{
|
||||
int k;
|
||||
|
||||
for (k = 0; k < MENU_COLS; k++) {
|
||||
int want = g_menu.open >= 0 && !g_menu.inline_ && k < g_menu.n;
|
||||
|
||||
if (!want && g_menu.win[k]) {
|
||||
reaktor_window_close(g_frame_app, g_menu.win[k]);
|
||||
g_menu.win[k] = 0;
|
||||
} else if (want && g_menu.win[k]) {
|
||||
reaktor_window_move(g_menu.win[k], g_menu.col[k].r);
|
||||
} else if (want) {
|
||||
g_menu.win[k] = reaktor_window_popup(g_menu.col[k].r, menu_window,
|
||||
(void *)(intptr_t)k);
|
||||
if (!g_menu.win[k]) g_menu.inline_ = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
menu_inside(struct nk_vec2 p)
|
||||
{
|
||||
int k;
|
||||
|
||||
for (k = 0; k < g_menu.n; k++)
|
||||
if (NK_INBOX(p.x, p.y, g_menu.col[k].r.x, g_menu.col[k].r.y,
|
||||
g_menu.col[k].r.w, g_menu.col[k].r.h))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_menubar(const reaktor_menubar_spec *s)
|
||||
{
|
||||
struct nk_context *ctx = g_frame_ctx;
|
||||
App *app = g_frame_app;
|
||||
const struct nk_style_button *mb;
|
||||
const struct nk_user_font *f;
|
||||
reaktor_box bar, title;
|
||||
struct nk_rect r;
|
||||
float h;
|
||||
int m, picked = 0, on_title = 0;
|
||||
|
||||
if (!app || !s || !s->menus || s->count <= 0) return 0;
|
||||
f = ctx->style.font;
|
||||
mb = &ctx->style.menu_button;
|
||||
h = (float)(int)(f->height + 2.0f * (mb->padding.y + mb->border) + 0.5f);
|
||||
if (h < 26.0f) h = 26.0f;
|
||||
if (g_menu.open >= s->count) g_menu.open = -1;
|
||||
{
|
||||
int focused = (SDL_GetWindowFlags(app->win) & SDL_WINDOW_INPUT_FOCUS) != 0;
|
||||
|
||||
if (g_menu.focused && !focused) g_menu.open = -1;
|
||||
g_menu.focused = focused;
|
||||
}
|
||||
if (g_menu.open >= 0) menu_key(s, app);
|
||||
|
||||
bar = s->box;
|
||||
decl_box_default(&bar, 0.0f, h);
|
||||
reaktor_box_open(REAKTOR_LAY_ROW, &bar);
|
||||
reaktor_note_push(app, REAKTOR_A11Y_MENUBAR, s->name ? s->name : "Menu bar",
|
||||
NULL, 0u, reaktor_box_rect(&r) ? r : nk_rect(0, 0, 0, 0));
|
||||
for (m = 0; m < s->count && m < MENU_TITLES; m++) {
|
||||
const char *label = s->menus[m].label;
|
||||
struct nk_style_button st = *mb;
|
||||
|
||||
memset(&title, 0, sizeof(title));
|
||||
title.w = (float)(int)(menu_text_w(f, label) +
|
||||
2.0f * (mb->padding.x + mb->border + mb->rounding) + 2.5f);
|
||||
title.h = h;
|
||||
if (!decl_place(REAKTOR_A11Y_MENU, label, NULL,
|
||||
g_menu.open == m ? REAKTOR_A11Y_EXPANDED : 0u, NULL, &title,
|
||||
&g_menu.tid[m]))
|
||||
continue;
|
||||
r = nk_widget_bounds(ctx);
|
||||
g_menu.title[m] = r;
|
||||
reaktor_hot(app, r, 1, 1);
|
||||
if (g_menu.open == m) { st.normal = st.active; st.text_normal = st.text_active; }
|
||||
nk_button_text_styled(ctx, &st, label, (int)strlen(label));
|
||||
if (!nk_input_is_mouse_hovering_rect(&ctx->input, r)) continue;
|
||||
on_title = 1;
|
||||
if (g_menu.open >= 0 && g_menu.open != m && nk_input_is_mouse_moved(&ctx->input))
|
||||
menu_open_at(m, 0);
|
||||
if (nk_input_is_mouse_released(&ctx->input, NK_BUTTON_LEFT)) {
|
||||
if (g_menu.open == m) g_menu.open = -1;
|
||||
else menu_open_at(m, app->focus_id == g_menu.tid[m] && app->focus_visible);
|
||||
}
|
||||
}
|
||||
reaktor_note_pop(app);
|
||||
reaktor_box_close();
|
||||
|
||||
if (g_menu.open >= 0) {
|
||||
menu_build(s);
|
||||
if (g_menu.kbd && g_menu.hi[0] < 0)
|
||||
g_menu.hi[0] = menu_step(g_menu.col[0].items, g_menu.col[0].count, -1, 1);
|
||||
g_menu.kbd = 0;
|
||||
if (!on_title && nk_input_is_mouse_released(&ctx->input, NK_BUTTON_LEFT) &&
|
||||
!(g_menu.inline_ && menu_inside(ctx->input.mouse.pos)))
|
||||
g_menu.open = -1;
|
||||
}
|
||||
menu_windows();
|
||||
if (g_menu.open >= 0 && g_menu.inline_) {
|
||||
struct nk_rect u = g_menu.col[0].r;
|
||||
int k;
|
||||
|
||||
for (k = 1; k < g_menu.n; k++) u = nk_rect(NK_MIN(u.x, g_menu.col[k].r.x),
|
||||
NK_MIN(u.y, g_menu.col[k].r.y),
|
||||
0.0f, 0.0f);
|
||||
for (k = 0; k < g_menu.n; k++) {
|
||||
u.w = NK_MAX(u.w, g_menu.col[k].r.x + g_menu.col[k].r.w - u.x);
|
||||
u.h = NK_MAX(u.h, g_menu.col[k].r.y + g_menu.col[k].r.h - u.y);
|
||||
}
|
||||
if (reaktor_flyout_begin(ctx, "reaktor-menu", u)) {
|
||||
nk_layout_space_begin(ctx, NK_STATIC, u.h, 64);
|
||||
for (k = 0; k < g_menu.n; k++)
|
||||
menu_draw_col(k, nk_vec2(g_menu.col[k].r.x, g_menu.col[k].r.y));
|
||||
nk_layout_space_end(ctx);
|
||||
reaktor_flyout_end(ctx);
|
||||
}
|
||||
}
|
||||
if (g_menu.open >= 0) app->popup_open = 1;
|
||||
|
||||
if (g_menu.open >= 0 && g_menu.picked_k >= 0 && g_menu.picked_k < g_menu.n) {
|
||||
const reaktor_menu_entry *e = &g_menu.col[g_menu.picked_k].src[g_menu.picked_i];
|
||||
|
||||
if (e->checked) *e->checked = !*e->checked;
|
||||
if (e->on_press.fn) e->on_press.fn(e->on_press.user);
|
||||
if (s->picked_menu) *s->picked_menu = g_menu.open;
|
||||
if (s->picked_item) *s->picked_item = g_menu.picked_i;
|
||||
if (s->picked) *s->picked = e;
|
||||
if (g_menu.open >= 0 && g_menu.keyed)
|
||||
reaktor_focus_take(app, g_menu.tid[g_menu.open], g_menu.title[g_menu.open]);
|
||||
g_menu.picked_k = -1;
|
||||
g_menu.open = -1;
|
||||
app->popup_open = 0;
|
||||
menu_windows();
|
||||
picked = 1;
|
||||
}
|
||||
return picked;
|
||||
}
|
||||
|
||||
@@ -399,8 +399,20 @@ stepper_wash(App *app, struct nk_context *ctx, struct nk_rect sq)
|
||||
reaktor_fill_round(app, nk_window_get_canvas(ctx), sq, sq.w * 0.5f, wash);
|
||||
}
|
||||
|
||||
/* How far below a centered line's middle its capitals' middle lies. */
|
||||
float
|
||||
reaktor_cap_offset(const struct nk_user_font *f)
|
||||
{
|
||||
const struct nk_font *nf = f ? (const struct nk_font *)f->userdata.ptr : NULL;
|
||||
const struct nk_font_glyph *g = nf ? nk_font_find_glyph((struct nk_font *)nf, 'H') : NULL;
|
||||
|
||||
if (!g || nf->info.height <= 0.0f) return 0.0f;
|
||||
return ((g->y0 + g->y1) * 0.5f - nf->info.height * 0.5f) * f->height / nf->info.height;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_property_chrome(App *app, struct nk_context *ctx, struct nk_rect b)
|
||||
reaktor_property_chrome(App *app, struct nk_context *ctx, struct nk_rect b,
|
||||
struct nk_rect *steps)
|
||||
{
|
||||
const struct nk_style_property *st = &ctx->style.property;
|
||||
float h = ctx->style.font->height;
|
||||
@@ -408,7 +420,8 @@ reaktor_property_chrome(App *app, struct nk_context *ctx, struct nk_rect b)
|
||||
|
||||
l.w = l.h = r.w = r.h = h;
|
||||
l.x = b.x + st->border + st->padding.x;
|
||||
l.y = b.y + st->border + b.h * 0.5f - h * 0.5f;
|
||||
l.y = (float)(int)(b.y + b.h * 0.5f - h * 0.5f +
|
||||
reaktor_cap_offset(ctx->style.font) + 0.5f);
|
||||
r.x = b.x + b.w - (h + st->padding.x);
|
||||
r.y = l.y;
|
||||
hot_push(app, l, 0, 1);
|
||||
@@ -417,6 +430,7 @@ reaktor_property_chrome(App *app, struct nk_context *ctx, struct nk_rect b)
|
||||
stepper_wash(app, ctx, r);
|
||||
reaktor_chevron_at(app, ctx, l, "chevron-back-outline", st->dec_button.text_normal);
|
||||
reaktor_chevron_at(app, ctx, r, "chevron-forward-outline", st->inc_button.text_normal);
|
||||
if (steps) { steps[0] = l; steps[1] = r; }
|
||||
}
|
||||
|
||||
void
|
||||
@@ -675,6 +689,16 @@ field_edit(App *app, struct nk_context *ctx, nk_flags flags, char *buf,
|
||||
undo_drop(u, 0);
|
||||
held = undo_keep(u, buf, *len);
|
||||
}
|
||||
/* After the click that focused the field, which would move the caret. */
|
||||
if (win->edit.active && win->edit.seq == win->edit.name &&
|
||||
app->field_pick.buf == buf && app->field_pick.asked &&
|
||||
app->key_click == KEY_CLICK_NONE) {
|
||||
int to = NK_MIN(app->field_pick.to, *len), from = NK_MIN(app->field_pick.from, to);
|
||||
|
||||
win->edit.sel_start = nk_utf_len(buf, from);
|
||||
win->edit.sel_end = win->edit.cursor = nk_utf_len(buf, to);
|
||||
app->field_pick.buf = NULL;
|
||||
}
|
||||
if (held && win->edit.active && win->edit.seq == win->edit.name &&
|
||||
!(win->layout->flags & NK_WINDOW_ROM)) {
|
||||
struct field_step *s = NULL;
|
||||
@@ -726,14 +750,16 @@ reaktor_field_text_as(App *app, struct nk_context *ctx, const char *sel,
|
||||
reaktor_style s;
|
||||
reaktor_style_frame f;
|
||||
nk_flags state;
|
||||
struct nk_vec2 hint_pad;
|
||||
|
||||
note_field_rect(app, ctx, bounds);
|
||||
hot_push(app, bounds, 2, 0);
|
||||
|
||||
f = push_edit_style(ctx, &s, 0, sel);
|
||||
f = push_edit_style(ctx, &s, sel);
|
||||
reaktor_edit_edge(app, ctx, bounds, &s);
|
||||
if (pad_x > 0.0f) ctx->style.edit.padding.x = pad_x;
|
||||
if (pad_y > 0.0f) ctx->style.edit.padding.y = pad_y;
|
||||
hint_pad = ctx->style.edit.padding;
|
||||
/* One byte short, so the value is always there to be read as a string. */
|
||||
state = field_edit(app, ctx, flags, buf, len, cap > 0 ? cap - 1 : 0,
|
||||
filter);
|
||||
@@ -745,7 +771,16 @@ reaktor_field_text_as(App *app, struct nk_context *ctx, const char *sel,
|
||||
hint ? hint : ((flags & NK_EDIT_BOX) ? "Notes" : "Text"), buf,
|
||||
state & NK_EDIT_ACTIVE ? REAKTOR_A11Y_FOCUSED : 0u, bounds);
|
||||
|
||||
if (hint && *len == 0) draw_hint(ctx, bounds, hint, &s);
|
||||
if (hint && *len == 0) {
|
||||
struct nk_rect at = bounds;
|
||||
|
||||
/* Where the first line would be: a box's sits at the top. */
|
||||
if (flags & NK_EDIT_MULTILINE) {
|
||||
s.pad_x = hint_pad.x;
|
||||
at.h = 2.0f * hint_pad.y + ctx->style.font->height;
|
||||
}
|
||||
draw_hint(ctx, at, hint, &s);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -870,6 +905,17 @@ reaktor_note(App *app, unsigned char role, const char *name, const char *value,
|
||||
return id;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_focus_take(App *app, unsigned id, struct nk_rect b)
|
||||
{
|
||||
if (!id) return;
|
||||
app->focus_id = id;
|
||||
app->focus_visible = 1;
|
||||
app->dirty = 1;
|
||||
reaktor_a11y_set_focus(&app->a11y, id);
|
||||
focus_saw(app, id, b);
|
||||
}
|
||||
|
||||
unsigned
|
||||
reaktor_note_push(App *app, unsigned char role, const char *name,
|
||||
const char *value, unsigned state, struct nk_rect bounds)
|
||||
@@ -949,6 +995,33 @@ reaktor_style_font(App *app, const char *selector, int px, int bold)
|
||||
return reaktor_font(app, px, bold);
|
||||
}
|
||||
|
||||
/* A borderless popup of the current window at r, in screen coordinates. */
|
||||
int
|
||||
reaktor_flyout_begin(struct nk_context *ctx, const char *name, struct nk_rect r)
|
||||
{
|
||||
struct nk_rect clip = ctx->current->layout->clip;
|
||||
|
||||
nk_style_push_style_item(ctx, &ctx->style.window.fixed_background, nk_style_item_hide());
|
||||
nk_style_push_vec2(ctx, &ctx->style.window.popup_padding, nk_vec2(0.0f, 0.0f));
|
||||
nk_style_push_float(ctx, &ctx->style.window.popup_border, 0.0f);
|
||||
if (nk_popup_begin(ctx, NK_POPUP_STATIC, name, NK_WINDOW_NO_SCROLLBAR,
|
||||
nk_rect(r.x - clip.x, r.y - clip.y, r.w, r.h)))
|
||||
return 1;
|
||||
nk_style_pop_float(ctx);
|
||||
nk_style_pop_vec2(ctx);
|
||||
nk_style_pop_style_item(ctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_flyout_end(struct nk_context *ctx)
|
||||
{
|
||||
nk_popup_end(ctx);
|
||||
nk_style_pop_float(ctx);
|
||||
nk_style_pop_vec2(ctx);
|
||||
nk_style_pop_style_item(ctx);
|
||||
}
|
||||
|
||||
float
|
||||
reaktor_popup_rounding(void)
|
||||
{
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
# The four programs
|
||||
|
||||
All four share `runtime/` and `core/`; what differs is `samples/`, and which
|
||||
modules each links. The showcase takes all three — the accessibility bridges,
|
||||
Locale and Text. The others take none, so they show what the runtime costs by
|
||||
itself, and a screen reader finds nothing in them.
|
||||
modules each links. The showcase takes every module. Notepad takes settings, popup
|
||||
menus and printing; bench and simple take none, so they show what the runtime costs by
|
||||
itself. Without the accessibility module, a screen reader finds nothing in
|
||||
notepad, bench or simple.
|
||||
|
||||
| | Lines | For |
|
||||
| --- | --- | --- |
|
||||
| `showcase` | ~3,300 | Every widget and layer, both schemes, three languages, and how far the CSS reaches |
|
||||
| `notepad` | ~280 | A text editor that opens, edits and saves a file |
|
||||
| `notepad` | ~330 | A text editor that opens, edits, searches and saves a file of any size |
|
||||
| `bench` | ~150 | The workload the published figures measure, here and in four other frameworks |
|
||||
| `simple` | ~40 | One button that closes the window |
|
||||
|
||||
@@ -34,7 +35,7 @@ Animation, Styling, Translations, Diagnostics — with the color scheme and the
|
||||
titlebar switch at its foot, and an icon in the tray. It is the reference for
|
||||
what the library draws, and where its claims are tested rather than asserted:
|
||||
|
||||
- **Styling** lays simple.css over tiny.css at the flick of a checkbox, and
|
||||
- **Styling** lays Bamboo over Water.css at the flick of a checkbox, and
|
||||
prints what each rule resolved to beside the widgets it painted.
|
||||
- **Translations** sets the opening of *The Ugly Duckling* in English, Polish
|
||||
and Japanese from the catalogs, beside a date, a number, one amount in three
|
||||
@@ -56,8 +57,9 @@ what the library draws, and where its claims are tested rather than asserted:
|
||||
<img src="../assets/screenshots/notepad.png" alt="Notepad in the dark scheme under its native titlebar: a File and Help menu bar, the editor open on its own source, notepad.c, and a status line with the file name and its character count">
|
||||
</p>
|
||||
|
||||
A real editor in one file: a menu bar, a multiline field, a status line, the
|
||||
platform's own open and save dialogs, and five shortcuts. A page of widgets
|
||||
A real editor in one file: a menu bar, a multiline field with line numbers
|
||||
that grows to fit any file, a find bar, printing and PDF export, a status line, the platform's own open
|
||||
and save dialogs, and eight shortcuts. A page of widgets
|
||||
never has to answer what happens to a modified document, or where a menu's last
|
||||
item lands when its popup is a pixel short; this does.
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ errors, so an internal function cannot slip back in.
|
||||
| `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` |
|
||||
| `reaktor_set_visible(app, on)` | Show or hide that App's window; with `.window.hidden`, the main window waits for it |
|
||||
| `reaktor_version()` | Reaktor's version, such as `"0.5.1"` |
|
||||
| `reaktor_version()` | Reaktor's version, such as `"0.6.0"` |
|
||||
|
||||
The `set` calls are for the main thread, take effect at the next frame, and do
|
||||
nothing when nothing changes.
|
||||
@@ -122,15 +122,64 @@ save mode to last, and restores them at start. Under `--shot` and
|
||||
`--a11y-dump` settings are neither read nor written, so a user's file cannot
|
||||
change a test.
|
||||
|
||||
**Notifications.** `reaktor_notify(app, &(reaktor_notification){ .title,
|
||||
.text })` tells the user something outside the window and answers 1 when it
|
||||
was sent. On Windows it is a balloon from an icon of the app's own, which
|
||||
Windows 10 and 11 show as a toast headed by the program's name, and the icon
|
||||
goes ten seconds later; on Linux and the BSDs, a `Notify` call to
|
||||
`org.freedesktop.Notifications` over `dbus-1`; on macOS,
|
||||
`UNUserNotificationCenter`, which answers 0 outside an app bundle; on the web,
|
||||
the browser's `Notification`, after it asks for permission once. A click on
|
||||
one is not reported.
|
||||
|
||||
**Printing.** `reaktor_print(app, &(reaktor_print_spec){ ... })` prints pages
|
||||
the application lays out, and `reaktor_print_pdf(app, path, &spec)` writes
|
||||
them to a PDF. `.page(app, ctx, index, w, h, user)` draws page `index` of
|
||||
`.pages` (up to 64) as a page hook would, `w` by `h` points: `.w` and `.h`, A4
|
||||
when unset. Each page is laid out and drawn as on screen, in a hidden window
|
||||
at `.dpi` (200 unset), so it carries the window's look: a page that should be
|
||||
white paints itself white. Both calls answer 1 when the job is queued; it runs
|
||||
between frames, and `.done(app, ok, user)` says how it went. A page is an
|
||||
image in the PDF, through [libHaru](https://github.com/libharu/libharu) and
|
||||
plutovg's JPEG writer, so its text is not selectable. To print, Windows shows
|
||||
its print dialog and draws the pages to the printer; macOS opens its print
|
||||
dialog on the PDF; Linux and the BSDs open the PDF in the user's viewer, which
|
||||
prints it. The web build does not print.
|
||||
|
||||
**Undo.** Each window keeps a stack of steps. `reaktor_undo_push(app,
|
||||
&(reaktor_undo_step){ .label, .undo, .redo, .free, .data, .merge })` records
|
||||
one the application has already done: `.undo(data)` and `.redo(data)` take it
|
||||
back and do it again, and `.free(data)` runs when the step is dropped. Steps
|
||||
pushed between `reaktor_undo_group(app, 1)` and `reaktor_undo_group(app, 0)`
|
||||
undo as one, and so do consecutive steps with the same nonzero `.merge`, as
|
||||
typing does. `reaktor_undo` and `reaktor_redo` take one step back or forward,
|
||||
`reaktor_undo_label` and `reaktor_redo_label` name it for a menu entry,
|
||||
`reaktor_undo_saved` marks where the document was saved and
|
||||
`reaktor_undo_dirty` says whether it has changed since. A new step drops the
|
||||
ones that could be redone. Ctrl+Z, and Ctrl+Y or Ctrl+Shift+Z, reach the stack
|
||||
when no field is being edited, as a field keeps its own history; the `key`
|
||||
hook sees them first.
|
||||
|
||||
| Call | Effect |
|
||||
| --- | --- |
|
||||
| `reaktor_undo_push(app, step)` | Record a step already done |
|
||||
| `reaktor_undo(app)`, `reaktor_redo(app)` | Take one back, or do it again; 0 when there is none |
|
||||
| `reaktor_undo_label(app)`, `reaktor_redo_label(app)` | What they would undo or redo, or `NULL` |
|
||||
| `reaktor_undo_group(app, begin)` | Steps between `1` and `0` undo as one |
|
||||
| `reaktor_undo_saved(app)`, `reaktor_undo_dirty(app)` | Mark the saved state; whether it has changed since |
|
||||
| `reaktor_undo_clear(app)` | Drop every step |
|
||||
|
||||
Clipboard, URLs and logging are SDL's: `SDL_SetClipboardText`,
|
||||
`SDL_GetClipboardText`, `SDL_OpenURL` (behind a link's `.url`), `SDL_Log`.
|
||||
`SDL_GetClipboardText`, `SDL_OpenURL` (behind a link's `.url`), `SDL_Log`;
|
||||
`.log` names a file that gets a copy of every line, with the time, priority
|
||||
and category, appended; `--log <path>` overrides it.
|
||||
|
||||
**Console.** `.console` is `REAKTOR_CONSOLE_NONE` (the window alone),
|
||||
`_PARENT` (on Windows, the terminal it was started from) or `_DEBUG` (that
|
||||
terminal or a console of its own, plus SDL's debug log). A redirected stream
|
||||
stays redirected. Ctrl+C reaches the app only from a console it owns.
|
||||
|
||||
**Assets.** `.css` adds up to four sheets after tiny.css and reaktor.css
|
||||
**Assets.** `.css` adds up to four sheets after Water.css and reaktor.css
|
||||
(`.no_reaktor_css` drops reaktor.css), `.font` and `.font_bold` replace
|
||||
Aileron (which stands in for one that cannot be read, or that is cut short or
|
||||
not a font at all), `.font_fallbacks` feed the Text module, `.icon_dirs` are searched for
|
||||
@@ -165,7 +214,7 @@ again), `.style` (a selector to read instead of the widget's own) and `.box`
|
||||
| Label | `reaktor_label` | — | `.text`, `.wrap`, `.align` (`REAKTOR_LEFT`, `_CENTER`, `_RIGHT`), `.color` (a token), `.value`, `.silent` (left out of the tree) |
|
||||
| Icon | `reaktor_icon` | — | `.name` (an Ionicon) and `.accent`, or `.src` (any image asset: SVG, PNG, JPEG), stretched to its box; `.tooltip` |
|
||||
| Swatch | `reaktor_swatch` | when pressed | `.fill`, `.on_press` |
|
||||
| Field | `reaktor_field` | — | `.buf`, `.len`, `.cap`, `.hint`, `.multiline`, `.filter`, `.pad_x`, `.pad_y` |
|
||||
| Field | `reaktor_field` | — | `.buf`, `.len`, `.cap`, or `.heap` and `.heap_cap`; `.hint`, `.multiline`, `.line_numbers`, `.filter`, `.pad_x`, `.pad_y` |
|
||||
| Check | `reaktor_check` | when toggled | `.label`, `.on`, or `.flags` and `.bit`; `.box_right` |
|
||||
| Radio | `reaktor_radio` | when pressed | `.label`, `.choice`, `.value` |
|
||||
| Select | `reaktor_select` | when toggled | `.label`, `.on`, `.icon`, `.disc`, `.centered` |
|
||||
@@ -173,11 +222,16 @@ again), `.style` (a selector to read instead of the widget's own) and `.box`
|
||||
| Progress | `reaktor_progress` | — | `.value`, `.max`, `.modifiable` (draggable) |
|
||||
| Knob | `reaktor_knob` | — | `.value`, `.lo`, `.hi` |
|
||||
| Property | `reaktor_property` | — | `.label`, `.ivalue`, `.fvalue` or `.dvalue`, `.lo`, `.hi`, `.step`, `.grain` (per pixel dragged) |
|
||||
| Spinner | `reaktor_spinner` | when it steps | `.label`, `.items` and `.count`, `.chosen`, `.wrap`; drawn as a property, stepped by its chevrons or the arrow keys |
|
||||
| Date | `reaktor_date_pick` | when a date is set | `.year`, `.month`, `.day` (0 until set), `.min_year`, `.max_year` |
|
||||
| Time | `reaktor_time_pick` | when a time is set | `.hour` (-1 until set), `.minute`, `.clock12` |
|
||||
| Combo | `REAKTOR_COMBO(...) { }` | — | `.label`, `.body_h`, `.disc`, `.swatch`; rows by `reaktor_combo_item(label, chosen)` |
|
||||
| Color | `reaktor_color_pick` | — | `.value`, a `struct reaktor_colorf` |
|
||||
| Sidebar | `reaktor_sidebar` | when an entry is chosen | [below](#sidebar-and-tabs) |
|
||||
| Tabs | `reaktor_tabs` | when an entry is chosen | [below](#sidebar-and-tabs) |
|
||||
| List | `reaktor_list` | when another row is chosen | `.count`, `.cell(row, column, user)`, `.column_count`, `.columns` (headers), `.widths` (shares), `.selected`, `.row_h` |
|
||||
| Menu bar | `reaktor_menubar` | when an item is chosen | [below](#menu-bar) |
|
||||
| List | `reaktor_list` | when another row is chosen, or one is dropped on it | `.count`, `.cell(row, column, user)`, `.column_count`, `.columns` (headers), `.widths` (shares), `.selected`, `.row_h`, `.drag` and `.dropped` |
|
||||
| Tree | `reaktor_tree` | when another node is chosen | `.count`, `.parent(node, user)`, `.label(node, user)`, `.icon(node, user)`, `.open` (a flag per node), `.selected` (a node), `.row_h` |
|
||||
| Splitter | `reaktor_splitter` | while dragged | `.value` (the first child's share, 0 to 1), `.lo`, `.hi` (0.1 and 0.9 unset), `.vertical` |
|
||||
|
||||
**An icon gives way to its label**: a button too narrow for both draws the
|
||||
@@ -189,6 +243,29 @@ anywhere else reseeds the buffer. Ctrl+Z and Ctrl+R undo and redo from a
|
||||
history each field keeps; editing another field, or changing the value in
|
||||
code, starts it over.
|
||||
|
||||
**A field can grow.** Given `.heap` and `.heap_cap` instead of `.buf` and
|
||||
`.cap`, it keeps the buffer, from `SDL_malloc` or `NULL`, large enough for what
|
||||
is typed or pasted, and the caller frees it with `SDL_free`. `.line_numbers`
|
||||
draws a gutter of line numbers beside a multiline field.
|
||||
`reaktor_field_select(app, buf, from, to)` focuses the field whose buffer is
|
||||
`buf` and selects bytes `from` to `to`, scrolling them into view: a find bar
|
||||
is a search over the buffer and this call, as in the notepad sample. Lines do
|
||||
not wrap: Nuklear's editor lays text out in hard lines only.
|
||||
|
||||
**A date or time is picked on wheels.** The field is drawn as an input,
|
||||
from `input`, and shows the value as the language writes a short date or
|
||||
time, or a hint (`date.day`, `date.month`, `date.year`, `time.hour`,
|
||||
`time.minute`) until one is set. A click or Enter opens wheels over it, a
|
||||
dialog surface with a wheel per part in the language's order: days, months
|
||||
and hours loop, years stop at `.min_year` and `.max_year` (1900 and 2100
|
||||
unset). Scroll a wheel, click a row, or use the arrows: Up and Down turn the
|
||||
focused wheel, Left and Right move between wheels. Enter or OK
|
||||
(`button.ok`) sets the value and answers 1; Escape, Cancel (`button.cancel`)
|
||||
or a click outside leaves it. Days follow the
|
||||
month and year on the wheels. Month names are the stand-alone form,
|
||||
`date.months.standalone`, as Polish names a month alone differently from one
|
||||
in a date.
|
||||
|
||||
**A tooltip** follows the pointer while its widget is hovered, above
|
||||
everything, styled by `.tooltip`.
|
||||
|
||||
@@ -197,7 +274,25 @@ first column names the row. With `.selected`, a click picks a row and the
|
||||
selection follows keyboard focus; the arrow keys move it, scrolling the row
|
||||
into view. Without it the rows are plain text. Unsized, a list shows up to
|
||||
eight rows and fills its row. Colors come from `thead`, `th`, `td`,
|
||||
`--table-bg` and `--table-bg-alt`, as in tiny.css.
|
||||
`--table-bg` and `--table-bg-alt`, which reaktor.css takes from Water.css's
|
||||
`--links`, `--background-body` and `--background-alt`.
|
||||
|
||||
**A row can be dragged** out of a list that names a `.drag` kind, a string.
|
||||
Its first column follows the pointer as a tooltip would, and any list of the
|
||||
same kind under the pointer, the same one included, draws a line where it
|
||||
would land. On release that list calls `.dropped(from, item, at, user)`:
|
||||
`from` is the name of the list it left, `item` its row there, and `at` the
|
||||
place between this list's rows it lands, counted before the row is taken out.
|
||||
Moving it is the caller's, so a list can copy instead.
|
||||
|
||||
**A tree is a list of its nodes in depth-first order**, each naming its
|
||||
parent, or -1 for a root; a node with children is followed by them. `.open`
|
||||
holds a flag per node, written when a branch opens or closes, and `.selected`
|
||||
a node. It is drawn as a list is, only the rows on screen, styled the same,
|
||||
each indented under its parent with a chevron on every branch. Up and Down
|
||||
move between rows; Right opens a branch or steps into it, Left closes it or
|
||||
steps out to its parent; a click on a chevron opens or closes it. Screen
|
||||
readers see tree items with their expanded and selected states.
|
||||
|
||||
**A splitter** writes the first child's share; pass it to both children's
|
||||
`.weight`. It drags, and with focus the arrow keys step it by 5%, moving the
|
||||
@@ -251,6 +346,54 @@ if (reaktor_sidebar(&(reaktor_sidebar_spec){
|
||||
show(page);
|
||||
```
|
||||
|
||||
### Menu bar
|
||||
|
||||
`reaktor_menubar` takes `.menus` and `.count`; each `reaktor_menu` is a
|
||||
`.label` and its `.items`. An entry has a `.label`, and optionally an `.icon`
|
||||
(an Ionicon), `.keys` (the shortcut, drawn at the right and announced; the
|
||||
`key` hook still handles it), `.checked` (toggled on choice, drawn as a dot),
|
||||
`.disabled` and `.on_press`. `.items` and `.count` make it a submenu.
|
||||
`.custom(app, ctx, user)` makes it a row of its own: the callback draws one
|
||||
widget into the row with the App and context of the window it is in,
|
||||
`.height` and `.width` size it, and `.on_press.user` is its `user`. An entry with neither a label nor `.custom` is a separator. The call
|
||||
answers 1 when an entry is chosen, writing the entry to `.picked`, its menu
|
||||
to `.picked_menu` and its place among its siblings to `.picked_item`.
|
||||
|
||||
```c
|
||||
static const reaktor_menu_entry zoom[] = {
|
||||
{ .label = "Zoom in", .keys = "Ctrl++" }, { .label = "Zoom out", .keys = "Ctrl+-" }
|
||||
};
|
||||
static const reaktor_menu_entry view[] = {
|
||||
{ .label = "Zoom", .items = zoom, .count = 2 },
|
||||
{ NULL },
|
||||
{ .label = "Full screen", .keys = "F11" }
|
||||
};
|
||||
static const reaktor_menu menus[] = { { "View", view, 3 } };
|
||||
const reaktor_menu_entry *e;
|
||||
|
||||
if (reaktor_menubar(&(reaktor_menubar_spec){ .menus = menus, .count = 1, .picked = &e }))
|
||||
run(e);
|
||||
```
|
||||
|
||||
Tab reaches each title. Enter opens its menu and moves focus to the first
|
||||
entry; Up and Down walk the entries, skipping disabled ones; Right opens a
|
||||
submenu, or the next menu; Left closes a submenu, or opens the previous menu;
|
||||
Escape closes one level and hands focus back. The pointer opens a submenu by
|
||||
hovering its entry. Screen readers see a menu bar, menus and menu items with
|
||||
their checked, expanded and disabled states.
|
||||
|
||||
**A menu is a window of its own.** On the desktop each open menu and submenu
|
||||
is an SDL popup-menu window, so it can reach past the main window's edge; it
|
||||
never takes keyboard focus, so the keys still reach the main window and the
|
||||
menu. A submenu opens to the right of its entry, or to the left when the
|
||||
display has no room, and a menu that would run off the bottom opens above its
|
||||
title. The web has no such windows, so there the menu is a popup in the page,
|
||||
fitted the same way inside the canvas, as it is if a window cannot be made.
|
||||
The windows are drawn after the frame, from a copy of each open menu's
|
||||
entries taken by the call, so the arrays need not outlive it; up to 32
|
||||
entries a menu are shown. Titles are Nuklear's menu button, which
|
||||
`style_map.c` styles.
|
||||
|
||||
## Layout
|
||||
|
||||
Containers are scopes, and children are declared inside them.
|
||||
@@ -312,7 +455,7 @@ in [`include/reaktor/ui.h`](../include/reaktor/ui.h); all of them are main-threa
|
||||
|
||||
A dialog inside the main window. `reaktor_floater_open` centers one whose body
|
||||
is `.w` by `.h`, as CSS sizes a box, with the `dialog` rule's padding around it;
|
||||
it answers its id, and calls `.body` every frame inside tiny.css's `dialog`
|
||||
it answers its id, and calls `.body` every frame inside the `dialog` rule's
|
||||
look, with the body's size; `.title` is its accessible name. A `.modal` one dims the window by
|
||||
`--dialog-backdrop` and holds everything under it — the page, the toasts,
|
||||
earlier floaters — until it closes, and Tab stays with it and the floaters
|
||||
@@ -424,11 +567,51 @@ and GTK 3 when the tray opens; nothing links them, and without them there is
|
||||
no tray. GTK sets the user's locale as it starts, and the runtime puts the C
|
||||
library's back.
|
||||
|
||||
### Inspector
|
||||
|
||||
The Inspector looks into a running app from a window of its own, titled
|
||||
"<window title> - Inspector"; on the web it is a floater in the page. Its tabs:
|
||||
|
||||
- **Tree**: the widget tree, as screen readers get it. Selecting a node
|
||||
outlines the widget in the app; **Pick**, then a click in the app, selects
|
||||
the widget under the pointer without pressing it.
|
||||
- **Box**: the widget's bounds, its rectangle in its parent, and where its
|
||||
width and height come from: its parent, its content, the stylesheet, or the
|
||||
page. A size the page fixed is one no rule can change.
|
||||
- **Style**: what the widget's element (`button`, `input`, ...) gets from the
|
||||
sheets, and a box of CSS applied after every other sheet, to this run only.
|
||||
- **Frame**: frames drawn, what made the last one run, and the build, render
|
||||
and present times.
|
||||
- **Logs**: every `SDL_Log` line since the app started, filtered by priority.
|
||||
|
||||
An app opts in with `.inspector`; left zero, there is no Inspector and the
|
||||
shortcut is the app's. `.mods` and `.key` replace the shortcut, Ctrl+Shift+I
|
||||
(Cmd+Option+I on macOS); `.key = -1` leaves it without one. `.open` opens it at
|
||||
start.
|
||||
|
||||
```c
|
||||
launchApp(argc, argv, &(reaktor_launch){
|
||||
.inspector = { .attach = 1 },
|
||||
.page = page });
|
||||
```
|
||||
|
||||
`reaktor_inspector_open(app)` opens it and answers 0 when the app has none,
|
||||
`reaktor_inspector_close(app)` closes it, and `reaktor_inspector_shown(app)`
|
||||
says whether it is open. `--inspect` opens it at start and `--no-inspector`
|
||||
detaches it, but no flag gives an Inspector to an app that did not attach one.
|
||||
|
||||
## Styling
|
||||
|
||||
Sheets are read in order and the last rule wins, as CSS settles a tie:
|
||||
tiny.css's palette (`variables-light.css` or `variables-dark.css`), tiny.css,
|
||||
`reaktor.css`, the application's `.css`, then `--css`. Nothing merges them.
|
||||
Water.css's palette (`variables-light.css` or `variables-dark.css`), Water.css
|
||||
(`parts/_core.css` and the parts it imports), `reaktor.css`, the application's
|
||||
`.css`, then `--css`. Nothing merges them. An `@import` is read in place,
|
||||
relative to the sheet that names it; one with a condition, such as
|
||||
`(prefers-color-scheme: dark)`, is read as that `@media` block. A selector or
|
||||
value longer than libcss holds as one token, or a value with a `;` in it, is
|
||||
dropped before libcss sees it. A field filled exactly like the rounded panel it sits on
|
||||
takes the page's color instead, so a sheet that styles `input` and `details`
|
||||
alike still shows its fields on a card.
|
||||
|
||||
A widget asks for a selector and gets computed values, or `matched` clear and
|
||||
Nuklear's default:
|
||||
@@ -495,11 +678,11 @@ and the accent. An icon on a button takes its label's color.
|
||||
current sidebar entry from `--links`.
|
||||
|
||||
`reaktor_set_css` swaps the application's sheets at the next frame. The
|
||||
showcase's Styling page lays simple.css over tiny.css that way, which is the
|
||||
test that the look is not in the code. reaktor.css is written in tiny.css's
|
||||
showcase's Styling page lays Bamboo over Water.css that way, which is the
|
||||
test that the look is not in the code. reaktor.css is written in Water.css's
|
||||
names, so once such a sheet is read, `--links`, `--background-body` and
|
||||
`--text-main` are given its link, page and text colors in one more sheet read
|
||||
last; Reaktor's own chrome then follows it too. A sheet laid over tiny.css
|
||||
last; Reaktor's own chrome then follows it too. A sheet laid over Water.css
|
||||
costs a second read.
|
||||
|
||||
## Keyboard
|
||||
@@ -653,7 +836,7 @@ samples/ showcase, notepad, simple, bench
|
||||
tests/ the console tests and launchtest
|
||||
tools/ packaging, the icon compiler, vmwalk
|
||||
benchmarks/ bench in four other frameworks, and the sampler
|
||||
external/ twelve submodules, read as they ship
|
||||
external/ thirteen submodules, read as they ship
|
||||
```
|
||||
|
||||
`runtime/` and `core/` build `reaktor_runtime`, a static library every
|
||||
@@ -663,11 +846,11 @@ in `core/` knows which application it is in.
|
||||
|
||||
**The default look is compiled in**: Aileron in both weights, the mark, the
|
||||
seven Ionicons the widgets draw (three chevrons, three discs and the toast's
|
||||
close cross), `reaktor.css` and tiny.css's three sheets, copied byte for byte
|
||||
close cross), `reaktor.css` and Water.css's palettes and parts, copied byte for byte
|
||||
at configure time. `reaktor_asset_load` still tries the file under the
|
||||
`.reaktor-root` marker first, so an edited sheet shows without a rebuild.
|
||||
Nothing is read from the working directory, and a path a user hands over is
|
||||
made absolute where it is taken. The rest of Ionicons, simple.css and the
|
||||
made absolute where it is taken. The rest of Ionicons, Bamboo and the
|
||||
catalogs are read from files; an icon that is not there is drawn as nothing,
|
||||
and the log names it.
|
||||
|
||||
@@ -780,7 +963,7 @@ mojibake and kb_text_shape, merged with `lib.exe`, Apple's `libtool` or an
|
||||
and SDL's, a CMake package, a pkg-config file and `share/reaktor/licenses`:
|
||||
|
||||
```cmake
|
||||
find_package(reaktor 0.5 REQUIRED)
|
||||
find_package(reaktor 0.6 REQUIRED)
|
||||
add_executable(app WIN32 main.c)
|
||||
target_link_libraries(app PRIVATE reaktor::reaktor)
|
||||
```
|
||||
@@ -827,6 +1010,12 @@ Passed to CMake, through either script:
|
||||
| `REAKTOR_LOCALE` | `ON` | Translations and formatting — [Localization](#localization) |
|
||||
| `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_SETTINGS` | `ON` | Settings kept between runs, in `settings.conf` |
|
||||
| `REAKTOR_TRAY` | `ON` | The tray icon |
|
||||
| `REAKTOR_POPUP_WINDOWS` | `ON` | Menus in windows of their own |
|
||||
| `REAKTOR_NOTIFY` | `ON` | System notifications |
|
||||
| `REAKTOR_PRINT` | `ON` | Printing and PDF export, through libHaru |
|
||||
| `REAKTOR_INSPECTOR` | `ON` | The [Inspector](#inspector) |
|
||||
| `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 `tests/` |
|
||||
| `REAKTOR_INSTALL` | `ON` at the top | Install rules for libreaktor's files |
|
||||
@@ -835,10 +1024,10 @@ Passed to CMake, through either script:
|
||||
pass `=ON` to switch one back.
|
||||
|
||||
**A module is two interface libraries**, and a program links one:
|
||||
`reaktor_a11y` or `reaktor_a11y_none`, and likewise `_locale` and `_text`.
|
||||
Both define the same functions. The showcase takes all three modules;
|
||||
`simple`, `notepad` and `bench` take none, and show what the runtime costs
|
||||
alone. An option switched off swaps in the `_none` half everywhere, and leaves
|
||||
`reaktor_a11y` or `reaktor_a11y_none`, and likewise `_locale`, `_text`,
|
||||
`_settings`, `_tray`, `_popups`, `_notify`, `_print` and `_inspector`. Both define the same functions. The
|
||||
showcase takes every module; `notepad` takes settings, popups and print; `simple` and
|
||||
`bench` take none, and show what the runtime costs alone. An option switched off swaps in the `_none` half everywhere, and leaves
|
||||
pixels and `--a11y-dump` byte-identical apart from what the module itself
|
||||
produces.
|
||||
|
||||
@@ -847,7 +1036,7 @@ reaktor_add_app(myapp MODULES a11y locale SOURCES main.c)
|
||||
```
|
||||
|
||||
`reaktor_add_app` links the modules named and the `_none` half of the rest
|
||||
(all three when `MODULES` is left out, none with `MODULES none`), builds a
|
||||
(all of them when `MODULES` is left out, none with `MODULES none`), builds a
|
||||
windowed program unless `CONSOLE` is given, and on the web adds the link
|
||||
options a page needs; `ASSETS <file>@<path>` packs files beside it there.
|
||||
|
||||
@@ -862,6 +1051,19 @@ options a page needs; `ASSETS <file>@<path>` packs files beside it there.
|
||||
- **`REAKTOR_TEXT=OFF`** leaves mojibake and kb_text_shape out. Nothing is
|
||||
reordered, shaped or taken from another font, and a line breaks after a
|
||||
space: Polish is untouched, Japanese comes out as boxes.
|
||||
- **`REAKTOR_SETTINGS=OFF`** leaves `ini.h` and the web's IndexedDB out:
|
||||
`reaktor_setting` answers `NULL`, saving and clearing do nothing, and
|
||||
`.remember_window` is ignored.
|
||||
- **`REAKTOR_TRAY=OFF`** answers 0 from `reaktor_tray_open`, so AppIndicator
|
||||
and GTK 3 are never loaded on Linux and the BSDs.
|
||||
- **`REAKTOR_PRINT=OFF`** leaves libHaru out; `reaktor_print` and
|
||||
`reaktor_print_pdf` answer 0.
|
||||
- **`REAKTOR_INSPECTOR=OFF`** answers 0 from `reaktor_inspector_open` and
|
||||
ignores `.inspector`, its shortcut and its flags.
|
||||
- **`REAKTOR_NOTIFY=OFF`** answers 0 from `reaktor_notify` and links nothing
|
||||
for it: not `shell32`, `dbus-1` or the UserNotifications framework.
|
||||
- **`REAKTOR_POPUP_WINDOWS=OFF`** draws menus inside the window, fitted to it,
|
||||
as the web does; `--popups inline` does the same without a rebuild.
|
||||
|
||||
## Command-line flags
|
||||
|
||||
@@ -877,7 +1079,10 @@ removes them from `argv` before the application sees it:
|
||||
| `--font-fallback <path>` | A font for the Text module, before the application's; repeatable |
|
||||
| `--renderer <name>` | `software` (default), `auto`, or a driver name |
|
||||
| `--video <name>` | SDL's video driver: `x11`, `wayland`, `dummy` |
|
||||
| `--popups inline` | Menus inside the window, not in windows of their own |
|
||||
| `--console <none\|parent\|debug>` | Override `.console` |
|
||||
| `--log <path>` | Override `.log` |
|
||||
| `--inspect`, `--no-inspector` | Open the [Inspector](#inspector) at start; detach it |
|
||||
| `--css <path>` | A sheet after the application's; up to four |
|
||||
| `--font <path>`, `--font-bold <path>` | Replace the UI face and its bold |
|
||||
| `--icons <dir>` | Look for `<name>.svg` here first; up to four |
|
||||
@@ -921,9 +1126,9 @@ Built by default and run from `build/`:
|
||||
| `animtest` | Curves, retargeting, a context a window |
|
||||
| `keytest` | Chord parsing and formatting |
|
||||
| `localetest` | Catalogs, lookup, plural rules, formatting |
|
||||
| `csstest` | Flattening a sheet for libcss: what is rewritten, what is dropped, and simple.css read through it |
|
||||
| `csstest` | Flattening a sheet for libcss: what is rewritten, what is dropped, and Bamboo read through it |
|
||||
| `texttest` | Line breaks, direction, measuring and glyph order, against `assets/fonts`; with the Text module |
|
||||
| `launchtest` | Opt-in (`./build.ps1 launchtest`): `launchApp`'s hooks by mode (`start-fail`, `quit`, `veto`, `title`, `confirm`, `confirm-cancel`), the services (`ask`, `timer`, `post`, `settings`, `save-change`, `save-timer`, `settings-clear`, `list`, `list-keys`, `split-keys`, `split-vkeys`, `tip`; `dialog-open`, `dialog-many`, `dialog-save` and `dialog-folder` wait for someone to answer the system's dialog), what a floater, toast or popup holds and where keys go (the `hold-` modes), and a window beside the main one (`window-text` and the `win-` modes: keys, drops, animation, title, theme, wakes, a drag, one change a frame, the picker, memory, `win-hints`) |
|
||||
| `launchtest` | Opt-in (`./build.ps1 launchtest`): `launchApp`'s hooks by mode (`start-fail`, `quit`, `veto`, `title`, `confirm`, `confirm-cancel`), the services (`ask`, `timer`, `post`, `settings`, `save-change`, `save-timer`, `settings-clear`, `list`, `list-keys`, `tree-keys`, `field-find`, `spin-keys`, `date-keys`, `undo`, `print-pdf`, `split-keys`, `split-vkeys`, `menu-keys`, `tip`; `dialog-open`, `dialog-many`, `dialog-save` and `dialog-folder` wait for someone to answer the system's dialog), what a floater, toast or popup holds and where keys go (the `hold-` modes), and a window beside the main one (`window-text` and the `win-` modes: keys, drops, animation, title, theme, wakes, a drag, one change a frame, the picker, memory, `win-hints`) |
|
||||
|
||||
Beyond those, check a visual change against the framebuffer (`--shot`) and the
|
||||
dump, not against a reading of the source.
|
||||
@@ -1030,8 +1235,10 @@ Formatting reads these keys, and a key a catalog leaves out is English's:
|
||||
| `date.days`, `date.days.short` | `Sunday \| …` | Seven, Sunday first |
|
||||
| `time.ampm` | `AM \| PM` | |
|
||||
|
||||
A pattern is made of `d dd M MM MMM MMMM y yy EEE EEEE H HH h hh m mm a`, with
|
||||
`'quoted'` text kept. The weekday is computed from the date. A catalog says
|
||||
A pattern is made of `d dd M MM MMM MMMM LLLL y yy EEE EEEE H HH h hh m mm a`,
|
||||
with `'quoted'` text kept; `LLLL` is a month's stand-alone name, from
|
||||
`date.months.standalone` where a catalog has it. `reaktor_format_pattern(buf,
|
||||
cap, tm, pattern)` formats any pattern. The weekday is computed from the date. A catalog says
|
||||
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`.
|
||||
@@ -1111,7 +1318,7 @@ None is a bug, and each cost an afternoon.
|
||||
`NK_BUTTON_TRIGGER_ON_RELEASE` is defined.
|
||||
- **A button's content rect is bounds − padding − border − rounding.** A large
|
||||
radius drives a small button's content negative and its symbol vanishes.
|
||||
- **A negative content rect moves the label instead of hiding it**: tiny.css's
|
||||
- **A negative content rect moves the label instead of hiding it**: a sheet's
|
||||
inset drew labels 4.6 px low on 30 px controls. `style_map.c` trims the
|
||||
vertical padding to what the row holds.
|
||||
- **`nk_stroke_rect` is asymmetric**, 1 px on the left and top of a 2 px
|
||||
|
||||
@@ -0,0 +1,258 @@
|
||||
# Frequently asked questions
|
||||
|
||||
> Short answers, each linking to the part of
|
||||
> [DOCUMENTATION.md](DOCUMENTATION.md) that covers it in full.
|
||||
> Something missing? [Open an issue](https://github.com/Alpaq92/Reaktor/issues).
|
||||
|
||||
**What and why**
|
||||
|
||||
- [What is Reaktor, and how is it different from Nuklear?](#what-is-reaktor-and-how-is-it-different-from-nuklear)
|
||||
- [Why C99 and an immediate-mode core instead of a retained toolkit like GTK or Qt?](#why-c99-and-an-immediate-mode-core-instead-of-a-retained-toolkit-like-gtk-or-qt)
|
||||
- [Which platforms and architectures are supported?](#which-platforms-and-architectures-are-supported)
|
||||
- [What license is it under?](#what-license-is-it-under)
|
||||
|
||||
**Styling**
|
||||
|
||||
- [Why doesn't my CSS rule change a widget's size?](#why-doesnt-my-css-rule-change-a-widgets-size)
|
||||
- [Why can't I use `em` or `rem`, and how far do `var()` and `color-mix()` go?](#why-cant-i-use-em-or-rem-and-how-far-do-var-and-color-mix-go)
|
||||
- [How do I ship my own stylesheet or theme?](#how-do-i-ship-my-own-stylesheet-or-theme)
|
||||
|
||||
**Layout and widgets**
|
||||
|
||||
- [Why does a widget have no rectangle, or the declared tree not settle?](#why-does-a-widget-have-no-rectangle-or-the-declared-tree-not-settle)
|
||||
- [Can I still call Nuklear directly?](#can-i-still-call-nuklear-directly)
|
||||
- [How do I write a widget of my own?](#how-do-i-write-a-widget-of-my-own)
|
||||
|
||||
**Apps**
|
||||
|
||||
- [Where are settings stored, and when are they saved?](#where-are-settings-stored-and-when-are-they-saved)
|
||||
- [How do settings work on the web?](#how-do-settings-work-on-the-web)
|
||||
- [How do I make a splash screen, a frameless window or a tray icon?](#how-do-i-make-a-splash-screen-a-frameless-window-or-a-tray-icon)
|
||||
- [How do I open files, ask a question or post work from another thread?](#how-do-i-open-files-ask-a-question-or-post-work-from-another-thread)
|
||||
- [How do I add undo, notifications or printing?](#how-do-i-add-undo-notifications-or-printing)
|
||||
|
||||
**Build and ship**
|
||||
|
||||
- [How do I build without CMake on PATH, or for x86 or ARM64?](#how-do-i-build-without-cmake-on-path-or-for-x86-or-arm64)
|
||||
- [How do I turn off accessibility, localization or text shaping?](#how-do-i-turn-off-accessibility-localization-or-text-shaping)
|
||||
- [How do I install libreaktor and link against it?](#how-do-i-install-libreaktor-and-link-against-it)
|
||||
- [How do I build and host the WebAssembly version?](#how-do-i-build-and-host-the-webassembly-version)
|
||||
- [Why is the web page blank in a background tab?](#why-is-the-web-page-blank-in-a-background-tab)
|
||||
|
||||
**Debugging**
|
||||
|
||||
- [How do I capture a screenshot or accessibility dump for a bug report?](#how-do-i-capture-a-screenshot-or-accessibility-dump-for-a-bug-report)
|
||||
- [Why is the frame time high on a machine with no GPU?](#why-is-the-frame-time-high-on-a-machine-with-no-gpu)
|
||||
- [Why does Japanese or Arabic text draw differently from Latin?](#why-does-japanese-or-arabic-text-draw-differently-from-latin)
|
||||
- [How do I report a bug?](#how-do-i-report-a-bug)
|
||||
|
||||
---
|
||||
|
||||
## What and why
|
||||
|
||||
### What is Reaktor, and how is it different from Nuklear?
|
||||
|
||||
Reaktor is a toolkit for building desktop and web apps in C. Nuklear, which it
|
||||
is built on, gives you widgets and leaves everything else to
|
||||
you. Reaktor fills in the rest:
|
||||
|
||||
- **The whole stack, ready to use.** Nuklear only draws; the window, input,
|
||||
fonts and rendering are yours to wire up. Reaktor brings them, built on
|
||||
SDL, so there is nothing to connect yourself.
|
||||
- **A finished app, not a drawing kit.** One call opens a window and runs
|
||||
it; you describe what's on screen and Reaktor lays it out.
|
||||
- **A look you change without recompiling.** Colors, fonts, spacing and
|
||||
rounded corners come from ordinary CSS files, with light and dark themes.
|
||||
- **Everyone can use it.** Screen readers can read it, and every control
|
||||
works from the keyboard.
|
||||
- **Any language.** Translations, number and date formats, and scripts such
|
||||
as Japanese and Arabic.
|
||||
- **What real apps need.** Menus, file pickers, dialogs, notifications,
|
||||
undo, printing, saved settings, extra windows and a tray icon.
|
||||
- **One codebase everywhere.** Windows, macOS, Linux, the BSDs and the
|
||||
browser.
|
||||
|
||||
Nuklear is still there underneath when you need something it offers
|
||||
directly. See [An application](DOCUMENTATION.md#an-application).
|
||||
|
||||
### Why C99 and an immediate-mode core instead of a retained toolkit like GTK or Qt?
|
||||
|
||||
To stay small: a 2.3 MB binary, about 10 MB of RAM, no GPU, and nothing to
|
||||
install beside it. A frame is drawn only when something changes, so the app
|
||||
idles at 0% of a core. See [The frame loop](DOCUMENTATION.md#the-frame-loop)
|
||||
and [PERFORMANCE.md](PERFORMANCE.md).
|
||||
|
||||
### Which platforms and architectures are supported?
|
||||
|
||||
Windows, macOS, Linux, FreeBSD, OpenBSD, NetBSD and WebAssembly, on x86 and
|
||||
ARM, plus ARMv7 and RISC-V on Linux. Every pull request builds them all; the
|
||||
BSDs' ARM64 runs under emulation and may fail without failing the run. See
|
||||
[Platforms](DOCUMENTATION.md#platforms).
|
||||
|
||||
### What license is it under?
|
||||
|
||||
MIT. Each dependency keeps its own license, all permissive; a release ships
|
||||
them in `licenses/` with [NOTICE.md](NOTICE.md), and your app should carry
|
||||
them too.
|
||||
|
||||
---
|
||||
|
||||
## Styling
|
||||
|
||||
### Why doesn't my CSS rule change a widget's size?
|
||||
|
||||
A size set in code beats the sheet: `.box = { .h = N }` locks CSS out of that
|
||||
axis. Leave the axis unset and the rule applies. See
|
||||
[Styling](DOCUMENTATION.md#styling).
|
||||
|
||||
### Why can't I use `em` or `rem`, and how far do `var()` and `color-mix()` go?
|
||||
|
||||
You can: the engine underneath, libcss, has neither, so `cssflat.c` turns
|
||||
them into pixels before it reads the sheet. It also resolves `var()`, works
|
||||
out `color-mix(in srgb, …)` and `calc()` over pixels, and keeps the
|
||||
`prefers-color-scheme` branch for the active scheme. Operator selectors such
|
||||
as `[href^="http"]` are dropped. See [Styling](DOCUMENTATION.md#styling).
|
||||
|
||||
### How do I ship my own stylesheet or theme?
|
||||
|
||||
Pass up to four sheets in `.css`; they are read after Water.css and
|
||||
reaktor.css, and the last rule wins. `reaktor_set_css` swaps them at run time,
|
||||
and `--css` adds one on top. `.no_reaktor_css` drops reaktor.css. See
|
||||
[Services](DOCUMENTATION.md#services) and [Styling](DOCUMENTATION.md#styling).
|
||||
|
||||
---
|
||||
|
||||
## Layout and widgets
|
||||
|
||||
### Why does a widget have no rectangle, or the declared tree not settle?
|
||||
|
||||
A box is placed one frame late and found again by its name. A widget whose
|
||||
label changes every frame needs a stable `.name`, and a node declared only on
|
||||
some frames renumbers everything after it. A loose label after a row belongs
|
||||
inside a named `REAKTOR_COLUMN`. See [Layout](DOCUMENTATION.md#layout).
|
||||
|
||||
### Can I still call Nuklear directly?
|
||||
|
||||
Yes. Every Nuklear type and call has a `reaktor_` alias, and `nk_*` stays
|
||||
available. A declared tree and hand-laid `reaktor_layout_row_*` cannot share
|
||||
a panel, but a group or popup is its own panel. See
|
||||
[Beyond the specs](DOCUMENTATION.md#beyond-the-specs).
|
||||
|
||||
### How do I write a widget of my own?
|
||||
|
||||
Lay it out by hand in a group, from the pieces in `ui.h`: colors from the
|
||||
sheet, rounded fills and borders, a hot rectangle so hover redraws, and a
|
||||
`reaktor_note` so screen readers and keyboard focus see it. See
|
||||
[Beyond the specs](DOCUMENTATION.md#beyond-the-specs).
|
||||
|
||||
---
|
||||
|
||||
## Apps
|
||||
|
||||
### Where are settings stored, and when are they saved?
|
||||
|
||||
In `settings.conf`, an INI file in SDL's preference folder for the app.
|
||||
`.save_settings` picks when: never (the default), on quit, on every change,
|
||||
or `.save_ms` after a change. `reaktor_settings_save` writes now and
|
||||
`reaktor_settings_clear` empties them and deletes the file. See
|
||||
[Services](DOCUMENTATION.md#services).
|
||||
|
||||
### How do settings work on the web?
|
||||
|
||||
The same `settings.conf` lives in the browser's IndexedDB, loaded before
|
||||
`main` and synced after each write; saving on quit means saving on change
|
||||
there. Clearing site data or closing a private window loses it.
|
||||
|
||||
### How do I make a splash screen, a frameless window or a tray icon?
|
||||
|
||||
A window takes `.borderless`, `.centered` and `.skip_taskbar`; a splash
|
||||
screen is those three on a window opened beside a `.hidden` main window.
|
||||
`reaktor_tray_open` adds a tray icon with a menu. See
|
||||
[Windows](DOCUMENTATION.md#windows) and [Tray](DOCUMENTATION.md#tray).
|
||||
|
||||
### How do I open files, ask a question or post work from another thread?
|
||||
|
||||
`reaktor_file_dialog_open` for the system's open, save and folder pickers,
|
||||
`reaktor_ask` for a modal question, `reaktor_timer` for later, and
|
||||
`reaktor_post` from any thread. Every callback runs on the main thread and is
|
||||
followed by a frame. See [Services](DOCUMENTATION.md#services).
|
||||
|
||||
### How do I add undo, notifications or printing?
|
||||
|
||||
Push a step with an undo and a redo callback after each change, and Ctrl+Z
|
||||
and Ctrl+Y take it back and forth, merging typing into one step if asked.
|
||||
`reaktor_notify` shows a message outside the window. `reaktor_print` and
|
||||
`reaktor_print_pdf` lay pages out as the window does and print them or write
|
||||
a PDF. See [Services](DOCUMENTATION.md#services).
|
||||
|
||||
---
|
||||
|
||||
## Build and ship
|
||||
|
||||
### How do I build without CMake on PATH, or for x86 or ARM64?
|
||||
|
||||
`./build.ps1` on Windows finds MSVC's CMake; `./build.sh` elsewhere.
|
||||
`./build.ps1 -Arch x86` or `-Arch arm64` builds that architecture into
|
||||
`build-<arch>`; ARM64 needs Visual Studio's ARM64 tools. See
|
||||
[Platforms](DOCUMENTATION.md#platforms).
|
||||
|
||||
### How do I turn off accessibility, localization or text shaping?
|
||||
|
||||
`-DREAKTOR_A11Y=OFF`, `-DREAKTOR_LOCALE=OFF` or `-DREAKTOR_TEXT=OFF`. Each
|
||||
swaps in a stub, and pixels and `--a11y-dump` stay identical apart from what
|
||||
the module drew. CMake keeps the option until you pass `=ON`. See
|
||||
[Build options](DOCUMENTATION.md#build-options).
|
||||
|
||||
### How do I install libreaktor and link against it?
|
||||
|
||||
Take the release's archive or the `.deb` or `.rpm`, or run
|
||||
`sh tools/libreaktor-pkg.sh -i`. Then `find_package(reaktor 0.6 REQUIRED)`
|
||||
and link `reaktor::reaktor`, or use `pkg-config --cflags --libs reaktor`. To
|
||||
build it into your tree instead, `add_subdirectory` the checkout and call
|
||||
`reaktor_add_app`. See [In your own project](DOCUMENTATION.md#in-your-own-project).
|
||||
|
||||
### How do I build and host the WebAssembly version?
|
||||
|
||||
`./build-wasm.sh` (or `.ps1`) with emsdk writes the pages into `build-wasm/`;
|
||||
serve that folder over HTTP, since opening the file directly will not load.
|
||||
See [The web build](DOCUMENTATION.md#the-web-build).
|
||||
|
||||
### Why is the web page blank in a background tab?
|
||||
|
||||
The loop waits on `requestAnimationFrame`, which a hidden tab, a minimized
|
||||
window or an off-screen pane never fires. It draws once it is visible.
|
||||
|
||||
---
|
||||
|
||||
## Debugging
|
||||
|
||||
### How do I capture a screenshot or accessibility dump for a bug report?
|
||||
|
||||
```bash
|
||||
./build/showcase --tab 7 --theme dark --shot a.bmp --a11y-dump a.txt
|
||||
```
|
||||
|
||||
Any app takes `--shot` and `--a11y-dump`; the dump lists every node with its
|
||||
bounds, so two dumps diff to the pixel. Settings are not read under either.
|
||||
See [Command-line flags](DOCUMENTATION.md#command-line-flags).
|
||||
|
||||
### Why is the frame time high on a machine with no GPU?
|
||||
|
||||
Most of it is usually `SDL_RenderPresent`, copying the frame to the screen,
|
||||
not drawing it. The Diagnostics page and `bench --no-vsync` split build,
|
||||
render and present. See [The renderer](DOCUMENTATION.md#the-renderer).
|
||||
|
||||
### Why does Japanese or Arabic text draw differently from Latin?
|
||||
|
||||
A string with a character the font atlas lacks is drawn by the Text module,
|
||||
which orders, shapes and takes glyphs from fallback fonts; the rest is
|
||||
Nuklear's. Arabic, Hebrew or an Indic script needs a font that has it, passed
|
||||
with `--font-fallback` or `.font_fallbacks`. See [Text](DOCUMENTATION.md#text).
|
||||
|
||||
### How do I report a bug?
|
||||
|
||||
Open an issue at [github.com/Alpaq92/Reaktor/issues](https://github.com/Alpaq92/Reaktor/issues)
|
||||
with the Reaktor version (`reaktor_version()`), the system and architecture,
|
||||
the steps that show it, and what you expected. For anything drawn wrong,
|
||||
attach a `--shot` and an `--a11y-dump` of it; for a crash, what the
|
||||
`--console debug` log printed.
|
||||
@@ -12,14 +12,15 @@ from the project's own license file at the pinned revision.
|
||||
| [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 |
|
||||
| [simple.css](https://github.com/kevquirk/simple.css) | The sheet the Styling page swaps in | MIT |
|
||||
| [Water.css](https://github.com/kognise/water.css) | The stylesheet the look comes from, compiled in | MIT |
|
||||
| [Bamboo](https://github.com/rilwis/bamboo) | The sheet the Styling page swaps in | MIT |
|
||||
| [Ionicons](https://github.com/ionic-team/ionicons) | Every icon, as SVG; the seven the widgets draw are compiled in | MIT |
|
||||
| [plutosvg](https://github.com/sammycage/plutosvg) | Rasterizing the SVGs | MIT |
|
||||
| [plutovg](https://github.com/sammycage/plutovg) | plutosvg's canvas (nested submodule) | MIT |
|
||||
| [mojibake](https://github.com/zaerl/mojibake) | Bidirectional text (UAX #9) and line breaking (UAX #14), for the Text module | MIT |
|
||||
| [kb_text_shape](https://github.com/JimmyLefevre/kb) | OpenType shaping, script segmentation and font coverage, for the Text module | zlib |
|
||||
| [ini.h](https://github.com/mattiasgustavsson/libs) | Reading and writing `settings.conf` | MIT or public domain |
|
||||
| [libHaru](https://github.com/libharu/libharu) | Writing PDFs, for the print module | zlib/libpng |
|
||||
|
||||
Only LCUI's `libcss` and `yutil` are built, not the toolkit. SDL is built
|
||||
static, without audio, joystick, haptic, HID, sensor, camera, power, GPU,
|
||||
@@ -125,19 +126,20 @@ each toolchain fetches its own framework, and none is part of a Reaktor build.
|
||||
|
||||
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,
|
||||
NukAnim, Onlay and ini.h, so it carries the zlib and MIT terms above. Each license
|
||||
NukAnim, Onlay and ini.h, and libHaru with the print module, so it carries the
|
||||
zlib and MIT terms above. Each license
|
||||
is copied unchanged into `licenses/` beside the programs (ini.h's sits at the
|
||||
end of the header, so the header itself is `licenses/ini.h.txt`): 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`
|
||||
(MIT); the seven Ionicons `chevron-down-outline`, `chevron-back-outline`,
|
||||
byte: Water.css's `variables-light.css`, `variables-dark.css` and the nine
|
||||
files in `src/parts/` (MIT); the seven Ionicons `chevron-down-outline`, `chevron-back-outline`,
|
||||
`chevron-forward-outline`, `ellipse`, `ellipse-outline`, `radio-button-off`
|
||||
and `close-outline` (MIT); Aileron Regular and Bold (CC0); and the mark and
|
||||
`assets/css/reaktor.css` (MIT). Their licenses are in `licenses/` too.
|
||||
|
||||
The rest of Ionicons, simple.css, the Japanese font and the catalogs are not
|
||||
The rest of Ionicons, Bamboo, the Japanese font and the catalogs are not
|
||||
embedded (the catalogs are with `-DREAKTOR_LOCALE_EMBED=ON`); a build that uses
|
||||
them ships them beside the binary, under the `.reaktor-root` marker. The
|
||||
WebAssembly build packs the ones it uses into its `.data` bundle.
|
||||
|
||||
@@ -183,7 +183,7 @@ fix). With a real GPU that reverses — see **Against the others**.
|
||||
## What it needs to run
|
||||
|
||||
**No GPU**, and about **10 MB of RAM**. The default look is compiled in, so a
|
||||
program needs no files beside it until it uses other Ionicons, simple.css, the
|
||||
program needs no files beside it until it uses other Ionicons, Bamboo, the
|
||||
catalogs or the Japanese font, found by walking up to the `.reaktor-root`
|
||||
marker. The web build packs those into its `.data` and needs an HTTP server,
|
||||
since a `file://` page cannot fetch the `.wasm`.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(consumer C)
|
||||
|
||||
find_package(reaktor 0.5 REQUIRED)
|
||||
find_package(reaktor 0.6 REQUIRED)
|
||||
|
||||
add_executable(simple WIN32 ../../samples/simple/simple.c)
|
||||
target_link_libraries(simple PRIVATE reaktor::reaktor)
|
||||
|
||||
@@ -63,10 +63,19 @@ typedef struct reaktor_window_spec {
|
||||
const SDL_Point *pt, void *data);
|
||||
} reaktor_window_spec;
|
||||
|
||||
typedef struct reaktor_inspector_spec {
|
||||
int attach;
|
||||
unsigned mods;
|
||||
SDL_Keycode key;
|
||||
int open;
|
||||
} reaktor_inspector_spec;
|
||||
|
||||
typedef struct reaktor_launch {
|
||||
const char *name, *id, *version;
|
||||
reaktor_window_spec window;
|
||||
reaktor_console console;
|
||||
const char *log;
|
||||
reaktor_inspector_spec inspector;
|
||||
reaktor_theme theme;
|
||||
const char *confirm_close;
|
||||
|
||||
@@ -155,6 +164,10 @@ int reaktor_tray_open(App *app, const reaktor_tray *tray);
|
||||
void reaktor_tray_check(App *app, int item, int checked);
|
||||
void reaktor_tray_close(App *app);
|
||||
|
||||
int reaktor_inspector_open(App *app);
|
||||
void reaktor_inspector_close(App *app);
|
||||
int reaktor_inspector_shown(App *app);
|
||||
|
||||
#ifndef REAKTOR_NO_SHORT_NAMES
|
||||
static SDL_INLINE int
|
||||
launchApp(int argc, char **argv, const reaktor_launch *launch)
|
||||
|
||||
@@ -29,5 +29,7 @@ enum {
|
||||
struct tm;
|
||||
const char *reaktor_format_date(char *buf, size_t cap, const struct tm *t,
|
||||
int style);
|
||||
const char *reaktor_format_pattern(char *buf, size_t cap, const struct tm *t,
|
||||
const char *pattern);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -180,6 +180,46 @@ void reaktor_setting_set(const char *key, const char *value);
|
||||
void reaktor_settings_save(void);
|
||||
void reaktor_settings_clear(void);
|
||||
|
||||
typedef struct reaktor_notification {
|
||||
const char *title;
|
||||
const char *text;
|
||||
} reaktor_notification;
|
||||
|
||||
int reaktor_notify(App *app, const reaktor_notification *n);
|
||||
|
||||
typedef struct reaktor_print_spec {
|
||||
const char *title;
|
||||
int pages;
|
||||
float w, h;
|
||||
int dpi;
|
||||
void (*page)(App *app, struct reaktor_context *ctx, int index, int w, int h,
|
||||
void *user);
|
||||
void (*done)(App *app, int ok, void *user);
|
||||
void *user;
|
||||
} reaktor_print_spec;
|
||||
|
||||
int reaktor_print(App *app, const reaktor_print_spec *s);
|
||||
int reaktor_print_pdf(App *app, const char *path, const reaktor_print_spec *s);
|
||||
|
||||
typedef struct reaktor_undo_step {
|
||||
const char *label;
|
||||
void (*undo)(void *data);
|
||||
void (*redo)(void *data);
|
||||
void (*free)(void *data);
|
||||
void *data;
|
||||
unsigned merge;
|
||||
} reaktor_undo_step;
|
||||
|
||||
void reaktor_undo_push(App *app, const reaktor_undo_step *s);
|
||||
int reaktor_undo(App *app);
|
||||
int reaktor_redo(App *app);
|
||||
const char *reaktor_undo_label(App *app);
|
||||
const char *reaktor_redo_label(App *app);
|
||||
void reaktor_undo_group(App *app, int begin);
|
||||
void reaktor_undo_saved(App *app);
|
||||
int reaktor_undo_dirty(App *app);
|
||||
void reaktor_undo_clear(App *app);
|
||||
|
||||
typedef struct reaktor_diag {
|
||||
const char *renderer;
|
||||
const char *mode;
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
|
||||
#include "reaktor/nuklear.h"
|
||||
|
||||
#ifndef REAKTOR_APP_FWD
|
||||
#define REAKTOR_APP_FWD
|
||||
typedef struct App App;
|
||||
#endif
|
||||
|
||||
enum {
|
||||
REAKTOR_LAY_ROW = 0,
|
||||
REAKTOR_LAY_COLUMN,
|
||||
@@ -74,6 +79,7 @@ typedef struct reaktor_button_spec {
|
||||
unsigned char disabled;
|
||||
unsigned char repeat;
|
||||
unsigned char fit_content;
|
||||
unsigned char flat;
|
||||
} reaktor_button_spec;
|
||||
|
||||
int reaktor_button(const reaktor_button_spec *s);
|
||||
@@ -124,9 +130,13 @@ typedef struct reaktor_field_spec {
|
||||
reaktor_plugin_filter filter;
|
||||
reaktor_box box;
|
||||
unsigned char multiline;
|
||||
unsigned char line_numbers;
|
||||
char **heap;
|
||||
int *heap_cap;
|
||||
} reaktor_field_spec;
|
||||
|
||||
void reaktor_field(const reaktor_field_spec *s);
|
||||
void reaktor_field_select(App *app, const char *buf, int from, int to);
|
||||
|
||||
typedef struct reaktor_check_spec {
|
||||
const char *label;
|
||||
@@ -212,6 +222,37 @@ typedef struct reaktor_property_spec {
|
||||
|
||||
void reaktor_property(const reaktor_property_spec *s);
|
||||
|
||||
typedef struct reaktor_spinner_spec {
|
||||
const char *label;
|
||||
const char *name;
|
||||
const char *const *items;
|
||||
int count;
|
||||
int *chosen;
|
||||
unsigned char wrap;
|
||||
const char *style;
|
||||
reaktor_box box;
|
||||
} reaktor_spinner_spec;
|
||||
|
||||
int reaktor_spinner(const reaktor_spinner_spec *s);
|
||||
|
||||
typedef struct reaktor_date_spec {
|
||||
const char *name;
|
||||
int *year, *month, *day;
|
||||
int min_year, max_year;
|
||||
reaktor_box box;
|
||||
} reaktor_date_spec;
|
||||
|
||||
int reaktor_date_pick(const reaktor_date_spec *s);
|
||||
|
||||
typedef struct reaktor_time_spec {
|
||||
const char *name;
|
||||
int *hour, *minute;
|
||||
unsigned char clock12;
|
||||
reaktor_box box;
|
||||
} reaktor_time_spec;
|
||||
|
||||
int reaktor_time_pick(const reaktor_time_spec *s);
|
||||
|
||||
typedef struct reaktor_combo_spec {
|
||||
const char *label;
|
||||
const char *name;
|
||||
@@ -267,10 +308,58 @@ typedef struct reaktor_list_spec {
|
||||
int *selected;
|
||||
float row_h;
|
||||
reaktor_box box;
|
||||
const char *drag;
|
||||
void (*dropped)(const char *from, int item, int at, void *user);
|
||||
} reaktor_list_spec;
|
||||
|
||||
int reaktor_list(const reaktor_list_spec *s);
|
||||
|
||||
typedef struct reaktor_tree_spec {
|
||||
const char *name;
|
||||
int count;
|
||||
int (*parent)(int node, void *user);
|
||||
const char *(*label)(int node, void *user);
|
||||
const char *(*icon)(int node, void *user);
|
||||
void *user;
|
||||
unsigned char *open;
|
||||
int *selected;
|
||||
float row_h;
|
||||
reaktor_box box;
|
||||
} reaktor_tree_spec;
|
||||
|
||||
int reaktor_tree(const reaktor_tree_spec *s);
|
||||
|
||||
typedef struct reaktor_menu_entry {
|
||||
const char *label;
|
||||
const char *icon;
|
||||
const char *keys;
|
||||
reaktor_handler on_press;
|
||||
reaktor_bool *checked;
|
||||
unsigned char disabled;
|
||||
const struct reaktor_menu_entry *items;
|
||||
int count;
|
||||
void (*custom)(App *app, struct reaktor_context *ctx, void *user);
|
||||
float height, width;
|
||||
} reaktor_menu_entry;
|
||||
|
||||
typedef struct reaktor_menu {
|
||||
const char *label;
|
||||
const reaktor_menu_entry *items;
|
||||
int count;
|
||||
} reaktor_menu;
|
||||
|
||||
typedef struct reaktor_menubar_spec {
|
||||
const reaktor_menu *menus;
|
||||
int count;
|
||||
const char *name;
|
||||
reaktor_box box;
|
||||
int *picked_menu;
|
||||
int *picked_item;
|
||||
const reaktor_menu_entry **picked;
|
||||
} reaktor_menubar_spec;
|
||||
|
||||
int reaktor_menubar(const reaktor_menubar_spec *s);
|
||||
|
||||
typedef struct reaktor_splitter_spec {
|
||||
float *value;
|
||||
float lo, hi;
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
#include "internal.h"
|
||||
|
||||
#if defined(__EMSCRIPTEN__)
|
||||
#include <emscripten.h>
|
||||
|
||||
EM_JS(void, notify_web, (const char *title, const char *text), {
|
||||
var t = UTF8ToString(title), b = UTF8ToString(text);
|
||||
if (!('Notification' in window) || Notification.permission === 'denied') return;
|
||||
if (Notification.permission === 'granted') { new Notification(t, { body: b }); return; }
|
||||
Notification.requestPermission().then(function (p) {
|
||||
if (p === 'granted') new Notification(t, { body: b });
|
||||
});
|
||||
});
|
||||
|
||||
int
|
||||
reaktor_notify(App *app, const reaktor_notification *n)
|
||||
{
|
||||
(void)app;
|
||||
if (!n || !n->title) return 0;
|
||||
notify_web(n->title, n->text ? n->text : "");
|
||||
return 1;
|
||||
}
|
||||
|
||||
#elif defined(_WIN32)
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <shellapi.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define NOTIFY_ID 0x5245u
|
||||
|
||||
static NOTIFYICONDATAW g_icon;
|
||||
|
||||
static void
|
||||
notify_remove(void)
|
||||
{
|
||||
if (g_icon.hWnd) Shell_NotifyIconW(NIM_DELETE, &g_icon);
|
||||
g_icon.hWnd = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
notify_gone(App *app, void *user)
|
||||
{
|
||||
(void)app; (void)user;
|
||||
notify_remove();
|
||||
}
|
||||
|
||||
/* As much of s as fits, cut short rather than lost. */
|
||||
static void
|
||||
notify_text(const char *s, WCHAR *out, int cap)
|
||||
{
|
||||
int n = MultiByteToWideChar(CP_UTF8, 0, s, -1, NULL, 0);
|
||||
WCHAR *w = n > 0 ? (WCHAR *)SDL_malloc((size_t)n * sizeof *w) : NULL;
|
||||
|
||||
out[0] = 0;
|
||||
if (w && MultiByteToWideChar(CP_UTF8, 0, s, -1, w, n) > 0) SDL_wcslcpy(out, w, (size_t)cap);
|
||||
SDL_free(w);
|
||||
}
|
||||
|
||||
/* A balloon from an icon of our own, which Windows 10 and 11 show as a toast. */
|
||||
int
|
||||
reaktor_notify(App *app, const reaktor_notification *n)
|
||||
{
|
||||
static unsigned gone;
|
||||
static int watched;
|
||||
HWND hwnd;
|
||||
int added;
|
||||
|
||||
if (!app || !n || !n->title) return 0;
|
||||
hwnd = (HWND)SDL_GetPointerProperty(SDL_GetWindowProperties(app->win),
|
||||
SDL_PROP_WINDOW_WIN32_HWND_POINTER, NULL);
|
||||
if (!hwnd) return 0;
|
||||
added = g_icon.hWnd != NULL;
|
||||
SDL_zero(g_icon);
|
||||
g_icon.cbSize = sizeof g_icon;
|
||||
g_icon.hWnd = hwnd;
|
||||
g_icon.uID = NOTIFY_ID;
|
||||
g_icon.uFlags = NIF_ICON | NIF_TIP | NIF_INFO;
|
||||
g_icon.hIcon = (HICON)SendMessageW(hwnd, WM_GETICON, ICON_SMALL, 0);
|
||||
if (!g_icon.hIcon) g_icon.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
|
||||
notify_text(n->title, g_icon.szInfoTitle, (int)SDL_arraysize(g_icon.szInfoTitle));
|
||||
notify_text(n->title, g_icon.szTip, (int)SDL_arraysize(g_icon.szTip));
|
||||
notify_text(n->text ? n->text : "", g_icon.szInfo, (int)SDL_arraysize(g_icon.szInfo));
|
||||
g_icon.dwInfoFlags = NIIF_USER | NIIF_RESPECT_QUIET_TIME;
|
||||
if (!Shell_NotifyIconW(added ? NIM_MODIFY : NIM_ADD, &g_icon)) {
|
||||
g_icon.hWnd = NULL;
|
||||
return 0;
|
||||
}
|
||||
/* A timer dies with the window; a quit before it fires would leave the icon. */
|
||||
if (!watched) watched = atexit(notify_remove) == 0;
|
||||
if (gone) reaktor_timer_stop(gone);
|
||||
gone = reaktor_timer(app, 10000, 0, notify_gone, NULL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#elif defined(REAKTOR_HAVE_DBUS)
|
||||
#include <dbus/dbus.h>
|
||||
|
||||
int
|
||||
reaktor_notify(App *app, const reaktor_notification *n)
|
||||
{
|
||||
DBusConnection *c;
|
||||
DBusMessage *m;
|
||||
DBusMessageIter it, sub;
|
||||
const char *name = reaktor_app_ident(), *icon = "", *body;
|
||||
dbus_uint32_t replaces = 0;
|
||||
dbus_int32_t expire = -1;
|
||||
int ok;
|
||||
|
||||
(void)app;
|
||||
if (!n || !n->title || !(c = dbus_bus_get(DBUS_BUS_SESSION, NULL))) return 0;
|
||||
m = dbus_message_new_method_call("org.freedesktop.Notifications",
|
||||
"/org/freedesktop/Notifications",
|
||||
"org.freedesktop.Notifications", "Notify");
|
||||
if (!m) return 0;
|
||||
body = n->text ? n->text : "";
|
||||
dbus_message_iter_init_append(m, &it);
|
||||
dbus_message_iter_append_basic(&it, DBUS_TYPE_STRING, &name);
|
||||
dbus_message_iter_append_basic(&it, DBUS_TYPE_UINT32, &replaces);
|
||||
dbus_message_iter_append_basic(&it, DBUS_TYPE_STRING, &icon);
|
||||
dbus_message_iter_append_basic(&it, DBUS_TYPE_STRING, &n->title);
|
||||
dbus_message_iter_append_basic(&it, DBUS_TYPE_STRING, &body);
|
||||
dbus_message_iter_open_container(&it, DBUS_TYPE_ARRAY, "s", &sub);
|
||||
dbus_message_iter_close_container(&it, &sub);
|
||||
dbus_message_iter_open_container(&it, DBUS_TYPE_ARRAY, "{sv}", &sub);
|
||||
dbus_message_iter_close_container(&it, &sub);
|
||||
dbus_message_iter_append_basic(&it, DBUS_TYPE_INT32, &expire);
|
||||
ok = dbus_connection_send(c, m, NULL);
|
||||
dbus_connection_flush(c);
|
||||
dbus_message_unref(m);
|
||||
dbus_connection_unref(c);
|
||||
return ok ? 1 : 0;
|
||||
}
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
int reaktor_notify_macos(const char *title, const char *text);
|
||||
|
||||
int
|
||||
reaktor_notify(App *app, const reaktor_notification *n)
|
||||
{
|
||||
(void)app;
|
||||
return n && n->title ? reaktor_notify_macos(n->title, n->text ? n->text : "") : 0;
|
||||
}
|
||||
|
||||
#else
|
||||
int
|
||||
reaktor_notify(App *app, const reaktor_notification *n)
|
||||
{
|
||||
(void)app; (void)n;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,26 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UserNotifications/UserNotifications.h>
|
||||
|
||||
/* Only a bundled app has a notification center; a bare program answers 0. */
|
||||
int
|
||||
reaktor_notify_macos(const char *title, const char *text)
|
||||
{
|
||||
UNUserNotificationCenter *center;
|
||||
UNMutableNotificationContent *content;
|
||||
UNNotificationRequest *request;
|
||||
|
||||
if (![[NSBundle mainBundle] bundleIdentifier]) return 0;
|
||||
center = [UNUserNotificationCenter currentNotificationCenter];
|
||||
content = [[UNMutableNotificationContent alloc] init];
|
||||
content.title = [NSString stringWithUTF8String:title];
|
||||
content.body = [NSString stringWithUTF8String:text];
|
||||
request = [UNNotificationRequest requestWithIdentifier:[[NSUUID UUID] UUIDString]
|
||||
content:content
|
||||
trigger:nil];
|
||||
[center requestAuthorizationWithOptions:UNAuthorizationOptionAlert | UNAuthorizationOptionSound
|
||||
completionHandler:^(BOOL granted, NSError *error) {
|
||||
(void)error;
|
||||
if (granted) [center addNotificationRequest:request withCompletionHandler:nil];
|
||||
}];
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#include "internal.h"
|
||||
|
||||
int
|
||||
reaktor_notify(App *app, const reaktor_notification *n)
|
||||
{
|
||||
(void)app; (void)n;
|
||||
return 0;
|
||||
}
|
||||
@@ -38,6 +38,10 @@ static int g_css_n, g_cli_css_n, g_css_pending;
|
||||
static const char *g_fallbacks[REAKTOR_LAYER_MAX];
|
||||
static int g_fallback_n;
|
||||
static const char *g_icon_dirs[REAKTOR_LAYER_MAX], *g_cli_icons[REAKTOR_LAYER_MAX];
|
||||
static int g_inspect_flag;
|
||||
static SDL_IOStream *g_log;
|
||||
static SDL_LogOutputFunction g_log_next;
|
||||
static void *g_log_next_user;
|
||||
static int g_icon_dir_n, g_cli_icon_n;
|
||||
|
||||
static const char *
|
||||
@@ -194,6 +198,54 @@ own_here(const char *path)
|
||||
return owned;
|
||||
}
|
||||
|
||||
static void SDLCALL
|
||||
log_line(void *user, int category, SDL_LogPriority priority, const char *message)
|
||||
{
|
||||
static const char *const level[] = { "", "TRACE", "VERBOSE", "DEBUG", "INFO",
|
||||
"WARN", "ERROR", "CRITICAL" };
|
||||
static const char *const area[] = { "app", "error", "assert", "system", "audio",
|
||||
"video", "render", "input", "test", "gpu" };
|
||||
SDL_Time now = 0;
|
||||
SDL_DateTime t;
|
||||
char cat[16];
|
||||
|
||||
SDL_zero(t);
|
||||
if (SDL_GetCurrentTime(&now)) SDL_TimeToDateTime(now, &t, true);
|
||||
if (category >= 0 && category < (int)SDL_arraysize(area))
|
||||
SDL_strlcpy(cat, area[category], sizeof cat);
|
||||
else
|
||||
SDL_snprintf(cat, sizeof cat, "%d", category);
|
||||
SDL_IOprintf(g_log, "%04d-%02d-%02d %02d:%02d:%02d.%03d %-8s %-6s %s\n",
|
||||
t.year, t.month, t.day, t.hour, t.minute, t.second,
|
||||
t.nanosecond / 1000000,
|
||||
(unsigned)priority < SDL_arraysize(level) ? level[priority] : "?",
|
||||
cat, message);
|
||||
SDL_FlushIO(g_log);
|
||||
if (g_log_next) g_log_next(g_log_next_user, category, priority, message);
|
||||
}
|
||||
|
||||
static void
|
||||
log_open(const char *path)
|
||||
{
|
||||
if (g_log) return;
|
||||
g_log = SDL_IOFromFile(path, "ab");
|
||||
if (!g_log) {
|
||||
SDL_Log("--log: %s", SDL_GetError());
|
||||
return;
|
||||
}
|
||||
SDL_GetLogOutputFunction(&g_log_next, &g_log_next_user);
|
||||
SDL_SetLogOutputFunction(log_line, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
log_close(void)
|
||||
{
|
||||
if (!g_log) return;
|
||||
SDL_SetLogOutputFunction(g_log_next, g_log_next_user);
|
||||
SDL_CloseIO(g_log);
|
||||
g_log = NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
take_flags(App *app, int argc, char **argv)
|
||||
{
|
||||
@@ -225,8 +277,15 @@ take_flags(App *app, int argc, char **argv)
|
||||
else if (v && SDL_strcmp(a, "--font") == 0) { g_cli_font = own_here(v); i++; }
|
||||
else if (v && SDL_strcmp(a, "--font-bold") == 0) { g_cli_font_bold = own_here(v); i++; }
|
||||
else if (v && SDL_strcmp(a, "--a11y-dump") == 0) { app->dump_path = v; i++; }
|
||||
else if (v && SDL_strcmp(a, "--log") == 0) { log_open(v); i++; }
|
||||
else if (SDL_strcmp(a, "--inspect") == 0) g_inspect_flag = 1;
|
||||
else if (SDL_strcmp(a, "--no-inspector") == 0) g_inspect_flag = -1;
|
||||
else if (v && SDL_strcmp(a, "--renderer") == 0) { app->renderer_pref = v; i++; }
|
||||
else if (v && SDL_strcmp(a, "--video") == 0) { app->video_pref = v; i++; }
|
||||
else if (v && SDL_strcmp(a, "--popups") == 0) {
|
||||
app->popups_inline = SDL_strcmp(v, "inline") == 0;
|
||||
i++;
|
||||
}
|
||||
else if (v && SDL_strcmp(a, "--lang") == 0) { app->lang_pref = v; i++; }
|
||||
else if (v && SDL_strcmp(a, "--font-fallback") == 0) { add_fallback(v); i++; }
|
||||
else if (v && SDL_strcmp(a, "--theme") == 0) {
|
||||
@@ -277,8 +336,8 @@ role_sheet(const App *app)
|
||||
static const char *
|
||||
theme_sheet(int dark)
|
||||
{
|
||||
return dark ? "external/tinycss/src/variables-dark.css"
|
||||
: "external/tinycss/src/variables-light.css";
|
||||
return dark ? "external/watercss/src/variables-dark.css"
|
||||
: "external/watercss/src/variables-light.css";
|
||||
}
|
||||
|
||||
void
|
||||
@@ -297,7 +356,9 @@ load_theme(App *app)
|
||||
base = n;
|
||||
for (i = 0; i < g_css_n && n < SHEET_MAX; i++) sheets[n++] = g_css[i];
|
||||
for (i = 0; i < g_cli_css_n && n < SHEET_MAX; i++) sheets[n++] = g_cli_css[i];
|
||||
if (reaktor_inspector_sheet() && n < SHEET_MAX) sheets[n++] = reaktor_inspector_sheet();
|
||||
app->sheets = n;
|
||||
app->why |= REAKTOR_WHY_STYLE;
|
||||
|
||||
t0 = SDL_GetPerformanceCounter();
|
||||
if (!reaktor_style_init(sheets, n, app->dark ? "dark" : "light"))
|
||||
@@ -597,7 +658,9 @@ app_init(void **appstate, int argc, char *argv[])
|
||||
|
||||
app->queue.moved_ok = 1;
|
||||
app->theme_mode = (int)g_launch.theme;
|
||||
reaktor_inspector_early();
|
||||
argc = take_flags(app, argc, argv);
|
||||
if (g_launch.log) log_open(g_launch.log);
|
||||
reaktor_process_start((int)g_launch.console, launch_title());
|
||||
|
||||
if (g_launch.name || g_launch.version || g_launch.id)
|
||||
@@ -762,6 +825,7 @@ app_init(void **appstate, int argc, char *argv[])
|
||||
nk_input_begin(app->ctx);
|
||||
g_started = 1;
|
||||
SDL_SetAtomicInt(&g_running, 1);
|
||||
reaktor_inspector_start(app, &g_launch.inspector, g_inspect_flag);
|
||||
return SDL_APP_CONTINUE;
|
||||
}
|
||||
|
||||
@@ -772,6 +836,7 @@ reaktor_take_event(App *app, SDL_Event *event)
|
||||
if (reaktor_input_page_key(app, event)) return;
|
||||
#endif
|
||||
if (app->secondary) reaktor_windows_take(app, event);
|
||||
else if (reaktor_inspector_event(app, event)) return;
|
||||
|
||||
switch (event->type) {
|
||||
case SDL_EVENT_MOUSE_BUTTON_DOWN:
|
||||
@@ -792,6 +857,7 @@ reaktor_take_event(App *app, SDL_Event *event)
|
||||
case SDL_EVENT_LOCALE_CHANGED:
|
||||
case SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED:
|
||||
app->dirty = 1;
|
||||
app->why |= REAKTOR_WHY_INPUT;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -1039,8 +1105,14 @@ 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 (w != app->laid_w || h != app->laid_h) {
|
||||
app->dirty = 1;
|
||||
app->why |= REAKTOR_WHY_RESIZE;
|
||||
}
|
||||
if (app->fling_v != 0.0f) {
|
||||
app->dirty = 1;
|
||||
app->why |= REAKTOR_WHY_MOTION;
|
||||
}
|
||||
|
||||
if (app->hover_pending &&
|
||||
SDL_GetTicks() - app->last_draw_ms >= g_hover_gap_ms) {
|
||||
@@ -1148,6 +1220,7 @@ reaktor_app_frame(App *app, int win_w, int win_h, const char *title,
|
||||
app->laid_h = win_h;
|
||||
app->hot_n = 0;
|
||||
app->editing = 0;
|
||||
app->surface_at = nk_rect(0, 0, 0, 0);
|
||||
if (app->last_frame_ms) app->frame_gap_ms = (float)(now - app->last_frame_ms);
|
||||
app->last_frame_ms = now;
|
||||
|
||||
@@ -1166,6 +1239,7 @@ reaktor_app_frame(App *app, int win_w, int win_h, const char *title,
|
||||
file_answer(app);
|
||||
|
||||
app->focus_seen = 0;
|
||||
app->popup_open = 0;
|
||||
app->popup_lo = app->popup_hi = app->trap_lo = app->trap_hi = -1;
|
||||
if (!app->anim) app->anim = reaktor_anim_create();
|
||||
if (app->anim) reaktor_anim_frame(app->anim, app->frame_gap_ms);
|
||||
@@ -1197,11 +1271,13 @@ reaktor_app_frame(App *app, int win_w, int win_h, const char *title,
|
||||
(reaktor_popup_open(pw) && pw->popup.type == NK_PANEL_POPUP));
|
||||
}
|
||||
app->focus_step = 0;
|
||||
if (!ctx->input.mouse.buttons[NK_BUTTON_LEFT].down) app->drag.armed = app->drag.active = 0;
|
||||
{
|
||||
int ring = app->focus_visible && app->focus_seen &&
|
||||
app->focus_layer == FOCUS_POPUP;
|
||||
|
||||
if (ring || app->tip) reaktor_overlay(app, ctx, ring);
|
||||
if (ring || app->tip || (is_main && reaktor_inspector_marks(app)))
|
||||
reaktor_overlay(app, ctx, ring);
|
||||
}
|
||||
app->stop_editing = 0;
|
||||
|
||||
@@ -1226,6 +1302,7 @@ reaktor_app_frame(App *app, int win_w, int win_h, const char *title,
|
||||
if (is_main) {
|
||||
reaktor_a11y_platform_push(&app->a11y, app->focus_id);
|
||||
a11y_dump_once(app);
|
||||
reaktor_inspector_frame(app);
|
||||
} else {
|
||||
reaktor_a11y_platform_window_push(app->win, &app->a11y, app->focus_id,
|
||||
reader_activate, reader_focus, app);
|
||||
@@ -1253,6 +1330,10 @@ reaktor_app_frame(App *app, int win_w, int win_h, const char *title,
|
||||
reaktor_render(app);
|
||||
t_present0 = SDL_GetPerformanceCounter();
|
||||
if (is_main) shot = take_shot(app);
|
||||
if (app->want_capture) {
|
||||
app->capture = SDL_RenderReadPixels(app->ren, NULL);
|
||||
app->want_capture = 0;
|
||||
}
|
||||
SDL_RenderPresent(app->ren);
|
||||
t_end = SDL_GetPerformanceCounter();
|
||||
|
||||
@@ -1342,11 +1423,13 @@ app_quit(void *appstate, SDL_AppResult result)
|
||||
reaktor_process_end();
|
||||
return;
|
||||
}
|
||||
reaktor_inspector_stop(app);
|
||||
run_stop(app);
|
||||
if (remembers(app)) reaktor_window_remember(app);
|
||||
reaktor_timers_drop(NULL);
|
||||
if (g_launch.save_settings != REAKTOR_SAVE_NEVER) reaktor_settings_save();
|
||||
reaktor_settings_free();
|
||||
reaktor_undo_clear(app);
|
||||
if (!SDL_GetAtomicInt(&g_exit_code) && (app->shot_failed || app->dump_failed))
|
||||
SDL_SetAtomicInt(&g_exit_code, app->shot_failed && app->dump_failed ? 4
|
||||
: app->shot_failed ? 2 : 3);
|
||||
@@ -1379,6 +1462,7 @@ app_quit(void *appstate, SDL_AppResult result)
|
||||
g_app = NULL;
|
||||
reaktor_signal_unwatch();
|
||||
reaktor_process_end();
|
||||
log_close();
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -1391,6 +1475,7 @@ launch_copy(const reaktor_launch *l)
|
||||
g_launch.name = own(l->name);
|
||||
g_launch.id = own(l->id);
|
||||
g_launch.version = own(l->version);
|
||||
g_launch.log = own(l->log);
|
||||
g_launch.window.title = own(l->window.title);
|
||||
g_confirm = l->confirm_close ? SDL_strdup(l->confirm_close) : NULL;
|
||||
g_icon_name = reaktor_asset_name(&l->window.icon, "app/icon.svg");
|
||||
@@ -1518,6 +1603,14 @@ reaktor_set_css(App *app, const reaktor_asset *css, int count)
|
||||
reaktor_wake(app);
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_restyle(void)
|
||||
{
|
||||
if (!g_app) return;
|
||||
g_app->theme_pending = g_app->theme_mode + 1;
|
||||
reaktor_wake(g_app);
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_set_title(App *app, const char *title)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,655 @@
|
||||
#include "internal.h"
|
||||
#include "layout.h"
|
||||
#include "reaktor/launch.h"
|
||||
#include "reaktor/keys.h"
|
||||
|
||||
#define LOG_MAX 1000
|
||||
#define LOG_TEXT 240
|
||||
#define ROWS 40
|
||||
#define CSS_CAP 4096
|
||||
|
||||
enum { TAB_TREE, TAB_BOX, TAB_STYLE, TAB_FRAME, TAB_LOGS, TABS };
|
||||
|
||||
typedef struct log_entry {
|
||||
Uint64 ms;
|
||||
int category;
|
||||
SDL_LogPriority priority;
|
||||
char text[LOG_TEXT];
|
||||
} log_entry;
|
||||
|
||||
static App *g_main;
|
||||
static reaktor_inspector_spec g_spec;
|
||||
static int g_attached, g_win, g_floater, g_tab, g_picking;
|
||||
static unsigned g_sel;
|
||||
|
||||
static reaktor_a11y_node g_node[REAKTOR_A11Y_MAX_NODES];
|
||||
static int g_parent[REAKTOR_A11Y_MAX_NODES];
|
||||
static char g_label[REAKTOR_A11Y_MAX_NODES][96];
|
||||
static unsigned char g_open[REAKTOR_A11Y_MAX_NODES];
|
||||
static int g_n, g_sel_ix = -1;
|
||||
|
||||
static char g_kv[ROWS][2][160];
|
||||
static int g_rows;
|
||||
|
||||
static unsigned g_frames, g_why;
|
||||
|
||||
static char g_css[CSS_CAP], g_css_applied[CSS_CAP];
|
||||
static int g_css_len, g_css_on;
|
||||
|
||||
static SDL_Mutex *g_log_lock;
|
||||
static log_entry g_log[LOG_MAX];
|
||||
static int g_log_head, g_log_n, g_log_min;
|
||||
static int g_log_row[LOG_MAX], g_log_rows;
|
||||
static SDL_LogOutputFunction g_log_next;
|
||||
static void *g_log_next_user;
|
||||
|
||||
static int shown(void);
|
||||
static void redraw_window_only(void);
|
||||
|
||||
static void SDLCALL
|
||||
log_take(void *user, int category, SDL_LogPriority priority, const char *message)
|
||||
{
|
||||
(void)user;
|
||||
if (g_log_lock) {
|
||||
log_entry *e;
|
||||
|
||||
SDL_LockMutex(g_log_lock);
|
||||
e = &g_log[(g_log_head + g_log_n) % LOG_MAX];
|
||||
if (g_log_n < LOG_MAX) g_log_n++;
|
||||
else g_log_head = (g_log_head + 1) % LOG_MAX;
|
||||
e->ms = SDL_GetTicks();
|
||||
e->category = category;
|
||||
e->priority = priority;
|
||||
SDL_strlcpy(e->text, message, sizeof e->text);
|
||||
SDL_UnlockMutex(g_log_lock);
|
||||
if (g_main && shown() && g_tab == TAB_LOGS) {
|
||||
redraw_window_only();
|
||||
reaktor_wake(g_main);
|
||||
}
|
||||
}
|
||||
if (g_log_next) g_log_next(g_log_next_user, category, priority, message);
|
||||
}
|
||||
|
||||
static int
|
||||
shown(void)
|
||||
{
|
||||
return g_win || g_floater;
|
||||
}
|
||||
|
||||
static void
|
||||
redraw_window_only(void)
|
||||
{
|
||||
App *w = g_win ? reaktor_window_app(g_win) : NULL;
|
||||
|
||||
if (w) w->dirty = 1;
|
||||
}
|
||||
|
||||
static void
|
||||
redraw(void)
|
||||
{
|
||||
redraw_window_only();
|
||||
if (g_main) {
|
||||
g_main->dirty = 1;
|
||||
reaktor_wake(g_main);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
snapshot(void)
|
||||
{
|
||||
const reaktor_a11y_node *t = reaktor_a11y_tree(&g_main->a11y, &g_n);
|
||||
int i, j;
|
||||
|
||||
if (g_n > REAKTOR_A11Y_MAX_NODES) g_n = REAKTOR_A11Y_MAX_NODES;
|
||||
g_sel_ix = -1;
|
||||
for (i = 0; i < g_n; i++) {
|
||||
g_node[i] = t[i];
|
||||
g_parent[i] = -1;
|
||||
for (j = i - 1; j >= 0; j--)
|
||||
if (t[j].id == t[i].parent) { g_parent[i] = j; break; }
|
||||
if (t[i].name && *t[i].name)
|
||||
SDL_snprintf(g_label[i], sizeof g_label[i], "%s \"%s\"",
|
||||
reaktor_a11y_role_name(t[i].role), t[i].name);
|
||||
else
|
||||
SDL_strlcpy(g_label[i], reaktor_a11y_role_name(t[i].role), sizeof g_label[i]);
|
||||
if (t[i].id == g_sel) g_sel_ix = i;
|
||||
}
|
||||
}
|
||||
|
||||
static const reaktor_a11y_node *
|
||||
selected(void)
|
||||
{
|
||||
return g_sel_ix >= 0 ? &g_node[g_sel_ix] : NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
row(const char *k, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
if (g_rows >= ROWS) return;
|
||||
SDL_strlcpy(g_kv[g_rows][0], k, sizeof g_kv[g_rows][0]);
|
||||
va_start(ap, fmt);
|
||||
SDL_vsnprintf(g_kv[g_rows][1], sizeof g_kv[g_rows][1], fmt, ap);
|
||||
va_end(ap);
|
||||
g_rows++;
|
||||
}
|
||||
|
||||
static const char *
|
||||
kv_cell(int r, int c, void *user)
|
||||
{
|
||||
(void)user;
|
||||
return g_kv[r][c];
|
||||
}
|
||||
|
||||
static void
|
||||
kv_list(const char *name)
|
||||
{
|
||||
static const char *const cols[] = { "Property", "Value" };
|
||||
static const float widths[] = { 2.0f, 3.0f };
|
||||
|
||||
reaktor_list(&(reaktor_list_spec){
|
||||
.name = name, .count = g_rows, .columns = cols, .widths = widths,
|
||||
.column_count = 2, .cell = kv_cell,
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y } });
|
||||
}
|
||||
|
||||
static void
|
||||
note(const char *text)
|
||||
{
|
||||
reaktor_label(&(reaktor_label_spec){ .text = text, .wrap = 1,
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X,
|
||||
.ml = 16.0f, .mr = 12.0f } });
|
||||
}
|
||||
|
||||
static int
|
||||
tree_parent(int node, void *user)
|
||||
{
|
||||
(void)user;
|
||||
return g_parent[node];
|
||||
}
|
||||
|
||||
static const char *
|
||||
tree_label(int node, void *user)
|
||||
{
|
||||
(void)user;
|
||||
return g_label[node];
|
||||
}
|
||||
|
||||
static void
|
||||
tab_tree(void)
|
||||
{
|
||||
int sel = g_sel_ix;
|
||||
|
||||
reaktor_tree(&(reaktor_tree_spec){
|
||||
.name = "Widgets", .count = g_n, .parent = tree_parent, .label = tree_label,
|
||||
.open = g_open, .selected = &sel,
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y } });
|
||||
if (sel != g_sel_ix && sel >= 0 && sel < g_n) {
|
||||
g_sel = g_node[sel].id;
|
||||
g_sel_ix = sel;
|
||||
redraw();
|
||||
}
|
||||
}
|
||||
|
||||
static const char *
|
||||
size_of(float v, unsigned flags, unsigned fill, unsigned sized)
|
||||
{
|
||||
if (flags & fill) return "fills its parent";
|
||||
if (v <= 0.0f) return "from its content";
|
||||
if (flags & sized) return "from the stylesheet or its text";
|
||||
return "fixed by the page: a rule cannot change it";
|
||||
}
|
||||
|
||||
static void
|
||||
tab_box(void)
|
||||
{
|
||||
const reaktor_a11y_node *n = selected();
|
||||
struct nk_rect r;
|
||||
unsigned flags;
|
||||
unsigned char dir;
|
||||
float w, h;
|
||||
|
||||
g_rows = 0;
|
||||
if (!n) {
|
||||
note("Choose a widget in the Tree tab, or pick one in the app.");
|
||||
return;
|
||||
}
|
||||
row("Role", "%s", reaktor_a11y_role_name(n->role));
|
||||
row("Name", "%s", n->name ? n->name : "");
|
||||
if (n->value) row("Value", "%s", n->value);
|
||||
row("Id", "%08x", n->id);
|
||||
row("Bounds", "%.0f, %.0f %.0f x %.0f", n->bounds.x, n->bounds.y,
|
||||
n->bounds.w, n->bounds.h);
|
||||
if (reaktor_layout_rect(&g_main->lay, n->id, &r))
|
||||
row("Laid out, in its parent", "%.0f, %.0f %.0f x %.0f", r.x, r.y, r.w, r.h);
|
||||
if (reaktor_layout_info(&g_main->lay, n->id, &flags, &dir, &w, &h)) {
|
||||
if (n->role == REAKTOR_A11Y_GROUP)
|
||||
row("Direction", "%s", dir == REAKTOR_LAY_ROW ? "row"
|
||||
: dir == REAKTOR_LAY_COLUMN ? "column" : "free");
|
||||
row("Width", "%.0f, %s", w, size_of(w, flags, REAKTOR_LAY_FILL_X, REAKTOR_LAY_SIZED_W));
|
||||
row("Height", "%.0f, %s", h, size_of(h, flags, REAKTOR_LAY_FILL_Y, REAKTOR_LAY_SIZED_H));
|
||||
row("Flags", "%s%s%s%s%s",
|
||||
flags & REAKTOR_LAY_WRAP ? "wrap " : "",
|
||||
flags & REAKTOR_LAY_CENTER_X ? "center-x " : "",
|
||||
flags & REAKTOR_LAY_CENTER_Y ? "center-y " : "",
|
||||
flags & REAKTOR_LAY_PACK_CENTER ? "pack-center " : "",
|
||||
flags & REAKTOR_LAY_PACK_END ? "pack-end " : "");
|
||||
row("Margins from the sheet", "%s%s%s%s",
|
||||
flags & REAKTOR_LAY_SHEET_L ? "left " : "",
|
||||
flags & REAKTOR_LAY_SHEET_T ? "top " : "",
|
||||
flags & REAKTOR_LAY_SHEET_R ? "right " : "",
|
||||
flags & REAKTOR_LAY_SHEET_B ? "bottom " : "");
|
||||
}
|
||||
row("State", "%s%s%s%s%s",
|
||||
n->state & REAKTOR_A11Y_FOCUSED ? "focused " : "",
|
||||
n->state & REAKTOR_A11Y_CHECKED ? "checked " : "",
|
||||
n->state & REAKTOR_A11Y_SELECTED ? "selected " : "",
|
||||
n->state & REAKTOR_A11Y_DISABLED ? "disabled " : "",
|
||||
n->state & REAKTOR_A11Y_OFFSCREEN ? "offscreen " : "");
|
||||
kv_list("Box");
|
||||
}
|
||||
|
||||
static const char *
|
||||
selector_of(unsigned char role)
|
||||
{
|
||||
switch (role) {
|
||||
case REAKTOR_A11Y_BUTTON: return "button";
|
||||
case REAKTOR_A11Y_LINK: return "a";
|
||||
case REAKTOR_A11Y_CHECKBOX: return "input.type-checkbox";
|
||||
case REAKTOR_A11Y_RADIO: return "input.type-radio";
|
||||
case REAKTOR_A11Y_TEXTBOX:
|
||||
case REAKTOR_A11Y_SPINBUTTON: return "input";
|
||||
case REAKTOR_A11Y_COMBOBOX: return "select";
|
||||
case REAKTOR_A11Y_SLIDER: return "input.type-range";
|
||||
case REAKTOR_A11Y_PROGRESS: return "progress";
|
||||
case REAKTOR_A11Y_MENU:
|
||||
case REAKTOR_A11Y_MENUITEM: return "menu";
|
||||
case REAKTOR_A11Y_DIALOG: return "dialog";
|
||||
case REAKTOR_A11Y_LABEL: return "p";
|
||||
default: return "body";
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
color_row(const char *k, const unsigned char c[4])
|
||||
{
|
||||
row(k, "#%02x%02x%02x%02x", c[0], c[1], c[2], c[3]);
|
||||
}
|
||||
|
||||
static void
|
||||
apply_css(void)
|
||||
{
|
||||
g_css_on = g_css_len > 0;
|
||||
SDL_memcpy(g_css_applied, g_css, (size_t)g_css_len);
|
||||
if (g_css_on)
|
||||
reaktor_asset_register(".reaktor-inspector.css", g_css_applied, (size_t)g_css_len);
|
||||
reaktor_restyle();
|
||||
}
|
||||
|
||||
static void
|
||||
tab_style(void)
|
||||
{
|
||||
const reaktor_a11y_node *n = selected();
|
||||
const char *sel = n ? selector_of(n->role) : "body";
|
||||
reaktor_style st;
|
||||
|
||||
g_rows = 0;
|
||||
reaktor_style_get(sel, &st);
|
||||
row("Selector", "%s%s", sel, st.matched ? "" : " (no rule matches)");
|
||||
color_row("color", st.fg);
|
||||
color_row("background", st.bg);
|
||||
color_row("border-color", st.border_col);
|
||||
row("border-width", "%.0f %.0f %.0f %.0f", st.border_w[0], st.border_w[1],
|
||||
st.border_w[2], st.border_w[3]);
|
||||
row("border-radius", "%.0f %.0f %.0f %.0f", st.radius[0], st.radius[1],
|
||||
st.radius[2], st.radius[3]);
|
||||
row("padding", "%.0f %.0f %.0f %.0f", st.pad[0], st.pad[1], st.pad[2], st.pad[3]);
|
||||
row("margin", "%.0f %.0f %.0f %.0f", st.margin[0], st.margin[1], st.margin[2],
|
||||
st.margin[3]);
|
||||
row("width / height", "%.0f / %.0f", st.width, st.height);
|
||||
row("min", "%.0f x %.0f", st.min_width, st.min_height);
|
||||
row("max", "%.0f x %.0f", st.max_width, st.max_height);
|
||||
row("font", "%dpx%s", st.font_px, st.bold ? " bold" : "");
|
||||
REAKTOR_COLUMN(.flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y, .gap = 8.0f) {
|
||||
kv_list("Style");
|
||||
note("CSS here applies after every other sheet, to this run only.");
|
||||
reaktor_field(&(reaktor_field_spec){
|
||||
.buf = g_css, .len = &g_css_len, .cap = CSS_CAP, .multiline = 1,
|
||||
.name = "Extra CSS", .hint = "button { border-radius: 0 }",
|
||||
.pad_x = 10.0f, .pad_y = 8.0f,
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X, .h = 120.0f, .ml = 12.0f, .mr = 12.0f } });
|
||||
REAKTOR_ROW(.flags = REAKTOR_LAY_FILL_X, .gap = 2.0f, .ml = 12.0f) {
|
||||
if (reaktor_button(&(reaktor_button_spec){ .label = "Apply", .accent = 1,
|
||||
.fit_content = 1 }))
|
||||
apply_css();
|
||||
if (reaktor_button(&(reaktor_button_spec){ .label = "Remove", .fit_content = 1,
|
||||
.disabled = (unsigned char)!g_css_on })) {
|
||||
g_css_len = 0;
|
||||
apply_css();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
tab_frame(void)
|
||||
{
|
||||
reaktor_diag d;
|
||||
|
||||
g_rows = 0;
|
||||
reaktor_diagnostics(g_main, &d);
|
||||
row("Frames drawn", "%u", g_frames);
|
||||
row("Last frame ran for", "%s%s%s%s%s",
|
||||
g_why & REAKTOR_WHY_INPUT ? "input " : "",
|
||||
g_why & REAKTOR_WHY_RESIZE ? "resize " : "",
|
||||
g_why & REAKTOR_WHY_MOTION ? "motion " : "",
|
||||
g_why & REAKTOR_WHY_STYLE ? "stylesheets " : "",
|
||||
g_why ? "" : "a timer, a wake or an animation");
|
||||
row("Build", "%.2f ms", d.build_ms);
|
||||
row("Render", "%.2f ms", d.render_ms);
|
||||
row("Present", "%.2f ms", d.present_ms);
|
||||
row("Since the previous frame", "%.1f ms", d.frame_gap_ms);
|
||||
row("Stylesheets", "%d, loaded in %.2f ms", d.sheets, d.style_ms);
|
||||
row("Renderer", "%s, %s", d.renderer ? d.renderer : "", d.mode ? d.mode : "");
|
||||
row("Scale", "%.2f", d.scale);
|
||||
row("Process memory", "%lu KiB", d.rss_bytes / 1024ul);
|
||||
kv_list("Frame");
|
||||
}
|
||||
|
||||
static const char *
|
||||
log_cell(int r, int c, void *user)
|
||||
{
|
||||
static const char *const level[] = { "", "trace", "verbose", "debug", "info",
|
||||
"warn", "error", "critical" };
|
||||
static char buf[32];
|
||||
const log_entry *e = &g_log[g_log_row[r]];
|
||||
|
||||
(void)user;
|
||||
switch (c) {
|
||||
case 0:
|
||||
SDL_snprintf(buf, sizeof buf, "%llu.%03llu", (unsigned long long)(e->ms / 1000),
|
||||
(unsigned long long)(e->ms % 1000));
|
||||
return buf;
|
||||
case 1:
|
||||
return (unsigned)e->priority < SDL_arraysize(level) ? level[e->priority] : "?";
|
||||
default:
|
||||
return e->text;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
tab_logs(void)
|
||||
{
|
||||
static const char *const cols[] = { "Time", "Level", "Message" };
|
||||
static const float widths[] = { 1.0f, 1.0f, 6.0f };
|
||||
static const char *const levels[] = { "Everything", "Debug and up", "Info and up",
|
||||
"Warnings and errors", "Errors" };
|
||||
static const SDL_LogPriority floor_of[] = { SDL_LOG_PRIORITY_TRACE,
|
||||
SDL_LOG_PRIORITY_DEBUG, SDL_LOG_PRIORITY_INFO, SDL_LOG_PRIORITY_WARN,
|
||||
SDL_LOG_PRIORITY_ERROR };
|
||||
int i;
|
||||
|
||||
REAKTOR_ROW(.flags = REAKTOR_LAY_FILL_X, .gap = 8.0f) {
|
||||
reaktor_spinner(&(reaktor_spinner_spec){
|
||||
.label = "Show:", .items = levels, .count = 5, .chosen = &g_log_min,
|
||||
.box = { .w = 300.0f, .ml = 12.0f, .mb = 8.0f } });
|
||||
}
|
||||
SDL_LockMutex(g_log_lock);
|
||||
for (g_log_rows = i = 0; i < g_log_n; i++) {
|
||||
int k = (g_log_head + i) % LOG_MAX;
|
||||
|
||||
if (g_log[k].priority >= floor_of[g_log_min]) g_log_row[g_log_rows++] = k;
|
||||
}
|
||||
SDL_UnlockMutex(g_log_lock);
|
||||
reaktor_list(&(reaktor_list_spec){
|
||||
.name = "Log", .count = g_log_rows, .columns = cols, .widths = widths,
|
||||
.column_count = 3, .cell = log_cell,
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y } });
|
||||
}
|
||||
|
||||
/* A flat icon beside the tabs; its name is also what the pointer shows. */
|
||||
static int
|
||||
tool(const char *icon, const char *name, const char *tip, int on, int off, float mr)
|
||||
{
|
||||
return reaktor_button(&(reaktor_button_spec){
|
||||
.icon = icon, .name = name, .tooltip = tip ? tip : name, .flat = 1,
|
||||
.accent = (unsigned char)on, .disabled = (unsigned char)off,
|
||||
.box = { .w = 24.0f, .h = 32.0f, .mr = mr } });
|
||||
}
|
||||
|
||||
static void
|
||||
page(App *app, struct reaktor_context *ctx, int w, int h, void *user)
|
||||
{
|
||||
static const char *const tabs[TABS] = { "Tree", "Box", "Style", "Frame", "Logs" };
|
||||
|
||||
(void)app; (void)ctx; (void)user; (void)w;
|
||||
if (!g_main) return;
|
||||
snapshot();
|
||||
REAKTOR_COLUMN(.h = (float)h - 12.0f, .gap = 10.0f, .flags = REAKTOR_LAY_FILL_X) {
|
||||
REAKTOR_ROW(.flags = REAKTOR_LAY_FILL_X, .gap = 2.0f) {
|
||||
reaktor_tabs(&(reaktor_tabs_spec){ .items = tabs, .count = TABS, .chosen = &g_tab,
|
||||
.name = "Inspector",
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X } });
|
||||
if (g_tab == TAB_LOGS && tool("checkmark-circle-outline", "Clear the log", NULL, 0, 0, 0.0f)) {
|
||||
SDL_LockMutex(g_log_lock);
|
||||
g_log_n = g_log_head = 0;
|
||||
SDL_UnlockMutex(g_log_lock);
|
||||
}
|
||||
if (tool("help-circle-outline", "Pick a widget",
|
||||
g_picking ? "Click a widget in the app" : "Pick a widget in the app",
|
||||
g_picking, 0, 0.0f)) {
|
||||
g_picking = !g_picking;
|
||||
redraw();
|
||||
}
|
||||
#ifdef __EMSCRIPTEN__
|
||||
if (tool("remove-circle-outline", "Clear the selection", NULL, 0, g_sel == 0, 0.0f)) {
|
||||
g_sel = 0;
|
||||
redraw();
|
||||
}
|
||||
/* The page's floater has no titlebar to close it from. */
|
||||
if (tool("close-circle-outline", "Close the Inspector", NULL, 0, 0, 8.0f))
|
||||
reaktor_inspector_close(g_main);
|
||||
#else
|
||||
if (tool("remove-circle-outline", "Clear the selection", NULL, 0, g_sel == 0, 8.0f)) {
|
||||
g_sel = 0;
|
||||
redraw();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
REAKTOR_COLUMN(.flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y, .gap = 8.0f) {
|
||||
switch (g_tab) {
|
||||
case TAB_TREE: tab_tree(); break;
|
||||
case TAB_BOX: tab_box(); break;
|
||||
case TAB_STYLE: tab_style(); break;
|
||||
case TAB_FRAME: tab_frame(); break;
|
||||
default: tab_logs(); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
closed(App *app, void *user)
|
||||
{
|
||||
(void)app; (void)user;
|
||||
g_win = g_floater = 0;
|
||||
g_picking = 0;
|
||||
redraw();
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_inspector_open(App *app)
|
||||
{
|
||||
char title[160];
|
||||
|
||||
(void)app;
|
||||
if (!g_attached || !g_main) return 0;
|
||||
if (shown()) return 1;
|
||||
SDL_snprintf(title, sizeof title, "%s - Inspector",
|
||||
SDL_GetWindowTitle(g_main->win) ? SDL_GetWindowTitle(g_main->win) : "Reaktor");
|
||||
#ifdef __EMSCRIPTEN__
|
||||
g_floater = reaktor_floater_open(g_main, &(reaktor_floater){
|
||||
.title = "Inspector", .w = 560.0f, .h = 600.0f, .body = page, .closed = closed });
|
||||
#else
|
||||
g_win = reaktor_window_open(g_main, &(reaktor_window){
|
||||
.window = { .title = title, .w = 560, .h = 680, .min_w = 360, .min_h = 320 },
|
||||
.page = page, .closed = closed });
|
||||
#endif
|
||||
redraw();
|
||||
return shown();
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_inspector_close(App *app)
|
||||
{
|
||||
(void)app;
|
||||
if (g_win) reaktor_window_close(g_main, g_win);
|
||||
if (g_floater) reaktor_floater_close(g_main, g_floater);
|
||||
closed(g_main, NULL);
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_inspector_shown(App *app)
|
||||
{
|
||||
(void)app;
|
||||
return shown();
|
||||
}
|
||||
|
||||
static void
|
||||
log_release(void)
|
||||
{
|
||||
SDL_LogOutputFunction now;
|
||||
void *now_user;
|
||||
|
||||
if (!g_log_lock) return;
|
||||
SDL_GetLogOutputFunction(&now, &now_user);
|
||||
if (now == log_take) SDL_SetLogOutputFunction(g_log_next, g_log_next_user);
|
||||
SDL_DestroyMutex(g_log_lock);
|
||||
g_log_lock = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_inspector_early(void)
|
||||
{
|
||||
if (g_log_lock || !(g_log_lock = SDL_CreateMutex())) return;
|
||||
SDL_GetLogOutputFunction(&g_log_next, &g_log_next_user);
|
||||
SDL_SetLogOutputFunction(log_take, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_inspector_start(App *app, const reaktor_inspector_spec *spec, int flag)
|
||||
{
|
||||
g_spec = *spec;
|
||||
g_attached = flag >= 0 && spec->attach;
|
||||
if (!g_attached) {
|
||||
log_release();
|
||||
return;
|
||||
}
|
||||
g_main = app;
|
||||
SDL_memset(g_open, 1, sizeof g_open);
|
||||
if (g_spec.open || flag > 0) reaktor_inspector_open(app);
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_inspector_stop(App *app)
|
||||
{
|
||||
(void)app;
|
||||
if (g_attached) reaktor_inspector_close(g_main);
|
||||
log_release();
|
||||
g_main = NULL;
|
||||
g_attached = 0;
|
||||
}
|
||||
|
||||
static int
|
||||
chord(const SDL_Event *e)
|
||||
{
|
||||
if (g_spec.key == (SDL_Keycode)-1) return 0;
|
||||
if (g_spec.key || g_spec.mods) return reaktor_chord(e, g_spec.mods, g_spec.key);
|
||||
#ifdef __APPLE__
|
||||
return reaktor_chord(e, REAKTOR_MOD_CMD | REAKTOR_MOD_ALT, SDLK_I);
|
||||
#else
|
||||
return reaktor_chord(e, REAKTOR_MOD_CTRL | REAKTOR_MOD_SHIFT, SDLK_I);
|
||||
#endif
|
||||
}
|
||||
|
||||
static unsigned
|
||||
widget_at(float x, float y)
|
||||
{
|
||||
const reaktor_a11y_node *t;
|
||||
unsigned id = 0;
|
||||
int i, n, depth = -1;
|
||||
|
||||
t = reaktor_a11y_tree(&g_main->a11y, &n);
|
||||
for (i = 0; i < n; i++) {
|
||||
const struct nk_rect *r = &t[i].bounds;
|
||||
|
||||
if (t[i].level >= depth && r->w > 0.0f && r->h > 0.0f &&
|
||||
x >= r->x && y >= r->y && x < r->x + r->w && y < r->y + r->h) {
|
||||
id = t[i].id;
|
||||
depth = t[i].level;
|
||||
}
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_inspector_event(App *app, const SDL_Event *e)
|
||||
{
|
||||
if (!g_attached || app != g_main) return 0;
|
||||
if (e->type == SDL_EVENT_KEY_DOWN && !e->key.repeat && chord(e)) {
|
||||
if (shown()) reaktor_inspector_close(app);
|
||||
else reaktor_inspector_open(app);
|
||||
return 1;
|
||||
}
|
||||
if (g_picking && e->type == SDL_EVENT_MOUSE_BUTTON_DOWN) {
|
||||
g_sel = widget_at(e->button.x, e->button.y);
|
||||
g_picking = 0;
|
||||
g_tab = TAB_BOX;
|
||||
redraw();
|
||||
return 1;
|
||||
}
|
||||
if (g_picking && e->type == SDL_EVENT_MOUSE_BUTTON_UP) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_inspector_frame(App *app)
|
||||
{
|
||||
if (app != g_main) return;
|
||||
g_frames++;
|
||||
g_why = app->why;
|
||||
app->why = 0;
|
||||
if (shown()) redraw_window_only();
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_inspector_marks(App *app)
|
||||
{
|
||||
return app == g_main && shown() && g_sel != 0;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_inspector_mark(App *app, struct nk_context *ctx, struct nk_command_buffer *o)
|
||||
{
|
||||
const reaktor_a11y_node *t;
|
||||
unsigned char c[4] = { 0xd0, 0x3a, 0xe0, 0xff };
|
||||
int i, n;
|
||||
|
||||
(void)ctx;
|
||||
if (!reaktor_inspector_marks(app)) return;
|
||||
reaktor_style_token("--accent", c);
|
||||
t = reaktor_a11y_tree(&app->a11y, &n);
|
||||
for (i = 0; i < n; i++) {
|
||||
if (t[i].id != g_sel) continue;
|
||||
nk_fill_rect(o, t[i].bounds, 0.0f, nk_rgba(c[0], c[1], c[2], 48));
|
||||
nk_stroke_rect(o, t[i].bounds, 0.0f, 2.0f, nk_rgba(c[0], c[1], c[2], 255));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const char *
|
||||
reaktor_inspector_sheet(void)
|
||||
{
|
||||
return g_css_on ? ".reaktor-inspector.css" : NULL;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#include "internal.h"
|
||||
#include "reaktor/launch.h"
|
||||
|
||||
int reaktor_inspector_open(App *app) { (void)app; return 0; }
|
||||
void reaktor_inspector_close(App *app) { (void)app; }
|
||||
int reaktor_inspector_shown(App *app) { (void)app; return 0; }
|
||||
|
||||
void reaktor_inspector_start(App *app, const reaktor_inspector_spec *spec, int flag)
|
||||
{
|
||||
(void)app; (void)spec; (void)flag;
|
||||
}
|
||||
void reaktor_inspector_early(void) { }
|
||||
void reaktor_inspector_stop(App *app) { (void)app; }
|
||||
int reaktor_inspector_event(App *app, const SDL_Event *e) { (void)app; (void)e; return 0; }
|
||||
void reaktor_inspector_frame(App *app) { app->why = 0; }
|
||||
int reaktor_inspector_marks(App *app) { (void)app; return 0; }
|
||||
void reaktor_inspector_mark(App *app, struct nk_context *ctx, struct nk_command_buffer *o)
|
||||
{
|
||||
(void)app; (void)ctx; (void)o;
|
||||
}
|
||||
const char *reaktor_inspector_sheet(void) { return NULL; }
|
||||
@@ -0,0 +1,34 @@
|
||||
#include "internal.h"
|
||||
#include "reaktor/launch.h"
|
||||
|
||||
int
|
||||
reaktor_window_popup(struct nk_rect r,
|
||||
void (*page)(App *, struct nk_context *, int, int, void *),
|
||||
void *user)
|
||||
{
|
||||
App *m = reaktor_main_app();
|
||||
reaktor_window spec;
|
||||
|
||||
if (!m || m->popups_inline) return 0;
|
||||
SDL_zero(spec);
|
||||
spec.page = page;
|
||||
spec.user = user;
|
||||
return reaktor_window_spawn(&spec, &r);
|
||||
}
|
||||
|
||||
/* The usable display, in the main window's logical units. */
|
||||
int
|
||||
reaktor_window_bounds(struct nk_rect *out)
|
||||
{
|
||||
App *m = reaktor_main_app();
|
||||
SDL_Rect d;
|
||||
int x, y;
|
||||
float k = reaktor_window_points();
|
||||
|
||||
if (!m || m->popups_inline ||
|
||||
!SDL_GetDisplayUsableBounds(SDL_GetDisplayForWindow(m->win), &d) ||
|
||||
!SDL_GetWindowPosition(m->win, &x, &y))
|
||||
return 0;
|
||||
*out = nk_rect((float)(d.x - x) / k, (float)(d.y - y) / k, (float)d.w / k, (float)d.h / k);
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
#include "internal.h"
|
||||
|
||||
int
|
||||
reaktor_window_popup(struct nk_rect r,
|
||||
void (*page)(App *, struct nk_context *, int, int, void *),
|
||||
void *user)
|
||||
{
|
||||
(void)r; (void)page; (void)user;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int reaktor_window_bounds(struct nk_rect *out) { (void)out; return 0; }
|
||||
@@ -0,0 +1,215 @@
|
||||
#include "internal.h"
|
||||
#include "reaktor/launch.h"
|
||||
#include "declare.h"
|
||||
#include "hpdf.h"
|
||||
#include "plutovg.h"
|
||||
|
||||
#define REAKTOR_PRINT_PAGES 64
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <commdlg.h>
|
||||
#endif
|
||||
|
||||
typedef struct print_job {
|
||||
reaktor_print_spec spec;
|
||||
char *path;
|
||||
int index, to_printer;
|
||||
} print_job;
|
||||
|
||||
typedef struct jpeg_buf {
|
||||
unsigned char *bytes;
|
||||
size_t len, cap;
|
||||
} jpeg_buf;
|
||||
|
||||
static void
|
||||
print_page(App *app, struct nk_context *ctx, int w, int h, void *user)
|
||||
{
|
||||
print_job *job = (print_job *)user;
|
||||
|
||||
job->spec.page(app, ctx, job->index, w, h, job->spec.user);
|
||||
}
|
||||
|
||||
static void
|
||||
jpeg_put(void *closure, void *data, int size)
|
||||
{
|
||||
jpeg_buf *b = (jpeg_buf *)closure;
|
||||
|
||||
if (b->len + (size_t)size > b->cap) {
|
||||
size_t cap = (b->len + (size_t)size) * 2;
|
||||
unsigned char *more = (unsigned char *)SDL_realloc(b->bytes, cap);
|
||||
|
||||
if (!more) return;
|
||||
b->bytes = more;
|
||||
b->cap = cap;
|
||||
}
|
||||
SDL_memcpy(b->bytes + b->len, data, (size_t)size);
|
||||
b->len += (size_t)size;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
/* The system's print dialog, then each page stretched over the printable area. */
|
||||
static int
|
||||
print_win32(App *app, SDL_Surface *const *page, int n, const char *title)
|
||||
{
|
||||
PRINTDLGEXW pd;
|
||||
DOCINFOW di;
|
||||
WCHAR name[256];
|
||||
int i, ok = 1;
|
||||
|
||||
SDL_zero(pd);
|
||||
pd.lStructSize = sizeof pd;
|
||||
pd.hwndOwner = (HWND)SDL_GetPointerProperty(SDL_GetWindowProperties(app->win),
|
||||
SDL_PROP_WINDOW_WIN32_HWND_POINTER, NULL);
|
||||
pd.Flags = PD_RETURNDC | PD_NOSELECTION | PD_NOCURRENTPAGE | PD_NOPAGENUMS;
|
||||
pd.nStartPage = START_PAGE_GENERAL;
|
||||
if (PrintDlgExW(&pd) != S_OK || pd.dwResultAction != PD_RESULT_PRINT || !pd.hDC) {
|
||||
if (pd.hDC) DeleteDC(pd.hDC);
|
||||
return 0;
|
||||
}
|
||||
MultiByteToWideChar(CP_UTF8, 0, title, -1, name, (int)SDL_arraysize(name) - 1);
|
||||
SDL_zero(di);
|
||||
di.cbSize = sizeof di;
|
||||
di.lpszDocName = name;
|
||||
if (StartDocW(pd.hDC, &di) <= 0) ok = 0;
|
||||
for (i = 0; ok && i < n; i++) {
|
||||
int pw = GetDeviceCaps(pd.hDC, HORZRES), ph = GetDeviceCaps(pd.hDC, VERTRES);
|
||||
BITMAPINFO bi;
|
||||
|
||||
SDL_zero(bi);
|
||||
bi.bmiHeader.biSize = sizeof bi.bmiHeader;
|
||||
bi.bmiHeader.biWidth = page[i]->w;
|
||||
bi.bmiHeader.biHeight = -page[i]->h;
|
||||
bi.bmiHeader.biPlanes = 1;
|
||||
bi.bmiHeader.biBitCount = 32;
|
||||
bi.bmiHeader.biCompression = BI_RGB;
|
||||
ok = StartPage(pd.hDC) > 0 &&
|
||||
StretchDIBits(pd.hDC, 0, 0, pw, ph, 0, 0, page[i]->w, page[i]->h,
|
||||
page[i]->pixels, &bi, DIB_RGB_COLORS, SRCCOPY) != GDI_ERROR &&
|
||||
EndPage(pd.hDC) > 0;
|
||||
}
|
||||
if (ok) EndDoc(pd.hDC);
|
||||
else AbortDoc(pd.hDC);
|
||||
DeleteDC(pd.hDC);
|
||||
if (pd.hDevMode) GlobalFree(pd.hDevMode);
|
||||
if (pd.hDevNames) GlobalFree(pd.hDevNames);
|
||||
return ok;
|
||||
}
|
||||
#elif defined(__APPLE__)
|
||||
int reaktor_print_macos(const char *path);
|
||||
#endif
|
||||
|
||||
static void
|
||||
print_run(App *app, void *user)
|
||||
{
|
||||
print_job *job = (print_job *)user;
|
||||
float keep = reaktor_scale(), pt_w = job->spec.w, pt_h = job->spec.h;
|
||||
SDL_Surface *page[REAKTOR_PRINT_PAGES];
|
||||
HPDF_Doc doc = NULL;
|
||||
App *pa = NULL;
|
||||
int id, i, n = 0, ok = 1;
|
||||
|
||||
SDL_zero(page);
|
||||
reaktor_set_scale((float)job->spec.dpi / 72.0f);
|
||||
id = reaktor_window_spawn(&(reaktor_window){
|
||||
.window = { .w = (int)pt_w, .h = (int)pt_h, .hidden = 1, .borderless = 1 },
|
||||
.page = print_page, .user = job }, NULL);
|
||||
pa = id ? reaktor_window_app(id) : NULL;
|
||||
for (i = 0; pa && i < job->spec.pages && i < REAKTOR_PRINT_PAGES; i++, n++) {
|
||||
int w, h, k;
|
||||
|
||||
job->index = i;
|
||||
reaktor_app_size(pa, &w, &h);
|
||||
for (k = 0; k < 6 || (!reaktor_frame_settled(pa) && k < 24); k++)
|
||||
reaktor_app_frame(pa, w, h, "", print_page, job);
|
||||
pa->want_capture = 1;
|
||||
reaktor_app_frame(pa, w, h, "", print_page, job);
|
||||
page[i] = pa->capture ? SDL_ConvertSurface(pa->capture, SDL_PIXELFORMAT_ARGB8888) : NULL;
|
||||
SDL_DestroySurface(pa->capture);
|
||||
pa->capture = NULL;
|
||||
if (!page[i]) ok = 0;
|
||||
}
|
||||
if (id) reaktor_window_close(app, id);
|
||||
reaktor_set_scale(keep);
|
||||
if (!pa) ok = 0;
|
||||
|
||||
#ifdef _WIN32
|
||||
if (ok && job->to_printer)
|
||||
ok = print_win32(app, page, n, job->spec.title ? job->spec.title : "Reaktor");
|
||||
else
|
||||
#endif
|
||||
if (ok) doc = HPDF_New(NULL, NULL);
|
||||
for (i = 0; doc && ok && i < n; i++) {
|
||||
plutovg_surface_t *s = plutovg_surface_create_for_data(page[i]->pixels, page[i]->w,
|
||||
page[i]->h, page[i]->pitch);
|
||||
jpeg_buf b = { NULL, 0, 0 };
|
||||
HPDF_Page p = HPDF_AddPage(doc);
|
||||
HPDF_Image im = NULL;
|
||||
|
||||
if (s) plutovg_surface_write_to_jpg_stream(s, jpeg_put, &b, 90);
|
||||
plutovg_surface_destroy(s);
|
||||
if (b.len) im = HPDF_LoadJpegImageFromMem(doc, b.bytes, (HPDF_UINT)b.len);
|
||||
SDL_free(b.bytes);
|
||||
HPDF_Page_SetWidth(p, pt_w);
|
||||
HPDF_Page_SetHeight(p, pt_h);
|
||||
if (!im || HPDF_Page_DrawImage(p, im, 0, 0, pt_w, pt_h) != HPDF_OK) ok = 0;
|
||||
}
|
||||
if (doc && job->spec.title) HPDF_SetInfoAttr(doc, HPDF_INFO_TITLE, job->spec.title);
|
||||
if (doc && ok) ok = HPDF_SaveToFile(doc, job->path) == HPDF_OK;
|
||||
if (doc) HPDF_Free(doc);
|
||||
#if defined(__APPLE__)
|
||||
if (doc && ok && job->to_printer) ok = reaktor_print_macos(job->path);
|
||||
#elif !defined(_WIN32)
|
||||
if (doc && ok && job->to_printer) {
|
||||
char *url = NULL;
|
||||
|
||||
SDL_asprintf(&url, "file://%s", job->path);
|
||||
ok = url && SDL_OpenURL(url);
|
||||
SDL_free(url);
|
||||
}
|
||||
#endif
|
||||
for (i = 0; i < REAKTOR_PRINT_PAGES; i++) SDL_DestroySurface(page[i]);
|
||||
if (job->spec.done) job->spec.done(app, ok, job->spec.user);
|
||||
SDL_free(job->path);
|
||||
SDL_free(job);
|
||||
}
|
||||
|
||||
static int
|
||||
print_queue(App *app, const char *path, const reaktor_print_spec *s, int to_printer)
|
||||
{
|
||||
print_job *job;
|
||||
|
||||
if (!app || !s || !s->page || s->pages <= 0 || (!path && !to_printer)) return 0;
|
||||
if (!(job = (print_job *)SDL_calloc(1, sizeof *job))) return 0;
|
||||
job->spec = *s;
|
||||
if (job->spec.w <= 0.0f) job->spec.w = 595.0f;
|
||||
if (job->spec.h <= 0.0f) job->spec.h = 842.0f;
|
||||
if (job->spec.dpi <= 0) job->spec.dpi = 200;
|
||||
job->to_printer = to_printer;
|
||||
if (path) {
|
||||
job->path = SDL_strdup(path);
|
||||
} else {
|
||||
char *dir = SDL_GetPrefPath(NULL, reaktor_app_ident());
|
||||
|
||||
if (dir) SDL_asprintf(&job->path, "%sprint.pdf", dir);
|
||||
SDL_free(dir);
|
||||
}
|
||||
if (!job->path || !reaktor_timer(app, 1, 0, print_run, job)) {
|
||||
SDL_free(job->path);
|
||||
SDL_free(job);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_print(App *app, const reaktor_print_spec *s)
|
||||
{
|
||||
return print_queue(app, NULL, s, 1);
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_print_pdf(App *app, const char *path, const reaktor_print_spec *s)
|
||||
{
|
||||
return print_queue(app, path, s, 0);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <PDFKit/PDFKit.h>
|
||||
|
||||
/* The PDF through the system's print dialog. */
|
||||
int
|
||||
reaktor_print_macos(const char *path)
|
||||
{
|
||||
PDFDocument *doc;
|
||||
NSPrintOperation *op;
|
||||
|
||||
doc = [[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:
|
||||
[NSString stringWithUTF8String:path]]];
|
||||
if (!doc) return 0;
|
||||
op = [doc printOperationForPrintInfo:[NSPrintInfo sharedPrintInfo]
|
||||
scalingMode:kPDFPrintPageScaleToFit
|
||||
autoRotate:YES];
|
||||
return op && [op runOperation] ? 1 : 0;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#include "internal.h"
|
||||
|
||||
int
|
||||
reaktor_print(App *app, const reaktor_print_spec *s)
|
||||
{
|
||||
(void)app; (void)s;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_print_pdf(App *app, const char *path, const reaktor_print_spec *s)
|
||||
{
|
||||
(void)app; (void)path; (void)s;
|
||||
return 0;
|
||||
}
|
||||
@@ -1,17 +1,5 @@
|
||||
#include "internal.h"
|
||||
|
||||
#define INI_IMPLEMENTATION
|
||||
#define INI_MALLOC(ctx, size) ((void)(ctx), SDL_malloc(size))
|
||||
#define INI_FREE(ctx, ptr) ((void)(ctx), SDL_free(ptr))
|
||||
#define INI_MEMCPY(dst, src, cnt) SDL_memcpy(dst, src, cnt)
|
||||
#define INI_STRLEN(s) SDL_strlen(s)
|
||||
#define INI_STRNICMP(s1, s2, cnt) SDL_strncasecmp(s1, s2, cnt)
|
||||
#include "ini.h"
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten.h>
|
||||
#endif
|
||||
|
||||
typedef struct timer {
|
||||
SDL_TimerID id;
|
||||
App *app;
|
||||
@@ -134,203 +122,3 @@ reaktor_post(App *app, reaktor_task fn, void *user)
|
||||
p->user = user;
|
||||
if (!SDL_RunOnMainThread(post_run, p, false)) SDL_free(p);
|
||||
}
|
||||
|
||||
static ini_t *g_ini;
|
||||
static int g_ini_dirty;
|
||||
static unsigned g_save_timer;
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
EM_JS(void, settings_persist, (void), {
|
||||
FS.syncfs(false, function (err) { if (err) console.warn('settings: ' + err); });
|
||||
});
|
||||
#else
|
||||
static void settings_persist(void) {}
|
||||
#endif
|
||||
|
||||
static char *
|
||||
settings_path(void)
|
||||
{
|
||||
char *dir = SDL_GetPrefPath(NULL, reaktor_app_ident());
|
||||
char *path = NULL;
|
||||
|
||||
if (dir) SDL_asprintf(&path, "%ssettings.conf", dir);
|
||||
SDL_free(dir);
|
||||
return path;
|
||||
}
|
||||
|
||||
static ini_t *
|
||||
settings(void)
|
||||
{
|
||||
char *text;
|
||||
|
||||
if (g_ini) return g_ini;
|
||||
if (reaktor_capturing()) return g_ini = ini_create(NULL);
|
||||
{
|
||||
char *path = settings_path();
|
||||
|
||||
text = path ? (char *)SDL_LoadFile(path, NULL) : NULL;
|
||||
SDL_free(path);
|
||||
}
|
||||
g_ini = text ? ini_load(text, NULL) : ini_create(NULL);
|
||||
SDL_free(text);
|
||||
return g_ini;
|
||||
}
|
||||
|
||||
static int
|
||||
setting_find(const char *key, int *section, int add)
|
||||
{
|
||||
const char *dot = SDL_strrchr(key, '.');
|
||||
ini_t *ini = settings();
|
||||
|
||||
*section = INI_GLOBAL_SECTION;
|
||||
if (!ini) return INI_NOT_FOUND;
|
||||
if (dot) {
|
||||
*section = ini_find_section(ini, key, (int)(dot - key));
|
||||
if (*section == INI_NOT_FOUND && add)
|
||||
*section = ini_section_add(ini, key, (int)(dot - key));
|
||||
if (*section == INI_NOT_FOUND) return INI_NOT_FOUND;
|
||||
key = dot + 1;
|
||||
}
|
||||
return ini_find_property(ini, *section, key, 0);
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_settings_save(void)
|
||||
{
|
||||
int size;
|
||||
char *text;
|
||||
|
||||
if (!g_ini_dirty || !g_ini || reaktor_capturing()) return;
|
||||
size = ini_save(g_ini, NULL, 0);
|
||||
text = (char *)SDL_malloc((size_t)size);
|
||||
if (!text) return;
|
||||
ini_save(g_ini, text, size);
|
||||
{
|
||||
char *path = settings_path(), *tmp = NULL;
|
||||
|
||||
if (path) SDL_asprintf(&tmp, "%s.new", path);
|
||||
if (!tmp || !SDL_SaveFile(tmp, text, (size_t)size - 1) || !SDL_RenamePath(tmp, path))
|
||||
SDL_Log("settings not saved: %s", SDL_GetError());
|
||||
SDL_free(tmp);
|
||||
SDL_free(path);
|
||||
}
|
||||
settings_persist();
|
||||
SDL_free(text);
|
||||
g_ini_dirty = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
settings_due(App *app, void *user)
|
||||
{
|
||||
(void)app; (void)user;
|
||||
g_save_timer = 0;
|
||||
reaktor_settings_save();
|
||||
}
|
||||
|
||||
static void
|
||||
settings_changed(void)
|
||||
{
|
||||
int ms;
|
||||
reaktor_save mode = reaktor_save_mode(&ms);
|
||||
|
||||
g_ini_dirty = 1;
|
||||
#ifdef __EMSCRIPTEN__
|
||||
if (mode == REAKTOR_SAVE_ON_QUIT) mode = REAKTOR_SAVE_ON_CHANGE;
|
||||
#endif
|
||||
if (mode == REAKTOR_SAVE_ON_CHANGE)
|
||||
reaktor_settings_save();
|
||||
else if (mode == REAKTOR_SAVE_ON_TIMER && !g_save_timer)
|
||||
g_save_timer = reaktor_timer(NULL, ms, 0, settings_due, NULL);
|
||||
}
|
||||
|
||||
const char *
|
||||
reaktor_setting(const char *key)
|
||||
{
|
||||
int section, property = key ? setting_find(key, §ion, 0) : INI_NOT_FOUND;
|
||||
|
||||
return property == INI_NOT_FOUND ? NULL
|
||||
: ini_property_value(g_ini, section, property);
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_setting_set(const char *key, const char *value)
|
||||
{
|
||||
const char *name;
|
||||
int section, property;
|
||||
|
||||
if (!key || !*key || SDL_strpbrk(key, "=[]\n") || (value && SDL_strchr(value, '\n')))
|
||||
return;
|
||||
property = setting_find(key, §ion, value != NULL);
|
||||
name = SDL_strrchr(key, '.') ? SDL_strrchr(key, '.') + 1 : key;
|
||||
if (property != INI_NOT_FOUND && value &&
|
||||
SDL_strcmp(ini_property_value(g_ini, section, property), value) == 0)
|
||||
return;
|
||||
if (!value && property == INI_NOT_FOUND) return;
|
||||
if (!value)
|
||||
ini_property_remove(g_ini, section, property);
|
||||
else if (property != INI_NOT_FOUND)
|
||||
ini_property_value_set(g_ini, section, property, value, 0);
|
||||
else if (section != INI_NOT_FOUND)
|
||||
ini_property_add(g_ini, section, name, 0, value, 0);
|
||||
else
|
||||
return;
|
||||
settings_changed();
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_settings_clear(void)
|
||||
{
|
||||
ini_destroy(g_ini);
|
||||
g_ini = ini_create(NULL);
|
||||
g_ini_dirty = 0;
|
||||
if (g_save_timer) reaktor_timer_stop(g_save_timer);
|
||||
g_save_timer = 0;
|
||||
if (reaktor_capturing()) return;
|
||||
{
|
||||
char *path = settings_path();
|
||||
|
||||
if (path) SDL_RemovePath(path);
|
||||
SDL_free(path);
|
||||
}
|
||||
settings_persist();
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_settings_free(void)
|
||||
{
|
||||
ini_destroy(g_ini);
|
||||
g_ini = NULL;
|
||||
g_ini_dirty = 0;
|
||||
g_save_timer = 0;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_window_restore(App *app)
|
||||
{
|
||||
const char *at = reaktor_setting("window");
|
||||
SDL_Rect r;
|
||||
|
||||
if (at && SDL_sscanf(at, "%d %d %d %d", &r.x, &r.y, &r.w, &r.h) == 4 &&
|
||||
r.w > 0 && r.h > 0) {
|
||||
SDL_SetWindowSize(app->win, r.w, r.h);
|
||||
if (SDL_GetDisplayForRect(&r)) SDL_SetWindowPosition(app->win, r.x, r.y);
|
||||
}
|
||||
if (reaktor_setting("window.maximized")) SDL_MaximizeWindow(app->win);
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_window_remember(App *app)
|
||||
{
|
||||
char at[64];
|
||||
SDL_Rect r;
|
||||
|
||||
if (SDL_GetWindowFlags(app->win) & SDL_WINDOW_MAXIMIZED) {
|
||||
reaktor_setting_set("window.maximized", "1");
|
||||
return;
|
||||
}
|
||||
SDL_GetWindowPosition(app->win, &r.x, &r.y);
|
||||
SDL_GetWindowSize(app->win, &r.w, &r.h);
|
||||
SDL_snprintf(at, sizeof at, "%d %d %d %d", r.x, r.y, r.w, r.h);
|
||||
reaktor_setting_set("window", at);
|
||||
reaktor_setting_set("window.maximized", NULL);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,213 @@
|
||||
#include "internal.h"
|
||||
|
||||
#define INI_IMPLEMENTATION
|
||||
#define INI_MALLOC(ctx, size) ((void)(ctx), SDL_malloc(size))
|
||||
#define INI_FREE(ctx, ptr) ((void)(ctx), SDL_free(ptr))
|
||||
#define INI_MEMCPY(dst, src, cnt) SDL_memcpy(dst, src, cnt)
|
||||
#define INI_STRLEN(s) SDL_strlen(s)
|
||||
#define INI_STRNICMP(s1, s2, cnt) SDL_strncasecmp(s1, s2, cnt)
|
||||
#include "ini.h"
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten.h>
|
||||
#endif
|
||||
|
||||
static ini_t *g_ini;
|
||||
static int g_ini_dirty;
|
||||
static unsigned g_save_timer;
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
EM_JS(void, settings_persist, (void), {
|
||||
FS.syncfs(false, function (err) { if (err) console.warn('settings: ' + err); });
|
||||
});
|
||||
#else
|
||||
static void settings_persist(void) {}
|
||||
#endif
|
||||
|
||||
static char *
|
||||
settings_path(void)
|
||||
{
|
||||
char *dir = SDL_GetPrefPath(NULL, reaktor_app_ident());
|
||||
char *path = NULL;
|
||||
|
||||
if (dir) SDL_asprintf(&path, "%ssettings.conf", dir);
|
||||
SDL_free(dir);
|
||||
return path;
|
||||
}
|
||||
|
||||
static ini_t *
|
||||
settings(void)
|
||||
{
|
||||
char *text;
|
||||
|
||||
if (g_ini) return g_ini;
|
||||
if (reaktor_capturing()) return g_ini = ini_create(NULL);
|
||||
{
|
||||
char *path = settings_path();
|
||||
|
||||
text = path ? (char *)SDL_LoadFile(path, NULL) : NULL;
|
||||
SDL_free(path);
|
||||
}
|
||||
g_ini = text ? ini_load(text, NULL) : ini_create(NULL);
|
||||
SDL_free(text);
|
||||
return g_ini;
|
||||
}
|
||||
|
||||
static int
|
||||
setting_find(const char *key, int *section, int add)
|
||||
{
|
||||
const char *dot = SDL_strrchr(key, '.');
|
||||
ini_t *ini = settings();
|
||||
|
||||
*section = INI_GLOBAL_SECTION;
|
||||
if (!ini) return INI_NOT_FOUND;
|
||||
if (dot) {
|
||||
*section = ini_find_section(ini, key, (int)(dot - key));
|
||||
if (*section == INI_NOT_FOUND && add)
|
||||
*section = ini_section_add(ini, key, (int)(dot - key));
|
||||
if (*section == INI_NOT_FOUND) return INI_NOT_FOUND;
|
||||
key = dot + 1;
|
||||
}
|
||||
return ini_find_property(ini, *section, key, 0);
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_settings_save(void)
|
||||
{
|
||||
int size;
|
||||
char *text;
|
||||
|
||||
if (!g_ini_dirty || !g_ini || reaktor_capturing()) return;
|
||||
size = ini_save(g_ini, NULL, 0);
|
||||
text = (char *)SDL_malloc((size_t)size);
|
||||
if (!text) return;
|
||||
ini_save(g_ini, text, size);
|
||||
{
|
||||
char *path = settings_path(), *tmp = NULL;
|
||||
|
||||
if (path) SDL_asprintf(&tmp, "%s.new", path);
|
||||
if (!tmp || !SDL_SaveFile(tmp, text, (size_t)size - 1) || !SDL_RenamePath(tmp, path))
|
||||
SDL_Log("settings not saved: %s", SDL_GetError());
|
||||
SDL_free(tmp);
|
||||
SDL_free(path);
|
||||
}
|
||||
settings_persist();
|
||||
SDL_free(text);
|
||||
g_ini_dirty = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
settings_due(App *app, void *user)
|
||||
{
|
||||
(void)app; (void)user;
|
||||
g_save_timer = 0;
|
||||
reaktor_settings_save();
|
||||
}
|
||||
|
||||
static void
|
||||
settings_changed(void)
|
||||
{
|
||||
int ms;
|
||||
reaktor_save mode = reaktor_save_mode(&ms);
|
||||
|
||||
g_ini_dirty = 1;
|
||||
#ifdef __EMSCRIPTEN__
|
||||
if (mode == REAKTOR_SAVE_ON_QUIT) mode = REAKTOR_SAVE_ON_CHANGE;
|
||||
#endif
|
||||
if (mode == REAKTOR_SAVE_ON_CHANGE)
|
||||
reaktor_settings_save();
|
||||
else if (mode == REAKTOR_SAVE_ON_TIMER && !g_save_timer)
|
||||
g_save_timer = reaktor_timer(NULL, ms, 0, settings_due, NULL);
|
||||
}
|
||||
|
||||
const char *
|
||||
reaktor_setting(const char *key)
|
||||
{
|
||||
int section, property = key ? setting_find(key, §ion, 0) : INI_NOT_FOUND;
|
||||
|
||||
return property == INI_NOT_FOUND ? NULL
|
||||
: ini_property_value(g_ini, section, property);
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_setting_set(const char *key, const char *value)
|
||||
{
|
||||
const char *name;
|
||||
int section, property;
|
||||
|
||||
if (!key || !*key || SDL_strpbrk(key, "=[]\n") || (value && SDL_strchr(value, '\n')))
|
||||
return;
|
||||
property = setting_find(key, §ion, value != NULL);
|
||||
name = SDL_strrchr(key, '.') ? SDL_strrchr(key, '.') + 1 : key;
|
||||
if (property != INI_NOT_FOUND && value &&
|
||||
SDL_strcmp(ini_property_value(g_ini, section, property), value) == 0)
|
||||
return;
|
||||
if (!value && property == INI_NOT_FOUND) return;
|
||||
if (!value)
|
||||
ini_property_remove(g_ini, section, property);
|
||||
else if (property != INI_NOT_FOUND)
|
||||
ini_property_value_set(g_ini, section, property, value, 0);
|
||||
else if (section != INI_NOT_FOUND)
|
||||
ini_property_add(g_ini, section, name, 0, value, 0);
|
||||
else
|
||||
return;
|
||||
settings_changed();
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_settings_clear(void)
|
||||
{
|
||||
ini_destroy(g_ini);
|
||||
g_ini = ini_create(NULL);
|
||||
g_ini_dirty = 0;
|
||||
if (g_save_timer) reaktor_timer_stop(g_save_timer);
|
||||
g_save_timer = 0;
|
||||
if (reaktor_capturing()) return;
|
||||
{
|
||||
char *path = settings_path();
|
||||
|
||||
if (path) SDL_RemovePath(path);
|
||||
SDL_free(path);
|
||||
}
|
||||
settings_persist();
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_settings_free(void)
|
||||
{
|
||||
ini_destroy(g_ini);
|
||||
g_ini = NULL;
|
||||
g_ini_dirty = 0;
|
||||
g_save_timer = 0;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_window_restore(App *app)
|
||||
{
|
||||
const char *at = reaktor_setting("window");
|
||||
SDL_Rect r;
|
||||
|
||||
if (at && SDL_sscanf(at, "%d %d %d %d", &r.x, &r.y, &r.w, &r.h) == 4 &&
|
||||
r.w > 0 && r.h > 0) {
|
||||
SDL_SetWindowSize(app->win, r.w, r.h);
|
||||
if (SDL_GetDisplayForRect(&r)) SDL_SetWindowPosition(app->win, r.x, r.y);
|
||||
}
|
||||
if (reaktor_setting("window.maximized")) SDL_MaximizeWindow(app->win);
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_window_remember(App *app)
|
||||
{
|
||||
char at[64];
|
||||
SDL_Rect r;
|
||||
|
||||
if (SDL_GetWindowFlags(app->win) & SDL_WINDOW_MAXIMIZED) {
|
||||
reaktor_setting_set("window.maximized", "1");
|
||||
return;
|
||||
}
|
||||
SDL_GetWindowPosition(app->win, &r.x, &r.y);
|
||||
SDL_GetWindowSize(app->win, &r.w, &r.h);
|
||||
SDL_snprintf(at, sizeof at, "%d %d %d %d", r.x, r.y, r.w, r.h);
|
||||
reaktor_setting_set("window", at);
|
||||
reaktor_setting_set("window.maximized", NULL);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#include "internal.h"
|
||||
|
||||
const char *reaktor_setting(const char *key) { (void)key; return NULL; }
|
||||
void reaktor_setting_set(const char *key, const char *v) { (void)key; (void)v; }
|
||||
void reaktor_settings_save(void) {}
|
||||
void reaktor_settings_clear(void) {}
|
||||
void reaktor_settings_free(void) {}
|
||||
void reaktor_window_restore(App *app) { (void)app; }
|
||||
void reaktor_window_remember(App *app) { (void)app; }
|
||||
@@ -0,0 +1,6 @@
|
||||
#include "internal.h"
|
||||
#include "reaktor/launch.h"
|
||||
|
||||
int reaktor_tray_open(App *app, const reaktor_tray *spec) { (void)app; (void)spec; return 0; }
|
||||
void reaktor_tray_check(App *app, int item, int checked) { (void)app; (void)item; (void)checked; }
|
||||
void reaktor_tray_close(App *app) { (void)app; }
|
||||
@@ -0,0 +1,123 @@
|
||||
#include "internal.h"
|
||||
|
||||
static void
|
||||
undo_free(undo_stack *u, int from)
|
||||
{
|
||||
while (u->n > from) {
|
||||
reaktor_undo_step *s = &u->step[--u->n];
|
||||
|
||||
if (s->free) s->free(s->data);
|
||||
}
|
||||
if (u->top > u->n) u->top = u->n;
|
||||
if (u->saved > u->n) u->saved = -1;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_undo_push(App *app, const reaktor_undo_step *s)
|
||||
{
|
||||
undo_stack *u = &app->undo;
|
||||
unsigned group;
|
||||
|
||||
if (!s || !s->undo || !s->redo) return;
|
||||
undo_free(u, u->top);
|
||||
if (u->n == u->cap) {
|
||||
int cap = u->cap ? u->cap * 2 : 32;
|
||||
reaktor_undo_step *step = (reaktor_undo_step *)SDL_realloc(u->step, (size_t)cap * sizeof *step);
|
||||
unsigned *grp = (unsigned *)SDL_realloc(u->group, (size_t)cap * sizeof *grp);
|
||||
|
||||
if (step) u->step = step;
|
||||
if (grp) u->group = grp;
|
||||
if (!step || !grp) {
|
||||
if (s->free) s->free(s->data);
|
||||
return;
|
||||
}
|
||||
u->cap = cap;
|
||||
}
|
||||
if (u->depth)
|
||||
group = u->open;
|
||||
else if (s->merge && u->n && u->step[u->n - 1].merge == s->merge && u->saved != u->n)
|
||||
group = u->group[u->n - 1];
|
||||
else
|
||||
group = ++u->next;
|
||||
u->step[u->n] = *s;
|
||||
u->group[u->n] = group;
|
||||
u->top = ++u->n;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_undo_group(App *app, int begin)
|
||||
{
|
||||
undo_stack *u = &app->undo;
|
||||
|
||||
if (begin && u->depth++ == 0) u->open = ++u->next;
|
||||
if (!begin && u->depth > 0) u->depth--;
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_undo(App *app)
|
||||
{
|
||||
undo_stack *u = &app->undo;
|
||||
unsigned group;
|
||||
|
||||
if (u->top == 0) return 0;
|
||||
group = u->group[u->top - 1];
|
||||
while (u->top > 0 && u->group[u->top - 1] == group) {
|
||||
reaktor_undo_step *s = &u->step[--u->top];
|
||||
|
||||
s->undo(s->data);
|
||||
}
|
||||
app->dirty = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_redo(App *app)
|
||||
{
|
||||
undo_stack *u = &app->undo;
|
||||
unsigned group;
|
||||
|
||||
if (u->top == u->n) return 0;
|
||||
group = u->group[u->top];
|
||||
while (u->top < u->n && u->group[u->top] == group) {
|
||||
reaktor_undo_step *s = &u->step[u->top++];
|
||||
|
||||
s->redo(s->data);
|
||||
}
|
||||
app->dirty = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char *
|
||||
reaktor_undo_label(App *app)
|
||||
{
|
||||
return app->undo.top > 0 ? app->undo.step[app->undo.top - 1].label : NULL;
|
||||
}
|
||||
|
||||
const char *
|
||||
reaktor_redo_label(App *app)
|
||||
{
|
||||
return app->undo.top < app->undo.n ? app->undo.step[app->undo.top].label : NULL;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_undo_saved(App *app)
|
||||
{
|
||||
app->undo.saved = app->undo.top;
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_undo_dirty(App *app)
|
||||
{
|
||||
return app->undo.top != app->undo.saved;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_undo_clear(App *app)
|
||||
{
|
||||
undo_stack *u = &app->undo;
|
||||
|
||||
undo_free(u, 0);
|
||||
SDL_free(u->step);
|
||||
SDL_free(u->group);
|
||||
SDL_zerop(u);
|
||||
}
|
||||
@@ -82,6 +82,7 @@ teardown(App *a)
|
||||
if (a->win) SDL_SetWindowModal(a->win, false);
|
||||
reaktor_app_input_free(a);
|
||||
field_undo_clear(a);
|
||||
reaktor_undo_clear(a);
|
||||
reaktor_layout_free(&a->lay);
|
||||
if (a->ren) img_cache_free(a);
|
||||
if (a->ctx) nk_sdl_shutdown(a->ctx);
|
||||
@@ -119,11 +120,20 @@ shut(int i, int tell)
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_window_open(App *app, const reaktor_window *spec)
|
||||
/* Logical units of the main window to its window coordinates. */
|
||||
static float
|
||||
to_points(const App *m)
|
||||
{
|
||||
float d = SDL_GetWindowPixelDensity(m->win);
|
||||
|
||||
return reaktor_scale() / (d > 0.0f ? d : 1.0f);
|
||||
}
|
||||
|
||||
static int
|
||||
open_window(const reaktor_window *spec, const struct nk_rect *popup)
|
||||
{
|
||||
#ifdef __EMSCRIPTEN__
|
||||
(void)app; (void)spec;
|
||||
(void)spec; (void)popup;
|
||||
SDL_Log("a page opens no windows of its own");
|
||||
return 0;
|
||||
#else
|
||||
@@ -131,12 +141,19 @@ reaktor_window_open(App *app, const reaktor_window *spec)
|
||||
rwin *w;
|
||||
int i;
|
||||
|
||||
(void)app;
|
||||
if (!m || !spec || !spec->page || g_win_n == WINDOW_MAX) return 0;
|
||||
if (!(a = (App *)SDL_calloc(1, sizeof *a))) return 0;
|
||||
a->secondary = 1;
|
||||
a->hot_last = -1;
|
||||
a->queue.moved_ok = 1;
|
||||
if (popup) {
|
||||
float k = to_points(m);
|
||||
|
||||
a->win = SDL_CreatePopupWindow(m->win, (int)(popup->x * k), (int)(popup->y * k),
|
||||
(int)(popup->w * k + 0.5f), (int)(popup->h * k + 0.5f),
|
||||
SDL_WINDOW_POPUP_MENU | SDL_WINDOW_NOT_FOCUSABLE |
|
||||
SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_HIDDEN);
|
||||
} else
|
||||
a->win = SDL_CreateWindow(spec->window.title ? spec->window.title : "",
|
||||
reaktor_px(spec->window.w > 0 ? (float)spec->window.w : 420.0f),
|
||||
reaktor_px(spec->window.h > 0 ? (float)spec->window.h : 280.0f),
|
||||
@@ -181,7 +198,7 @@ reaktor_window_open(App *app, const reaktor_window *spec)
|
||||
apply_render_scale(a);
|
||||
rebuild_font(a);
|
||||
apply_widget_style(a);
|
||||
{
|
||||
if (!popup) {
|
||||
const char *icon = reaktor_asset_name(&spec->window.icon,
|
||||
"app/window-icon.svg");
|
||||
|
||||
@@ -200,12 +217,55 @@ reaktor_window_open(App *app, const reaktor_window *spec)
|
||||
w->app = a;
|
||||
w->spec = *spec;
|
||||
w->title = SDL_strdup(spec->window.title ? spec->window.title : "");
|
||||
SDL_ShowWindow(a->win);
|
||||
if (!spec->window.hidden) SDL_ShowWindow(a->win);
|
||||
reaktor_wake(a);
|
||||
return w->id;
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_window_open(App *app, const reaktor_window *spec)
|
||||
{
|
||||
(void)app;
|
||||
return open_window(spec, NULL);
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_window_spawn(const reaktor_window *spec, const struct nk_rect *popup)
|
||||
{
|
||||
return open_window(spec, popup);
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_window_move(int id, struct nk_rect r)
|
||||
{
|
||||
rwin *w = by_id(id);
|
||||
App *m = reaktor_main_app();
|
||||
float k;
|
||||
|
||||
if (!w || !m) return;
|
||||
k = to_points(m);
|
||||
SDL_SetWindowPosition(w->app->win, (int)(r.x * k), (int)(r.y * k));
|
||||
SDL_SetWindowSize(w->app->win, (int)(r.w * k + 0.5f), (int)(r.h * k + 0.5f));
|
||||
w->app->dirty = 1;
|
||||
}
|
||||
|
||||
App *
|
||||
reaktor_window_app(int id)
|
||||
{
|
||||
rwin *w = by_id(id);
|
||||
|
||||
return w ? w->app : NULL;
|
||||
}
|
||||
|
||||
float
|
||||
reaktor_window_points(void)
|
||||
{
|
||||
App *m = reaktor_main_app();
|
||||
|
||||
return m ? to_points(m) : 1.0f;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_window_close(App *app, int id)
|
||||
{
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "reaktor/reaktor.h"
|
||||
#include "reaktor/main.h"
|
||||
|
||||
#define TEXT_CAP 65536
|
||||
|
||||
static struct {
|
||||
char text[TEXT_CAP];
|
||||
int len;
|
||||
char *text;
|
||||
int len, cap;
|
||||
char find[128];
|
||||
int find_len, find_open, find_at;
|
||||
char path[520];
|
||||
unsigned saved_hash;
|
||||
int saved_len;
|
||||
@@ -15,7 +16,6 @@ static struct {
|
||||
int seeded;
|
||||
} g;
|
||||
|
||||
#define MENUBAR_H 30.0f
|
||||
#define STATUS_H 26.0f
|
||||
|
||||
static unsigned
|
||||
@@ -48,9 +48,23 @@ shown_name(void)
|
||||
return slash ? slash + 1 : g.path;
|
||||
}
|
||||
|
||||
static int
|
||||
room(int n)
|
||||
{
|
||||
char *more;
|
||||
|
||||
if (n < g.cap) return 1;
|
||||
more = (char *)SDL_realloc(g.text, (size_t)n + 256);
|
||||
if (!more) return 0;
|
||||
g.text = more;
|
||||
g.cap = n + 256;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
new_file(void)
|
||||
{
|
||||
if (!room(0)) return;
|
||||
g.text[0] = '\0';
|
||||
g.len = 0;
|
||||
g.path[0] = '\0';
|
||||
@@ -69,10 +83,8 @@ load(const char *path)
|
||||
SDL_snprintf(g.status, sizeof(g.status), "Could not read %s", path);
|
||||
return;
|
||||
}
|
||||
if (n >= TEXT_CAP) {
|
||||
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);
|
||||
if (!room((int)n)) {
|
||||
SDL_snprintf(g.status, sizeof(g.status), "%s does not fit in memory", path);
|
||||
SDL_free(body);
|
||||
return;
|
||||
}
|
||||
@@ -145,12 +157,88 @@ save(App *app)
|
||||
SDL_snprintf(g.status, sizeof(g.status), "Saved %s", shown_name());
|
||||
}
|
||||
|
||||
static void
|
||||
menu_cursor(App *app, struct reaktor_context *ctx)
|
||||
#define PAGE_LINES 60
|
||||
|
||||
static int
|
||||
line_count(void)
|
||||
{
|
||||
reaktor_hot_top(app, reaktor_window_get_bounds(ctx), 1, 0);
|
||||
int i, n = 1;
|
||||
|
||||
for (i = 0; i < g.len; i++) n += g.text[i] == '\n';
|
||||
return n;
|
||||
}
|
||||
|
||||
/* One printed page: its sixty lines on white, as plain labels. */
|
||||
static void
|
||||
print_page(App *app, struct reaktor_context *ctx, int index, int w, int h, void *user)
|
||||
{
|
||||
const char *p = g.text, *end = g.text + g.len;
|
||||
char line[256];
|
||||
int skip = index * PAGE_LINES, k;
|
||||
|
||||
(void)app; (void)user;
|
||||
reaktor_fill_rect(reaktor_window_get_canvas(ctx), reaktor_rect(0, 0, (float)w, (float)h),
|
||||
0.0f, reaktor_rgb(255, 255, 255));
|
||||
while (skip > 0 && p < end) if (*p++ == '\n') skip--;
|
||||
REAKTOR_FREE(.w = (float)w, .h = (float)h) {
|
||||
REAKTOR_COLUMN(.w = (float)w - 96.0f, .ml = 48.0f, .mt = 40.0f) {
|
||||
for (k = 0; k < PAGE_LINES && p < end; k++) {
|
||||
const char *nl = memchr(p, '\n', (size_t)(end - p));
|
||||
int n = (int)((nl ? nl : end) - p);
|
||||
|
||||
SDL_snprintf(line, sizeof line, "%.*s", n < 255 ? n : 255, p);
|
||||
reaktor_label(&(reaktor_label_spec){ .text = line, .silent = 1,
|
||||
.color = "#000000",
|
||||
.box = { .h = 12.5f } });
|
||||
p += n + (nl != NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
printed(App *app, int ok, void *user)
|
||||
{
|
||||
(void)app; (void)user;
|
||||
SDL_strlcpy(g.status, ok ? "Printed" : "Not printed", sizeof(g.status));
|
||||
}
|
||||
|
||||
static reaktor_print_spec
|
||||
print_spec(void)
|
||||
{
|
||||
return (reaktor_print_spec){ .title = shown_name(),
|
||||
.pages = (line_count() + PAGE_LINES - 1) / PAGE_LINES,
|
||||
.page = print_page, .done = printed };
|
||||
}
|
||||
|
||||
static void
|
||||
exported(App *app, const char *const *paths, int count, void *user)
|
||||
{
|
||||
reaktor_print_spec s = print_spec();
|
||||
|
||||
(void)user;
|
||||
if (count && reaktor_print_pdf(app, paths[0], &s))
|
||||
SDL_strlcpy(g.status, "Writing the PDF...", sizeof(g.status));
|
||||
}
|
||||
|
||||
static void
|
||||
find_next(App *app)
|
||||
{
|
||||
int i, k, line = 1;
|
||||
|
||||
g.find[g.find_len] = '\0';
|
||||
if (!g.find_len) return;
|
||||
for (k = 0; k < 2; k++, g.find_at = 0)
|
||||
for (i = g.find_at; i + g.find_len <= g.len; i++)
|
||||
if (SDL_memcmp(g.text + i, g.find, (size_t)g.find_len) == 0) {
|
||||
g.find_at = i + g.find_len;
|
||||
reaktor_field_select(app, g.text, i, g.find_at);
|
||||
while (--i >= 0) line += g.text[i] == '\n';
|
||||
SDL_snprintf(g.status, sizeof(g.status), "Found on line %d", line);
|
||||
return;
|
||||
}
|
||||
SDL_snprintf(g.status, sizeof(g.status), "\"%s\" is not there", g.find);
|
||||
}
|
||||
|
||||
static void
|
||||
page_shell(App *app, struct reaktor_context *ctx, int win_w, int win_h)
|
||||
@@ -165,71 +253,82 @@ page_shell(App *app, struct reaktor_context *ctx, int win_w, int win_h)
|
||||
g.seeded = 1;
|
||||
}
|
||||
|
||||
reaktor_menu_style_push(ctx);
|
||||
reaktor_menubar_begin(ctx);
|
||||
|
||||
{
|
||||
struct reaktor_style_item clear = reaktor_style_item_color(reaktor_rgba(0, 0, 0, 0));
|
||||
reaktor_style_push_style_item(ctx, &ctx->style.menu_button.normal,
|
||||
clear);
|
||||
reaktor_style_push_style_item(ctx, &ctx->style.menu_button.hover,
|
||||
clear);
|
||||
reaktor_style_push_style_item(ctx, &ctx->style.menu_button.active,
|
||||
clear);
|
||||
}
|
||||
|
||||
reaktor_layout_row_begin(ctx, REAKTOR_STATIC, MENUBAR_H, 2);
|
||||
|
||||
reaktor_layout_row_push(ctx, 60.0f);
|
||||
if (reaktor_menu_begin_label(ctx, "File", REAKTOR_TEXT_CENTERED,
|
||||
reaktor_vec2(200.0f,
|
||||
reaktor_menu_height(4)))) {
|
||||
reaktor_menu_edge(app, ctx);
|
||||
menu_cursor(app, ctx);
|
||||
reaktor_layout_row_dynamic(ctx, REAKTOR_MENU_ROW, 1);
|
||||
if (reaktor_menu_item(app, ctx, "New", "Ctrl+N", 0))
|
||||
new_file();
|
||||
if (reaktor_menu_item(app, ctx, "Open...", "Ctrl+O", 0))
|
||||
ask_file(app, REAKTOR_FILE_OPEN);
|
||||
if (reaktor_menu_item(app, ctx, "Save", "Ctrl+S", 0))
|
||||
save(app);
|
||||
if (reaktor_menu_item(app, ctx, "Quit", "Ctrl+Q", 0))
|
||||
reaktor_request_quit(app);
|
||||
reaktor_menu_end(ctx);
|
||||
}
|
||||
|
||||
reaktor_layout_row_push(ctx, 60.0f);
|
||||
if (reaktor_menu_begin_label(ctx, "Help", REAKTOR_TEXT_CENTERED,
|
||||
reaktor_vec2(200.0f,
|
||||
reaktor_menu_height(2)))) {
|
||||
reaktor_menu_edge(app, ctx);
|
||||
menu_cursor(app, ctx);
|
||||
reaktor_layout_row_dynamic(ctx, REAKTOR_MENU_ROW, 1);
|
||||
if (reaktor_menu_item(app, ctx, "Shortcuts", "Ctrl+K", 0))
|
||||
SDL_strlcpy(g.status,
|
||||
"Ctrl+N new, Ctrl+O open, Ctrl+S save, Ctrl+Q quit",
|
||||
sizeof(g.status));
|
||||
if (reaktor_menu_item(app, ctx, "About", NULL, 0))
|
||||
SDL_strlcpy(g.status,
|
||||
"A text editor in one file, on Reaktor",
|
||||
sizeof(g.status));
|
||||
reaktor_menu_end(ctx);
|
||||
}
|
||||
|
||||
reaktor_layout_row_end(ctx);
|
||||
reaktor_menubar_end(ctx);
|
||||
reaktor_style_pop_style_item(ctx);
|
||||
reaktor_style_pop_style_item(ctx);
|
||||
reaktor_style_pop_style_item(ctx);
|
||||
reaktor_menu_style_pop(ctx);
|
||||
|
||||
REAKTOR_COLUMN(.h = reaktor_window_get_content_region_size(ctx).y,
|
||||
.gap = 1.0f) {
|
||||
{
|
||||
static const reaktor_menu_entry file[] = {
|
||||
{ .label = "New", .keys = "Ctrl+N" },
|
||||
{ .label = "Open...", .keys = "Ctrl+O" },
|
||||
{ .label = "Save", .keys = "Ctrl+S" },
|
||||
{ NULL },
|
||||
{ .label = "Print...", .keys = "Ctrl+P" },
|
||||
{ .label = "Export as PDF..." },
|
||||
{ NULL },
|
||||
{ .label = "Quit", .keys = "Ctrl+Q" }
|
||||
};
|
||||
static const reaktor_menu_entry edit[] = {
|
||||
{ .label = "Find...", .keys = "Ctrl+F" },
|
||||
{ .label = "Find next", .keys = "F3" }
|
||||
};
|
||||
static const reaktor_menu_entry help[] = {
|
||||
{ .label = "Shortcuts", .keys = "Ctrl+K" },
|
||||
{ .label = "About" }
|
||||
};
|
||||
static const reaktor_menu menus[3] = {
|
||||
{ "File", file, 8 }, { "Edit", edit, 2 }, { "Help", help, 2 }
|
||||
};
|
||||
int m = -1, i = -1;
|
||||
|
||||
if (reaktor_menubar(&(reaktor_menubar_spec){
|
||||
.menus = menus, .count = 3,
|
||||
.box = { .ml = 4.0f, .mt = 6.0f, .mb = 2.0f },
|
||||
.picked_menu = &m, .picked_item = &i })) {
|
||||
if (m == 0 && i == 0) new_file();
|
||||
if (m == 0 && i == 1) ask_file(app, REAKTOR_FILE_OPEN);
|
||||
if (m == 0 && i == 2) save(app);
|
||||
if (m == 0 && i == 4) {
|
||||
reaktor_print_spec ps = print_spec();
|
||||
|
||||
reaktor_print(app, &ps);
|
||||
}
|
||||
if (m == 0 && i == 5 &&
|
||||
!reaktor_file_dialog_open(app, &(reaktor_file_dialog){
|
||||
.kind = REAKTOR_FILE_SAVE, .chosen = exported,
|
||||
.filters = (const reaktor_file_filter[]){ { "PDF", "pdf" } },
|
||||
.filter_count = 1 }))
|
||||
SDL_strlcpy(g.status, "A dialog is already open", sizeof(g.status));
|
||||
if (m == 0 && i == 7) reaktor_request_quit(app);
|
||||
if (m == 1 && i == 0) g.find_open = 1;
|
||||
if (m == 1 && i == 1) find_next(app);
|
||||
if (m == 2 && i == 0)
|
||||
SDL_strlcpy(g.status,
|
||||
"Ctrl+N new, Ctrl+O open, Ctrl+S save, Ctrl+F find, F3 next, Ctrl+Q quit",
|
||||
sizeof(g.status));
|
||||
if (m == 2 && i == 1)
|
||||
SDL_strlcpy(g.status, "A text editor in one file, on Reaktor",
|
||||
sizeof(g.status));
|
||||
}
|
||||
}
|
||||
|
||||
if (g.find_open)
|
||||
REAKTOR_ROW(.h = 30.0f, .gap = 6.0f, .ml = 6.0f, .mr = 6.0f, .mt = 4.0f,
|
||||
.flags = REAKTOR_LAY_FILL_X) {
|
||||
reaktor_field(&(reaktor_field_spec){
|
||||
.buf = g.find, .len = &g.find_len, .cap = (int)sizeof g.find,
|
||||
.hint = "Find", .name = "Find",
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X } });
|
||||
if (reaktor_button(&(reaktor_button_spec){ .label = "Next", .keys = "F3",
|
||||
.box = { .w = 80.0f } }))
|
||||
find_next(app);
|
||||
if (reaktor_button(&(reaktor_button_spec){ .label = "Close",
|
||||
.box = { .w = 80.0f } }))
|
||||
g.find_open = 0;
|
||||
}
|
||||
|
||||
reaktor_field(&(reaktor_field_spec){
|
||||
.buf = g.text, .len = &g.len, .cap = TEXT_CAP,
|
||||
.name = "Document", .multiline = 1,
|
||||
.box = { .ml = 6.0f, .mr = 6.0f, .mt = 5.0f, .mb = 3.0f,
|
||||
.heap = &g.text, .heap_cap = &g.cap, .len = &g.len,
|
||||
.name = "Document", .multiline = 1, .line_numbers = 1,
|
||||
.box = { .ml = 6.0f, .mr = 6.0f, .mt = 2.0f, .mb = 3.0f,
|
||||
.flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y } });
|
||||
|
||||
REAKTOR_ROW(.h = STATUS_H, .flags = REAKTOR_LAY_FILL_X) {
|
||||
@@ -258,13 +357,21 @@ sample_key(App *app, const SDL_Event *e)
|
||||
return 1;
|
||||
}
|
||||
if (reaktor_chord(e, REAKTOR_MOD_CTRL, SDLK_S)) { save(app); return 1; }
|
||||
if (reaktor_chord(e, REAKTOR_MOD_CTRL, SDLK_F)) { g.find_open = 1; return 1; }
|
||||
if (reaktor_chord(e, REAKTOR_MOD_CTRL, SDLK_P)) {
|
||||
reaktor_print_spec ps = print_spec();
|
||||
|
||||
reaktor_print(app, &ps);
|
||||
return 1;
|
||||
}
|
||||
if (reaktor_chord(e, 0, SDLK_F3)) { find_next(app); return 1; }
|
||||
if (reaktor_chord(e, REAKTOR_MOD_CTRL, SDLK_Q)) {
|
||||
reaktor_request_quit(app);
|
||||
return 1;
|
||||
}
|
||||
if (reaktor_chord(e, REAKTOR_MOD_CTRL, SDLK_K)) {
|
||||
SDL_strlcpy(g.status,
|
||||
"Ctrl+N new, Ctrl+O open, Ctrl+S save, Ctrl+Q quit",
|
||||
"Ctrl+N new, Ctrl+O open, Ctrl+S save, Ctrl+F find, F3 next, Ctrl+Q quit",
|
||||
sizeof(g.status));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ page_buttons(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
|
||||
section(app, ctx, "Buttons",
|
||||
"The fill, border, radius, padding and font all come from "
|
||||
"tiny.css's `button` rule; the hover color is its "
|
||||
"Water.css's `button` rule; the hover color is its "
|
||||
"--button-hover. The accent is --links, which is the only thing "
|
||||
"in a classless stylesheet that means \"this is the one to "
|
||||
"press\".");
|
||||
@@ -92,6 +92,36 @@ page_buttons(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
}
|
||||
}
|
||||
|
||||
section(app, ctx, "Flat icons",
|
||||
"An icon with no label and .flat set is a toolbar button: no "
|
||||
"fill and no edge until the pointer is over it, then the sheet's "
|
||||
"button:hover. The icon takes the text color, or the accent's "
|
||||
"with .accent, which is how a tool shows it is on. Its .name is "
|
||||
"what a reader hears, and .tooltip what the pointer shows.");
|
||||
api(app, ctx, "reaktor_button / .icon / .flat");
|
||||
|
||||
{
|
||||
static const struct { const char *icon, *name; } tools[8] = {
|
||||
{ "cut-outline", "Cut" }, { "copy-outline", "Copy" },
|
||||
{ "clipboard-outline", "Paste" }, { "arrow-undo-outline", "Undo" },
|
||||
{ "arrow-redo-outline", "Redo" }, { "search-outline", "Find" },
|
||||
{ "locate-outline", "Pick" }, { "trash-outline", "Delete" }
|
||||
};
|
||||
static int on = 6;
|
||||
|
||||
REAKTOR_ROW(.h = 32.0f, .gap = 2.0f) {
|
||||
for (i = 0; i < 8; i++)
|
||||
if (reaktor_button(&(reaktor_button_spec){
|
||||
.icon = tools[i].icon, .name = tools[i].name,
|
||||
.tooltip = tools[i].name, .flat = 1,
|
||||
.accent = (unsigned char)(i == on),
|
||||
.box = { .w = 32.0f, .h = 32.0f } })) {
|
||||
on = i;
|
||||
s->presses++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
section(app, ctx, "Color, image, repeat and disabled",
|
||||
"reaktor_button_color paints a swatch and nothing else. A repeater "
|
||||
"fires for as long as it is held rather than once on release. "
|
||||
|
||||
@@ -49,6 +49,25 @@ page_diagnostics(App *app, struct reaktor_context *ctx, showcase_state *st)
|
||||
(void)st;
|
||||
reaktor_diagnostics(app, &d);
|
||||
|
||||
section(app, ctx, "Inspector",
|
||||
"The widget tree, a widget's box and style, the last frame and "
|
||||
"the log, in a window of its own. Ctrl+Shift+I opens it from any "
|
||||
"page; Pick, then a click here, finds the widget under the "
|
||||
"pointer.");
|
||||
api(app, ctx, ".inspector = { .attach = 1 } / reaktor_inspector_open");
|
||||
REAKTOR_ROW(.h = ROW, .gap = ctx->style.window.spacing.x) {
|
||||
int shown = reaktor_inspector_shown(app);
|
||||
|
||||
if (reaktor_button(&(reaktor_button_spec){
|
||||
.label = shown ? "Close the Inspector" : "Open the Inspector",
|
||||
.name = "Inspector", .keys = "Ctrl+Shift+I",
|
||||
.box = { .w = 240.0f } })) {
|
||||
if (shown) reaktor_inspector_close(app);
|
||||
else reaktor_inspector_open(app);
|
||||
}
|
||||
reaktor_soak();
|
||||
}
|
||||
|
||||
section(app, ctx, "Rendering",
|
||||
"Which backend SDL settled on. It is the software rasterizer "
|
||||
"on every platform: this draws nothing at rest, so a GPU buys it "
|
||||
|
||||
@@ -4,7 +4,7 @@ static const char *const g_grid[7][3] = {
|
||||
{ "SDL3", "Zlib", "window, input, renderer, main loop" },
|
||||
{ "Nuklear", "MIT/PD", "the widgets and their layout" },
|
||||
{ "LCUI css", "MIT", "parses the stylesheet, computes values" },
|
||||
{ "tiny.css", "MIT", "the stylesheet itself" },
|
||||
{ "Water.css", "MIT", "the stylesheet itself" },
|
||||
{ "plutosvg", "MIT", "rasterises the icons" },
|
||||
{ "Ionicons", "MIT", "the icons" },
|
||||
{ "Aileron", "CC0", "the typeface" }
|
||||
@@ -28,7 +28,7 @@ section_grid(App *app, struct reaktor_context *ctx)
|
||||
"The only widget on these pages that Nuklear does not have - and "
|
||||
"one whose colors come from the stylesheet's own table rules: "
|
||||
"thead, th, td and the --table-bg stripes are read straight out of "
|
||||
"tiny.css. Only the rows on screen are drawn, so a list of a "
|
||||
"Water.css. Only the rows on screen are drawn, so a list of a "
|
||||
"million costs what a list of eight does; a row is chosen by a "
|
||||
"click or from the keyboard.");
|
||||
api(app, ctx, "reaktor_list");
|
||||
@@ -38,6 +38,79 @@ section_grid(App *app, struct reaktor_context *ctx)
|
||||
.column_count = 3, .cell = grid_cell, .selected = &chosen });
|
||||
}
|
||||
|
||||
typedef struct file_node {
|
||||
const char *label, *icon;
|
||||
int parent;
|
||||
} file_node;
|
||||
|
||||
static const file_node g_files[] = {
|
||||
{ "Documents", "folder-outline", -1 },
|
||||
{ "Reports", "folder-outline", 0 },
|
||||
{ "2025.pdf", "document-text-outline", 1 },
|
||||
{ "2026.pdf", "document-text-outline", 1 },
|
||||
{ "Notes.txt", "document-outline", 0 },
|
||||
{ "Pictures", "folder-outline", -1 },
|
||||
{ "Holiday", "folder-outline", 5 },
|
||||
{ "Beach.jpg", "image-outline", 6 },
|
||||
{ "Harbor.jpg", "image-outline", 6 },
|
||||
{ "Music", "folder-outline", -1 },
|
||||
{ "Overture.ogg", "musical-notes-outline", 9 }
|
||||
};
|
||||
|
||||
static int file_parent(int n, void *u) { (void)u; return g_files[n].parent; }
|
||||
static const char *file_label(int n, void *u) { (void)u; return g_files[n].label; }
|
||||
static const char *file_icon(int n, void *u) { (void)u; return g_files[n].icon; }
|
||||
|
||||
/* Two lists of task numbers; a drop moves one from a list to a place in another. */
|
||||
static const char *const g_tasks[] = {
|
||||
"Write the release notes", "Check the BSD builds", "Answer the issue on fonts",
|
||||
"Draw the new icon", "Measure the web build", "Update the screenshots"
|
||||
};
|
||||
static int g_lane[2][6] = { { 0, 1, 2, 3 }, { 4, 5 } };
|
||||
static int g_lane_n[2] = { 4, 2 };
|
||||
|
||||
static const char *
|
||||
lane_cell(int row, int column, void *user)
|
||||
{
|
||||
(void)column;
|
||||
return g_tasks[g_lane[(intptr_t)user][row]];
|
||||
}
|
||||
|
||||
static App *g_lane_app;
|
||||
|
||||
typedef struct lane_move { int src, from, dst, to; } lane_move;
|
||||
|
||||
static void
|
||||
lane_shift(int src, int from, int dst, int to)
|
||||
{
|
||||
int task = g_lane[src][from], i;
|
||||
|
||||
for (i = from; i < g_lane_n[src] - 1; i++) g_lane[src][i] = g_lane[src][i + 1];
|
||||
g_lane_n[src]--;
|
||||
for (i = g_lane_n[dst]; i > to; i--) g_lane[dst][i] = g_lane[dst][i - 1];
|
||||
g_lane[dst][to] = task;
|
||||
g_lane_n[dst]++;
|
||||
}
|
||||
|
||||
static void lane_undo(void *d) { lane_move *m = d; lane_shift(m->dst, m->to, m->src, m->from); }
|
||||
static void lane_redo(void *d) { lane_move *m = d; lane_shift(m->src, m->from, m->dst, m->to); }
|
||||
|
||||
static void
|
||||
lane_dropped(const char *from, int item, int at, void *user)
|
||||
{
|
||||
lane_move *m = (lane_move *)SDL_malloc(sizeof *m);
|
||||
|
||||
if (!m) return;
|
||||
m->src = SDL_strcmp(from, "To do") == 0 ? 0 : 1;
|
||||
m->from = item;
|
||||
m->dst = (int)(intptr_t)user;
|
||||
m->to = m->src == m->dst && at > item ? at - 1 : at;
|
||||
lane_redo(m);
|
||||
reaktor_undo_push(g_lane_app, &(reaktor_undo_step){
|
||||
.label = "Move a task", .undo = lane_undo, .redo = lane_redo, .free = SDL_free,
|
||||
.data = m });
|
||||
}
|
||||
|
||||
void
|
||||
page_display(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
{
|
||||
@@ -172,71 +245,54 @@ page_display(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
section_grid(app, ctx);
|
||||
|
||||
section(app, ctx, "Trees and lists",
|
||||
"A tree remembers whether it is open between frames without the "
|
||||
"caller holding a bool, by hashing the source line it was written "
|
||||
"on. reaktor_tree_element makes the header itself selectable, drawn "
|
||||
"through reaktor_style_selectable - so an unselected one shows "
|
||||
"nothing but its label, and a selected one fills with the accent. A "
|
||||
"list view emits only the rows actually on screen, so its cost does "
|
||||
"not grow with the data.");
|
||||
api(app, ctx, "reaktor_tree_push / reaktor_tree_element_push / "
|
||||
"reaktor_list_view_begin");
|
||||
"A tree is its nodes in depth-first order, each naming its parent; "
|
||||
"the open flags and the selection are the caller's. Only the rows "
|
||||
"on screen are drawn. Up and Down move between rows, Right opens a "
|
||||
"branch or steps into it, Left closes it or steps out to the parent. "
|
||||
"Below it, a list view by hand emits only the rows on screen too, so "
|
||||
"its cost does not grow with the data.");
|
||||
api(app, ctx, "reaktor_tree / reaktor_list_view_begin");
|
||||
|
||||
{
|
||||
struct reaktor_rect hb = tree_header_bounds(ctx);
|
||||
int open;
|
||||
REAKTOR_COLUMN(.name = "Files", .flags = REAKTOR_LAY_FILL_X) {
|
||||
reaktor_tree(&(reaktor_tree_spec){
|
||||
.name = "Files", .count = (int)SDL_arraysize(g_files),
|
||||
.parent = file_parent, .label = file_label, .icon = file_icon,
|
||||
.open = s->tree_open, .selected = &s->tree_sel,
|
||||
.box = { .h = 200.0f, .flags = REAKTOR_LAY_FILL_X } });
|
||||
}
|
||||
|
||||
hot(app, ctx, REAKTOR_A11Y_NONE, NULL, 0);
|
||||
open = reaktor_tree_push(ctx, REAKTOR_TREE_TAB, "A tab-style tree",
|
||||
REAKTOR_MAXIMIZED);
|
||||
tree_chevron(app, ctx, hb, open);
|
||||
reaktor_note_push(app, REAKTOR_A11Y_TREEITEM, "A tab-style tree", NULL,
|
||||
open ? REAKTOR_A11Y_EXPANDED : 0u, hb);
|
||||
if (open) {
|
||||
reaktor_layout_row_dynamic(ctx, ROW_SMALL, 1);
|
||||
reaktor_text_label(ctx, "Its children are indented under it.",
|
||||
REAKTOR_TEXT_LEFT);
|
||||
section(app, ctx, "Drag and drop",
|
||||
"A list with a .drag kind lets its rows be dragged; a list of the same "
|
||||
"kind shows where one would land and hands the drop to .dropped, with "
|
||||
"the list it came from. Reordering is a drop on the same list. Each "
|
||||
"move here is a step on the window's undo stack: Ctrl+Z and Ctrl+Y, or "
|
||||
"the buttons, which name the step they would undo.");
|
||||
api(app, ctx, "reaktor_list .drag / .dropped / reaktor_undo_push");
|
||||
g_lane_app = app;
|
||||
|
||||
hb = tree_header_bounds(ctx);
|
||||
hot(app, ctx, REAKTOR_A11Y_NONE, NULL, 0);
|
||||
open = reaktor_tree_push(ctx, REAKTOR_TREE_NODE, "A node inside it",
|
||||
REAKTOR_MINIMIZED);
|
||||
tree_chevron(app, ctx, hb, open);
|
||||
reaktor_note_push(app, REAKTOR_A11Y_TREEITEM, "A node inside it",
|
||||
NULL, open ? REAKTOR_A11Y_EXPANDED : 0u, hb);
|
||||
if (open) {
|
||||
reaktor_layout_row_dynamic(ctx, ROW_SMALL, 1);
|
||||
reaktor_text_label(ctx, "Nesting is unlimited.",
|
||||
REAKTOR_TEXT_LEFT);
|
||||
reaktor_tree_pop(ctx);
|
||||
}
|
||||
reaktor_note_pop(app);
|
||||
REAKTOR_ROW(.h = 200.0f, .gap = ctx->style.window.spacing.x, .flags = REAKTOR_LAY_FILL_X) {
|
||||
reaktor_list(&(reaktor_list_spec){
|
||||
.name = "To do", .count = g_lane_n[0], .cell = lane_cell, .user = (void *)0,
|
||||
.drag = "task", .dropped = lane_dropped, .columns = (const char *const[]){ "To do" },
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y } });
|
||||
reaktor_list(&(reaktor_list_spec){
|
||||
.name = "Done", .count = g_lane_n[1], .cell = lane_cell, .user = (void *)1,
|
||||
.drag = "task", .dropped = lane_dropped, .columns = (const char *const[]){ "Done" },
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y } });
|
||||
}
|
||||
REAKTOR_ROW(.h = ROW, .gap = ctx->style.window.spacing.x) {
|
||||
char undo[48], redo[48];
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
char lab[32];
|
||||
SDL_snprintf(lab, sizeof(lab), "Selectable branch %d", i + 1);
|
||||
hb = tree_header_bounds(ctx);
|
||||
hot(app, ctx, REAKTOR_A11Y_NONE, NULL, 0);
|
||||
open = reaktor_tree_element_push(ctx, REAKTOR_TREE_NODE, lab,
|
||||
REAKTOR_MINIMIZED,
|
||||
&s->tree_leaf[i]);
|
||||
tree_chevron(app, ctx, hb, open);
|
||||
reaktor_note_push(app, REAKTOR_A11Y_TREEITEM, lab, NULL,
|
||||
(open ? REAKTOR_A11Y_EXPANDED : 0u) |
|
||||
(s->tree_leaf[i] ? REAKTOR_A11Y_CHECKED
|
||||
: 0u),
|
||||
hb);
|
||||
if (open) {
|
||||
reaktor_layout_row_dynamic(ctx, ROW_SMALL, 1);
|
||||
reaktor_text_label(ctx, "with a checkbox in the header",
|
||||
REAKTOR_TEXT_LEFT);
|
||||
reaktor_tree_pop(ctx);
|
||||
}
|
||||
reaktor_note_pop(app);
|
||||
}
|
||||
reaktor_tree_pop(ctx);
|
||||
}
|
||||
reaktor_note_pop(app);
|
||||
SDL_snprintf(undo, sizeof undo, "Undo %s", reaktor_undo_label(app) ? reaktor_undo_label(app) : "");
|
||||
SDL_snprintf(redo, sizeof redo, "Redo %s", reaktor_redo_label(app) ? reaktor_redo_label(app) : "");
|
||||
if (reaktor_button(&(reaktor_button_spec){ .label = undo, .name = "Undo",
|
||||
.disabled = !reaktor_undo_label(app),
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y } }))
|
||||
reaktor_undo(app);
|
||||
if (reaktor_button(&(reaktor_button_spec){ .label = redo, .name = "Redo",
|
||||
.disabled = !reaktor_redo_label(app),
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y } }))
|
||||
reaktor_redo(app);
|
||||
}
|
||||
|
||||
reaktor_layout_row_dynamic(ctx, 10.0f, 1);
|
||||
|
||||
@@ -7,7 +7,7 @@ page_inputs(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
char line[96];
|
||||
|
||||
section(app, ctx, "Text",
|
||||
"One rule - tiny.css's `input` - supplies the fill, the radius, "
|
||||
"One rule - Water.css's `input` - supplies the fill, the radius, "
|
||||
"the padding and the border - 2px of transparent until "
|
||||
"`input:focus` colors it. Only the focused field takes that "
|
||||
"color; the rest get the neutral edge, because the rule assumes "
|
||||
@@ -42,13 +42,13 @@ page_inputs(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
}
|
||||
}
|
||||
|
||||
api(app, ctx, "reaktor_field with .multiline "
|
||||
api(app, ctx, "reaktor_field with .multiline and .line_numbers "
|
||||
"(Nuklear breaks lines on newlines only - there is no wrap)");
|
||||
{
|
||||
REAKTOR_ROW(.h = 92.0f) {
|
||||
reaktor_field(&(reaktor_field_spec){
|
||||
.buf = s->note, .len = &s->note_len, .cap = SC_BOX_CAP,
|
||||
.name = "Notes", .multiline = 1,
|
||||
.name = "Notes", .multiline = 1, .line_numbers = 1,
|
||||
.filter = reaktor_filter_default,
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X |
|
||||
REAKTOR_LAY_FILL_Y } });
|
||||
@@ -118,8 +118,9 @@ page_inputs(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
section(app, ctx, "Properties",
|
||||
"A property is a labeled number that can be dragged, clicked "
|
||||
"through its two steppers, or typed into - the three ways a "
|
||||
"person expects to change a number, in one widget.");
|
||||
api(app, ctx, "reaktor_property with .ivalue / .fvalue / .dvalue");
|
||||
"person expects to change a number, in one widget. A spinner "
|
||||
"steps through any list of values the same way, and wraps if asked.");
|
||||
api(app, ctx, "reaktor_property with .ivalue / .fvalue / .dvalue / reaktor_spinner");
|
||||
|
||||
{
|
||||
REAKTOR_ROW(.h = ROW,
|
||||
@@ -140,6 +141,40 @@ page_inputs(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X |
|
||||
REAKTOR_LAY_FILL_Y } });
|
||||
}
|
||||
REAKTOR_ROW(.h = ROW, .gap = ctx->style.window.spacing.x) {
|
||||
static const char *const quality[] = { "Low", "Medium", "High", "Best" };
|
||||
static const char *const days[] = { "Monday", "Tuesday", "Wednesday",
|
||||
"Thursday", "Friday", "Saturday",
|
||||
"Sunday" };
|
||||
|
||||
reaktor_spinner(&(reaktor_spinner_spec){
|
||||
.label = "Quality:", .items = quality, .count = 4, .chosen = &s->spin_q,
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y } });
|
||||
reaktor_spinner(&(reaktor_spinner_spec){
|
||||
.label = "Day:", .items = days, .count = 7, .chosen = &s->spin_d,
|
||||
.wrap = 1,
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y } });
|
||||
}
|
||||
}
|
||||
|
||||
section(app, ctx, "Dates and times",
|
||||
"An input that shows the value as the language writes it, or a hint "
|
||||
"until one is set. A click or Enter opens wheels, in the language's "
|
||||
"order, that loop where the values do: scroll one, click a row, or use "
|
||||
"the arrows - Up and Down turn the wheel, Left and Right move between "
|
||||
"wheels. Enter or OK sets the value, Escape or Cancel leaves it.");
|
||||
api(app, ctx, "reaktor_date_pick / reaktor_time_pick");
|
||||
|
||||
REAKTOR_ROW(.h = ROW, .gap = ctx->style.window.spacing.x) {
|
||||
reaktor_date_pick(&(reaktor_date_spec){
|
||||
.name = "Date", .year = &s->date_y, .month = &s->date_m, .day = &s->date_d,
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y } });
|
||||
reaktor_time_pick(&(reaktor_time_spec){
|
||||
.name = "Time", .hour = &s->time_h, .minute = &s->time_m,
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y } });
|
||||
reaktor_time_pick(&(reaktor_time_spec){
|
||||
.name = "Time, 12-hour", .hour = &s->time12_h, .minute = &s->time12_m,
|
||||
.clock12 = 1, .box = { .flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y } });
|
||||
}
|
||||
|
||||
section(app, ctx, "Combo boxes",
|
||||
|
||||
@@ -205,7 +205,7 @@ tray_demo(App *app, struct reaktor_context *ctx)
|
||||
static void
|
||||
closing_demo(App *app, struct reaktor_context *ctx)
|
||||
{
|
||||
static reaktor_bool ask;
|
||||
static reaktor_bool ask = 1;
|
||||
|
||||
section(app, ctx, "Closing",
|
||||
"A close can ask first. The close button, the tray's Quit and a "
|
||||
@@ -215,7 +215,7 @@ closing_demo(App *app, struct reaktor_context *ctx)
|
||||
REAKTOR_ROW(.h = ROW, .flags = REAKTOR_LAY_FILL_X) {
|
||||
if (reaktor_check(&(reaktor_check_spec){ .label = "Ask before closing",
|
||||
.on = &ask }))
|
||||
reaktor_set_confirm_close(app, ask ? "Close the Showcase?" : NULL);
|
||||
reaktor_set_confirm_close(app, ask ? SC_CLOSE_QUESTION : NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,6 +256,44 @@ showcase_toasts(App *app)
|
||||
reaktor_toast(app, &g_toast_undo);
|
||||
}
|
||||
|
||||
/* A page of what the Popups tab holds, laid out for paper. */
|
||||
static void
|
||||
print_sample(App *app, struct reaktor_context *ctx, int index, int w, int h, void *user)
|
||||
{
|
||||
(void)app; (void)index; (void)user;
|
||||
reaktor_fill_rect(reaktor_window_get_canvas(ctx), reaktor_rect(0, 0, (float)w, (float)h),
|
||||
0.0f, reaktor_rgb(255, 255, 255));
|
||||
REAKTOR_FREE(.w = (float)w, .h = (float)h) {
|
||||
REAKTOR_COLUMN(.w = (float)w - 96.0f, .gap = 10.0f, .ml = 48.0f, .mt = 48.0f) {
|
||||
reaktor_label(&(reaktor_label_spec){ .text = "A page from Reaktor", .style = "h4",
|
||||
.color = "#000000" });
|
||||
reaktor_label(&(reaktor_label_spec){
|
||||
.text = "Laid out and drawn as the window draws it, then printed or "
|
||||
"written to a PDF.", .wrap = 1, .color = "#333333",
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X } });
|
||||
reaktor_button(&(reaktor_button_spec){ .label = "A button on paper",
|
||||
.box = { .w = 180.0f } });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
print_done(App *app, int ok, void *user)
|
||||
{
|
||||
(void)user;
|
||||
reaktor_toast(app, &(reaktor_toast_spec){ .text = ok ? "Printed" : "Not printed",
|
||||
.timeout_ms = 3000 });
|
||||
}
|
||||
|
||||
static void
|
||||
pdf_chosen(App *app, const char *const *paths, int count, void *user)
|
||||
{
|
||||
(void)user;
|
||||
if (count)
|
||||
reaktor_print_pdf(app, paths[0], &(reaktor_print_spec){
|
||||
.title = "Reaktor", .pages = 1, .page = print_sample, .done = print_done });
|
||||
}
|
||||
|
||||
static void
|
||||
toast_demos(App *app, struct reaktor_context *ctx)
|
||||
{
|
||||
@@ -263,8 +301,10 @@ toast_demos(App *app, struct reaktor_context *ctx)
|
||||
"Messages at the bottom of the window, stacked newest last. Each "
|
||||
"holds text, an optional icon, an action, custom controls and a "
|
||||
"close button. One stays until it is closed, or goes by itself "
|
||||
"when it is given a timeout - five seconds here.");
|
||||
api(app, ctx, "reaktor_toast");
|
||||
"when it is given a timeout - five seconds here. A system "
|
||||
"notification leaves the window: a toast on Windows, the desktop's "
|
||||
"own on Linux, macOS and the BSDs, the browser's on the web.");
|
||||
api(app, ctx, "reaktor_toast / reaktor_notify");
|
||||
|
||||
REAKTOR_ROW(.h = ROW, .gap = ctx->style.window.spacing.x) {
|
||||
if (reaktor_button(&(reaktor_button_spec){
|
||||
@@ -298,16 +338,54 @@ toast_demos(App *app, struct reaktor_context *ctx)
|
||||
reaktor_toast(app, &(reaktor_toast_spec){
|
||||
.text = "This one stays until it is closed" });
|
||||
}
|
||||
REAKTOR_ROW(.h = ROW, .gap = ctx->style.window.spacing.x) {
|
||||
if (reaktor_button(&(reaktor_button_spec){
|
||||
.label = "System notification",
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X } }) &&
|
||||
!reaktor_notify(app, &(reaktor_notification){
|
||||
.title = "Reaktor", .text = "A notification from outside the window" }))
|
||||
reaktor_toast(app, &(reaktor_toast_spec){
|
||||
.text = "This system has no notifications", .timeout_ms = 5000 });
|
||||
}
|
||||
}
|
||||
|
||||
static float
|
||||
menu_w(struct reaktor_context *ctx, const char *label)
|
||||
static void
|
||||
print_demos(App *app, struct reaktor_context *ctx)
|
||||
{
|
||||
const struct reaktor_user_font *f = ctx->style.font;
|
||||
const struct reaktor_style_button *b = &ctx->style.menu_button;
|
||||
section(app, ctx, "Printing",
|
||||
"A page is drawn as the window would draw it, at the printer's "
|
||||
"resolution, and goes to the system's print dialog on Windows and "
|
||||
"macOS, or opens as a PDF on Linux and the BSDs. The same pages can "
|
||||
"be written to a PDF file instead.");
|
||||
api(app, ctx, "reaktor_print / reaktor_print_pdf");
|
||||
|
||||
return (float)(int)(f->width(f->userdata, f->height, label, (int)strlen(label)) +
|
||||
2.0f * (b->padding.x + b->border + b->rounding) + 2.5f);
|
||||
REAKTOR_ROW(.h = ROW, .gap = ctx->style.window.spacing.x) {
|
||||
if (reaktor_button(&(reaktor_button_spec){
|
||||
.label = "Print a page",
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X } }) &&
|
||||
!reaktor_print(app, &(reaktor_print_spec){ .title = "Reaktor", .pages = 1,
|
||||
.page = print_sample,
|
||||
.done = print_done }))
|
||||
reaktor_toast(app, &(reaktor_toast_spec){
|
||||
.text = "This build does not print", .timeout_ms = 5000 });
|
||||
if (reaktor_button(&(reaktor_button_spec){
|
||||
.label = "Export as PDF",
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X } }))
|
||||
reaktor_file_dialog_open(app, &(reaktor_file_dialog){
|
||||
.kind = REAKTOR_FILE_SAVE, .chosen = pdf_chosen,
|
||||
.location = "exported.pdf",
|
||||
.filters = (const reaktor_file_filter[]){ { "PDF", "pdf" } },
|
||||
.filter_count = 1 });
|
||||
}
|
||||
}
|
||||
|
||||
static reaktor_size *g_menu_progress;
|
||||
|
||||
static void
|
||||
menu_progress(App *app, struct reaktor_context *ctx, void *user)
|
||||
{
|
||||
(void)user;
|
||||
reaktor_progress_bar(app, ctx, g_menu_progress, 100, REAKTOR_MODIFIABLE);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -420,106 +498,79 @@ page_popups(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
{
|
||||
char line[SC_PATH_CAP + 32];
|
||||
struct reaktor_rect bar;
|
||||
int ok, tip = 0;
|
||||
int tip = 0;
|
||||
|
||||
popup_style_push(ctx);
|
||||
reaktor_layout_row_dynamic(ctx, 40.0f, 1);
|
||||
bar = reaktor_widget_bounds(ctx);
|
||||
reaktor_style_push_vec2(ctx, &ctx->style.window.group_padding,
|
||||
reaktor_vec2(12.0f, 7.0f));
|
||||
ok = reaktor_group_begin(ctx, "menubar", REAKTOR_WINDOW_NO_SCROLLBAR);
|
||||
reaktor_style_pop_vec2(ctx);
|
||||
if (ok) {
|
||||
reaktor_note_push(app, REAKTOR_A11Y_MENUBAR, "Menu bar", NULL, 0, bar);
|
||||
reaktor_menubar_begin(ctx);
|
||||
reaktor_layout_row_begin(ctx, REAKTOR_STATIC, 26.0f, 3);
|
||||
reaktor_layout_row_push(ctx, menu_w(ctx, "File"));
|
||||
hot(app, ctx, REAKTOR_A11Y_MENU, "File", 0);
|
||||
if (reaktor_menu_begin_label(ctx, "File", REAKTOR_TEXT_CENTERED,
|
||||
reaktor_vec2(150.0f,
|
||||
reaktor_menu_height(3)))) {
|
||||
reaktor_menu_style_push(ctx);
|
||||
reaktor_menu_edge(app, ctx);
|
||||
reaktor_layout_row_dynamic(ctx, REAKTOR_MENU_ROW, 1);
|
||||
if (item_with_icon(app, ctx, "New", "add-outline", 0))
|
||||
SDL_strlcpy(s->menu_pick, "File > New", sizeof(s->menu_pick));
|
||||
if (item_with_icon(app, ctx, "Open...", "folder-open-outline", 0)) {
|
||||
SDL_strlcpy(s->menu_pick, "File > Open", sizeof(s->menu_pick));
|
||||
if (reaktor_file_dialog_open(app, &(reaktor_file_dialog){
|
||||
REAKTOR_ROW(.name = "Menus", .h = 40.0f, .flags = REAKTOR_LAY_FILL_X) {
|
||||
static const reaktor_menu_entry file[] = {
|
||||
{ .label = "New", .icon = "add-outline", .keys = "Ctrl+N" },
|
||||
{ .label = "Open...", .icon = "folder-open-outline", .keys = "Ctrl+O" },
|
||||
{ NULL },
|
||||
{ .label = "Close", .icon = "close-outline", .keys = "Ctrl+W" }
|
||||
};
|
||||
static const reaktor_menu_entry zoom[] = {
|
||||
{ .label = "Zoom in", .keys = "Ctrl++" },
|
||||
{ .label = "Zoom out", .keys = "Ctrl+-" },
|
||||
{ NULL },
|
||||
{ .label = "Actual size", .keys = "Ctrl+0" }
|
||||
};
|
||||
reaktor_menu_entry edit[] = {
|
||||
{ .label = "Cut", .keys = "Ctrl+X" },
|
||||
{ .label = "Copy", .keys = "Ctrl+C" },
|
||||
{ .label = "Paste", .keys = "Ctrl+V", .disabled = 1 },
|
||||
{ NULL },
|
||||
{ .label = "Overwrite", .checked = &s->check_spell }
|
||||
};
|
||||
reaktor_menu_entry view[] = {
|
||||
{ .custom = menu_progress },
|
||||
{ .label = "Reset progress" },
|
||||
{ NULL },
|
||||
{ .label = "Zoom", .items = zoom, .count = (int)SDL_arraysize(zoom) },
|
||||
{ .label = "Full screen", .disabled = 1 }
|
||||
};
|
||||
const reaktor_menu_entry *pe = NULL;
|
||||
reaktor_menu menus[3] = {
|
||||
{ "File", file, (int)SDL_arraysize(file) },
|
||||
{ "Edit", edit, (int)SDL_arraysize(edit) },
|
||||
{ "View", view, (int)SDL_arraysize(view) }
|
||||
};
|
||||
int pm = -1, pi = -1;
|
||||
|
||||
g_menu_progress = &s->progress;
|
||||
|
||||
if (reaktor_box_rect(&bar))
|
||||
reaktor_edge_round(app, reaktor_window_get_canvas(ctx), bar,
|
||||
ctx->style.window.rounding, 1.0f,
|
||||
ctx->style.window.border_color);
|
||||
if (reaktor_menubar(&(reaktor_menubar_spec){
|
||||
.menus = menus, .count = 3, .name = "Menu bar",
|
||||
.box = { .ml = 12.0f, .mt = 7.0f },
|
||||
.picked_menu = &pm, .picked_item = &pi, .picked = &pe }) && pe) {
|
||||
SDL_snprintf(s->menu_pick, sizeof(s->menu_pick), "%s > %s",
|
||||
menus[pm].label, pe->label);
|
||||
if (pm == 0 && pi == 1 &&
|
||||
reaktor_file_dialog_open(app, &(reaktor_file_dialog){
|
||||
.filters = g_sheet_filters,
|
||||
.filter_count = (int)SDL_arraysize(g_sheet_filters),
|
||||
.chosen = file_chosen }))
|
||||
SDL_strlcpy(s->file_pick, "waiting for the picker...",
|
||||
sizeof(s->file_pick));
|
||||
if (pe == &view[1]) s->progress = 50;
|
||||
}
|
||||
if (item_with_icon(app, ctx, "Close", "close-outline", 0))
|
||||
SDL_strlcpy(s->menu_pick, "File > Close", sizeof(s->menu_pick));
|
||||
reaktor_menu_end(ctx);
|
||||
reaktor_menu_style_pop(ctx);
|
||||
}
|
||||
reaktor_layout_row_push(ctx, menu_w(ctx, "Edit"));
|
||||
hot(app, ctx, REAKTOR_A11Y_MENU, "Edit", 0);
|
||||
if (reaktor_menu_begin_label(ctx, "Edit", REAKTOR_TEXT_CENTERED,
|
||||
reaktor_vec2(190.0f,
|
||||
reaktor_menu_height(4)))) {
|
||||
reaktor_menu_style_push(ctx);
|
||||
reaktor_menu_edge(app, ctx);
|
||||
reaktor_layout_row_dynamic(ctx, REAKTOR_MENU_ROW, 1);
|
||||
if (reaktor_menu_item(app, ctx, "Cut", NULL, 0))
|
||||
SDL_strlcpy(s->menu_pick, "Edit > Cut", sizeof(s->menu_pick));
|
||||
if (reaktor_menu_item(app, ctx, "Copy", NULL, 0))
|
||||
SDL_strlcpy(s->menu_pick, "Edit > Copy", sizeof(s->menu_pick));
|
||||
reaktor_layout_row_template_begin(ctx, REAKTOR_MENU_ROW);
|
||||
reaktor_layout_row_template_push_static(ctx, 5.0f);
|
||||
reaktor_layout_row_template_push_dynamic(ctx);
|
||||
reaktor_layout_row_template_push_static(ctx, 6.0f);
|
||||
reaktor_layout_row_template_end(ctx);
|
||||
reaktor_spacer(ctx);
|
||||
reaktor_hot_top(app, reaktor_widget_bounds(ctx), 0, 1);
|
||||
reaktor_checkbox_label_align(ctx, "Overwrite", &s->check_spell,
|
||||
REAKTOR_WIDGET_RIGHT, REAKTOR_TEXT_LEFT);
|
||||
reaktor_spacer(ctx);
|
||||
reaktor_layout_row_dynamic(ctx, REAKTOR_MENU_ROW, 1);
|
||||
reaktor_slider_bar(app, ctx, 0, &s->slider_f, 0.0f, 1.0f, 0.01f);
|
||||
reaktor_menu_end(ctx);
|
||||
reaktor_menu_style_pop(ctx);
|
||||
}
|
||||
reaktor_layout_row_push(ctx, menu_w(ctx, "View"));
|
||||
hot(app, ctx, REAKTOR_A11Y_MENU, "View", 0);
|
||||
if (reaktor_menu_begin_label(ctx, "View", REAKTOR_TEXT_CENTERED,
|
||||
reaktor_vec2(170.0f,
|
||||
reaktor_menu_height(2)))) {
|
||||
reaktor_menu_style_push(ctx);
|
||||
reaktor_menu_edge(app, ctx);
|
||||
reaktor_layout_row_dynamic(ctx, REAKTOR_MENU_ROW, 1);
|
||||
reaktor_progress_bar(app, ctx, &s->progress, 100, REAKTOR_MODIFIABLE);
|
||||
if (reaktor_menu_item(app, ctx, "Reset", NULL, 0))
|
||||
s->progress = 50;
|
||||
reaktor_menu_end(ctx);
|
||||
reaktor_menu_style_pop(ctx);
|
||||
}
|
||||
reaktor_layout_row_end(ctx);
|
||||
reaktor_menubar_end(ctx);
|
||||
reaktor_note_pop(app);
|
||||
reaktor_group_end(ctx);
|
||||
}
|
||||
reaktor_edge_round(app, reaktor_window_get_canvas(ctx), bar,
|
||||
ctx->style.window.rounding, 1.0f,
|
||||
ctx->style.window.border_color);
|
||||
popup_style_pop(ctx);
|
||||
|
||||
reaktor_layout_row_dynamic(ctx, 8.0f, 1);
|
||||
reaktor_spacer(ctx);
|
||||
head_and_note(app, ctx, "Menus",
|
||||
"The bar above. A menu is a popup anchored to the item that "
|
||||
"opened it, and its items are ordinary widgets - the View menu "
|
||||
"has a draggable progress bar in it. An item's glyph and the "
|
||||
"Edit menu's checkbox both sit at the right edge: the checkbox "
|
||||
"through reaktor_checkbox_label_align, the glyph painted there, "
|
||||
"because reaktor_menu_item_symbol_label centers its label whatever "
|
||||
"alignment it is given.");
|
||||
api(app, ctx, "reaktor_menubar_begin / reaktor_menu_begin_label / "
|
||||
"reaktor_menu_item_label / reaktor_checkbox_label_align");
|
||||
"The bar above is declared: menus of items, each with an optional "
|
||||
"icon, a shortcut shown at the right, a check and a disabled state, "
|
||||
"separators, submenus, and rows that hold a widget of their own - "
|
||||
"the View menu's progress bar. Tab reaches the titles, Enter opens "
|
||||
"one and moves into it, Up and Down walk its items, Right opens a "
|
||||
"submenu or the next menu, Left goes back, and Escape closes; "
|
||||
"screen readers see a menu bar, menus and items.");
|
||||
api(app, ctx, "reaktor_menubar / reaktor_menu / reaktor_menu_entry");
|
||||
|
||||
{
|
||||
reaktor_style_push_font(ctx, reaktor_style_font(app, ".small", 13, 0));
|
||||
@@ -627,6 +678,7 @@ page_popups(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
closing_demo(app, ctx);
|
||||
tray_demo(app, ctx);
|
||||
toast_demos(app, ctx);
|
||||
print_demos(app, ctx);
|
||||
ask_demo(app, ctx);
|
||||
settings_demo(app, ctx);
|
||||
|
||||
|
||||
@@ -44,8 +44,8 @@ rule_says(const char *selector)
|
||||
void
|
||||
page_styling(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
{
|
||||
static const reaktor_asset simple_css = {
|
||||
.path = "external/simplecss/simple.css" };
|
||||
static const reaktor_asset bamboo_css = {
|
||||
.path = "external/bamboocss/dist/bamboo.min.css" };
|
||||
static reaktor_bool on;
|
||||
|
||||
section(app, ctx, "Change the stylesheet, change the application",
|
||||
@@ -54,15 +54,15 @@ page_styling(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
"in the window follows - the buttons, the fields, the borders, "
|
||||
"the corners. That is the only claim this library makes about "
|
||||
"styling, and it is either true in front of you or it is not.");
|
||||
api(app, ctx, "external/simplecss");
|
||||
api(app, ctx, "external/bamboocss");
|
||||
|
||||
REAKTOR_ROW(.h = ROW, .gap = ctx->style.window.spacing.x) {
|
||||
if (reaktor_check(&(reaktor_check_spec){
|
||||
.label = "Read simple.css over the top of tiny.css",
|
||||
.label = "Read Bamboo over the top of Water.css",
|
||||
.name = "Override stylesheet",
|
||||
.on = &on,
|
||||
.box = { .w = 380.0f, .flags = REAKTOR_LAY_CENTER_Y } }))
|
||||
reaktor_set_css(app, on ? &simple_css : NULL, on ? 1 : 0);
|
||||
reaktor_set_css(app, on ? &bamboo_css : NULL, on ? 1 : 0);
|
||||
reaktor_soak();
|
||||
}
|
||||
|
||||
@@ -130,12 +130,12 @@ page_styling(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
}
|
||||
|
||||
section(app, ctx, "Three sheets, read in order",
|
||||
"The palette, then tiny.css, then this application's own, then "
|
||||
"The palette, then Water.css, then this application's own, then "
|
||||
"the override if there is one. There is no merging step and no "
|
||||
"precedence table - CSS resolves a tie by document order, so the "
|
||||
"last sheet read wins, and reading one last is the whole "
|
||||
"mechanism. A selector the override says nothing about still "
|
||||
"resolves to tiny.css's rule; one neither mentions leaves the "
|
||||
"resolves to Water.css's rule; one neither mentions leaves the "
|
||||
"widget on Nuklear's own default.");
|
||||
api(app, ctx, "reaktor_style_init(sheets, n, theme)");
|
||||
|
||||
@@ -150,7 +150,7 @@ page_styling(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
.name = "Controls with no rule", .color = "--text-muted",
|
||||
.wrap = 1, .box = { .flags = REAKTOR_LAY_FILL_X } });
|
||||
reaktor_label(&(reaktor_label_spec){
|
||||
.text = "simple.css keeps its dark palette in "
|
||||
.text = "Bamboo keeps its dark palette in "
|
||||
"@media (prefers-color-scheme: dark), which this tree "
|
||||
"used to drop along with every other at-rule - so a "
|
||||
"sheet written that way loaded light-only. That branch "
|
||||
|
||||
@@ -128,7 +128,7 @@ splash_page(App *app, struct reaktor_context *ctx, int w, int h, void *user)
|
||||
SDL_snprintf(line, sizeof line, "SDL %d.%d.%d \xC2\xB7 Nuklear \xC2\xB7 NukAnim \xC2\xB7 LCUI \xC2\xB7 plutosvg",
|
||||
SDL_VERSIONNUM_MAJOR(v), SDL_VERSIONNUM_MINOR(v), SDL_VERSIONNUM_MICRO(v));
|
||||
credit(cv, reaktor_font(app, 12, 0), line, 250.0f, w, muted, tag);
|
||||
credit(cv, reaktor_font(app, 12, 0), "Onlay \xC2\xB7 mojibake \xC2\xB7 kb_text_shape \xC2\xB7 tiny.css",
|
||||
credit(cv, reaktor_font(app, 12, 0), "Onlay \xC2\xB7 mojibake \xC2\xB7 kb_text_shape \xC2\xB7 Water.css",
|
||||
268.0f, w, muted, tag);
|
||||
}
|
||||
|
||||
@@ -440,6 +440,8 @@ login_card(App *app, struct reaktor_context *ctx, float body_x, float body_w,
|
||||
reaktor_style_pop_style_item(ctx);
|
||||
}
|
||||
|
||||
#define STRIP_ROUND 4.0f
|
||||
|
||||
static reaktor_style_frame
|
||||
push_strip_look(struct reaktor_context *ctx, struct reaktor_color fg, struct reaktor_color wash)
|
||||
{
|
||||
@@ -453,8 +455,11 @@ push_strip_look(struct reaktor_context *ctx, struct reaktor_color fg, struct rea
|
||||
reaktor_style_push_color(ctx, &ctx->style.button.text_hover, fg);
|
||||
reaktor_style_push_color(ctx, &ctx->style.button.text_active, fg);
|
||||
reaktor_style_push_float(ctx, &ctx->style.button.border, 0.0f);
|
||||
reaktor_style_push_float(ctx, &ctx->style.button.rounding, 4.0f);
|
||||
return (reaktor_style_frame){ 3, 3, 2, 0, 0 };
|
||||
reaktor_style_push_float(ctx, &ctx->style.button.rounding, STRIP_ROUND);
|
||||
/* The width was measured with this padding; the sheet's own may be wider. */
|
||||
reaktor_style_push_vec2(ctx, &ctx->style.button.padding,
|
||||
reaktor_vec2((float)TAB_PAD_X, ctx->style.button.padding.y));
|
||||
return (reaktor_style_frame){ 3, 3, 2, 1, 0 };
|
||||
}
|
||||
|
||||
static struct reaktor_color
|
||||
@@ -476,8 +481,9 @@ sample_option(App *app, struct reaktor_context *ctx, const char *label, float w,
|
||||
|
||||
if (w <= 0.0f) {
|
||||
const struct reaktor_user_font *f = ctx->style.font;
|
||||
/* Nuklear takes the rounding out of a button's text room too. */
|
||||
w = f->width(f->userdata, f->height, label, (int)strlen(label))
|
||||
+ 2.0f * (float)TAB_PAD_X;
|
||||
+ 2.0f * ((float)TAB_PAD_X + STRIP_ROUND);
|
||||
}
|
||||
reaktor_layout_row_push(ctx, w);
|
||||
b = reaktor_widget_bounds(ctx);
|
||||
@@ -801,6 +807,8 @@ main(int argc, char **argv)
|
||||
.window = { .w = WINDOW_WIDTH, .h = WINDOW_HEIGHT, .hidden = 1,
|
||||
.borderless = 1, .hit_test = window_hit_test },
|
||||
.font_fallbacks = { { .path = "assets/fonts/MPLUS1p-Regular.ttf" } },
|
||||
.confirm_close = SC_CLOSE_QUESTION,
|
||||
.inspector = { .attach = 1 },
|
||||
.page = page_shell,
|
||||
.key = sample_key,
|
||||
.start = sample_start,
|
||||
|
||||
@@ -93,27 +93,6 @@ popup_style_pop(struct reaktor_context *ctx)
|
||||
reaktor_style_pop_style_item(ctx);
|
||||
}
|
||||
|
||||
struct reaktor_rect
|
||||
tree_header_bounds(struct reaktor_context *ctx)
|
||||
{
|
||||
struct reaktor_rect b = reaktor_widget_bounds(ctx);
|
||||
b.h = ctx->style.font->height + 2.0f * ctx->style.tab.padding.y;
|
||||
return b;
|
||||
}
|
||||
|
||||
void
|
||||
tree_chevron(App *app, struct reaktor_context *ctx, struct reaktor_rect b,
|
||||
int open)
|
||||
{
|
||||
float h = ctx->style.font->height;
|
||||
struct reaktor_rect s = reaktor_rect(b.x + ctx->style.tab.padding.x,
|
||||
b.y + ctx->style.tab.padding.y, h, h);
|
||||
|
||||
reaktor_chevron_at(app, ctx, s,
|
||||
open ? "chevron-down-outline" : "chevron-forward-outline",
|
||||
ctx->style.tab.text);
|
||||
}
|
||||
|
||||
void
|
||||
draw_tooltip(App *app, struct reaktor_context *ctx, const char *const *lines,
|
||||
int n, float bar)
|
||||
@@ -214,6 +193,9 @@ seed(showcase_state *s)
|
||||
s->anim_curve = REAKTOR_EASE_CUBIC_OUT;
|
||||
s->anim_slot = 0;
|
||||
for (i = 0; i < 4; i++) s->grow[i] = 1.0f;
|
||||
s->tree_open[0] = s->tree_open[1] = 1;
|
||||
s->tree_sel = 2;
|
||||
s->time_h = s->time12_h = -1;
|
||||
|
||||
SDL_strlcpy(s->name, "Ada Lovelace", sizeof(s->name));
|
||||
s->name_len = (int)strlen(s->name);
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#define SC_BOX_CAP 512
|
||||
#define SC_SERIES_N 32
|
||||
#define SC_LIST_N 64
|
||||
#define SC_CLOSE_QUESTION "Close the Showcase?"
|
||||
#define SC_PATH_CAP 520
|
||||
|
||||
#define WINDOW_WIDTH 1100
|
||||
@@ -84,7 +85,10 @@ typedef struct showcase_state {
|
||||
|
||||
float series[SC_SERIES_N];
|
||||
int list_sel;
|
||||
reaktor_bool tree_leaf[3];
|
||||
unsigned char tree_open[16];
|
||||
int tree_sel;
|
||||
int spin_q, spin_d;
|
||||
int date_y, date_m, date_d, time_h, time_m, time12_h, time12_m;
|
||||
|
||||
int anim_slot;
|
||||
int anim_curve;
|
||||
@@ -133,8 +137,6 @@ void popup_style_pop(struct reaktor_context *ctx);
|
||||
void popup_style_push(struct reaktor_context *ctx);
|
||||
void rule(struct reaktor_context *ctx);
|
||||
void section(App *app, struct reaktor_context *ctx, const char *title, const char *note);
|
||||
void tree_chevron(App *app, struct reaktor_context *ctx, struct reaktor_rect b, int open);
|
||||
struct reaktor_rect tree_header_bounds(struct reaktor_context *ctx);
|
||||
|
||||
void page_buttons(App *app, struct reaktor_context *ctx, showcase_state *s);
|
||||
void page_inputs(App *app, struct reaktor_context *ctx, showcase_state *s);
|
||||
|
||||
@@ -14,7 +14,10 @@ static const char g_sheet[] =
|
||||
"button:enabled:hover { color: #123456; }\n"
|
||||
"button[disabled] { color: #654321; }\n"
|
||||
"p { padding: calc(1.5 * 8px) calc(8px / 2); top: calc(0px - 8px); "
|
||||
"margin: calc(2 * (3px + 1px)); width: calc(100% - 2 * 8px); }\n";
|
||||
"margin: calc(2 * (3px + 1px)); width: calc(100% - 2 * 8px); }\n"
|
||||
"q { background-image: url(data:image/svg+xml;base64,AAAA); color: #010203; }\n"
|
||||
"q.v { content: \"a value longer than the engine token\"; color: #040506; }\n"
|
||||
".a-selector-longer-than-the-engines-token, u { color: #070809; }\n";
|
||||
|
||||
char *
|
||||
reaktor_asset_load(const char *name, size_t *len)
|
||||
@@ -76,11 +79,11 @@ int
|
||||
main(void)
|
||||
{
|
||||
static const char *const test[1] = { "test.css" };
|
||||
static const char *const simple[1] = { "external/simplecss/simple.css" };
|
||||
static const char *const bamboo[1] = { "external/bamboocss/dist/bamboo.min.css" };
|
||||
char *out;
|
||||
int i;
|
||||
|
||||
out = reaktor_css_flatten(test, 1, "light", NULL);
|
||||
out = reaktor_css_flatten(test, 1, "light", 32, NULL);
|
||||
ok("a sheet flattens", out != NULL);
|
||||
if (out) {
|
||||
ok("two :not() in one compound are dropped", !strstr(out, "not("));
|
||||
@@ -94,12 +97,15 @@ main(void)
|
||||
ok(" with a subtraction", strstr(out, "top: -8px;") != NULL);
|
||||
ok(" and brackets", strstr(out, "margin: 8px;") != NULL);
|
||||
ok("calc() with a percentage is left", strstr(out, "width: calc(100% - 2 * 8px);") != NULL);
|
||||
ok("a value with a ';' is dropped", !strstr(out, "base64") && strstr(out, "#010203"));
|
||||
ok("a value past the token is dropped", !strstr(out, "longer") && strstr(out, "#040506"));
|
||||
ok("a selector past the token is dropped", !strstr(out, "a-selector") && strstr(out, "u {"));
|
||||
free(out);
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
out = reaktor_css_flatten(simple, 1, i ? "dark" : "light", NULL);
|
||||
ok(i ? "simple.css flattens, dark" : "simple.css flattens, light",
|
||||
out = reaktor_css_flatten(bamboo, 1, i ? "dark" : "light", 0, NULL);
|
||||
ok(i ? "Bamboo flattens, dark" : "Bamboo flattens, light",
|
||||
out != NULL && strstr(out, "button") != NULL);
|
||||
ok(" and no compound in it holds two :not()", out != NULL && !not_twice(out));
|
||||
free(out);
|
||||
|
||||
@@ -775,6 +775,349 @@ service_page(App *app, struct nk_context *ctx, int w, int h)
|
||||
reaktor_wake(app);
|
||||
}
|
||||
|
||||
static const char *
|
||||
focused_name(App *app)
|
||||
{
|
||||
const reaktor_a11y_node *t = app->a11y.node[1 - app->a11y.front];
|
||||
int n = app->a11y.count[1 - app->a11y.front], i;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
if (t[i].id == app->focus_id) return t[i].name ? t[i].name : "?";
|
||||
return "nothing";
|
||||
}
|
||||
|
||||
static int
|
||||
press_role(App *app, unsigned char role, const char *name)
|
||||
{
|
||||
const reaktor_a11y_node *t = app->a11y.node[1 - app->a11y.front];
|
||||
int n = app->a11y.count[1 - app->a11y.front], i;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
if (t[i].role == role && t[i].name && SDL_strcmp(t[i].name, name) == 0) {
|
||||
push_click(app, t[i].bounds.x + t[i].bounds.w * 0.5f,
|
||||
t[i].bounds.y + t[i].bounds.h * 0.5f);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char *
|
||||
expanded(App *app)
|
||||
{
|
||||
const reaktor_a11y_node *t = app->a11y.node[1 - app->a11y.front];
|
||||
int n = app->a11y.count[1 - app->a11y.front], i;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
if (t[i].role == REAKTOR_A11Y_MENU && (t[i].state & REAKTOR_A11Y_EXPANDED) &&
|
||||
t[i].name)
|
||||
return t[i].name;
|
||||
return "none";
|
||||
}
|
||||
|
||||
static void
|
||||
menu_page(App *app, struct nk_context *ctx, int w, int h)
|
||||
{
|
||||
static reaktor_bool wrap;
|
||||
static const reaktor_menu_entry items[] = {
|
||||
{ .label = "New", .keys = "Ctrl+N" },
|
||||
{ .label = "Open", .disabled = 1 },
|
||||
{ NULL },
|
||||
{ .label = "Wrap", .checked = &wrap }
|
||||
};
|
||||
static const reaktor_menu_entry zoom[] = { { .label = "In" }, { .label = "Out" } };
|
||||
static const reaktor_menu_entry view[] = {
|
||||
{ .label = "Zoom", .items = zoom, .count = 2 }, { .label = "Reset" }
|
||||
};
|
||||
static const reaktor_menu menus[] = { { "File", items, 4 }, { "View", view, 2 } };
|
||||
static const reaktor_menu_entry *pe;
|
||||
static int pm = -1;
|
||||
char line[96];
|
||||
|
||||
(void)ctx;
|
||||
if (g_frames >= 3 && g_frames <= 9 && g_frames % 2 &&
|
||||
SDL_strcmp(focused_name(app), "File") != 0)
|
||||
push_tap(app, SDLK_TAB);
|
||||
if (g_frames == 12 || g_frames == 22 || g_frames == 40 || g_frames == 54 ||
|
||||
g_frames == 82)
|
||||
push_tap(app, SDLK_RETURN);
|
||||
if (g_frames == 18) push_tap(app, SDLK_DOWN);
|
||||
if (g_frames == 46) push_tap(app, SDLK_ESCAPE);
|
||||
if (g_frames == 60 || g_frames == 66 || g_frames == 76) push_tap(app, SDLK_RIGHT);
|
||||
if (g_frames == 72) push_tap(app, SDLK_LEFT);
|
||||
if (g_frames == 20 || g_frames == 30 || g_frames == 45 || g_frames == 52 ||
|
||||
g_frames == 64 || g_frames == 90 || g_frames == 100 || g_frames == 108) {
|
||||
SDL_snprintf(line, sizeof line, "open %s, focus on %s, picked %s in %d, wrap %s",
|
||||
expanded(app), focused_name(app), pe ? pe->label : "nothing", pm,
|
||||
wrap ? "on" : "off");
|
||||
note(line);
|
||||
}
|
||||
if (g_frames == 94 || g_frames == 102) press_role(app, REAKTOR_A11Y_MENU, "File");
|
||||
if (g_frames > 112) reaktor_quit(app, 0);
|
||||
REAKTOR_FREE(.w = (float)w, .h = (float)h) {
|
||||
REAKTOR_COLUMN(.w = (float)w) {
|
||||
reaktor_button(&(reaktor_button_spec){ .label = "Before" });
|
||||
reaktor_menubar(&(reaktor_menubar_spec){ .menus = menus, .count = 2,
|
||||
.picked_menu = &pm, .picked = &pe });
|
||||
}
|
||||
}
|
||||
app->dirty = 1;
|
||||
reaktor_wake(app);
|
||||
}
|
||||
|
||||
static const int g_tree_parent[6] = { -1, 0, 1, 1, -1, 4 };
|
||||
static const char *g_tree_label[6] = { "A", "A1", "A1a", "A1b", "B", "B1" };
|
||||
|
||||
static int tree_parent(int n, void *u) { (void)u; return g_tree_parent[n]; }
|
||||
static const char *tree_label(int n, void *u) { (void)u; return g_tree_label[n]; }
|
||||
|
||||
static void
|
||||
tree_page(App *app, struct nk_context *ctx, int w, int h)
|
||||
{
|
||||
static unsigned char open[6];
|
||||
static int sel = -1;
|
||||
char line[96];
|
||||
static const SDL_Keycode keys[] = { SDLK_TAB, SDLK_RIGHT, SDLK_RIGHT, SDLK_RIGHT,
|
||||
SDLK_DOWN, SDLK_LEFT, SDLK_LEFT };
|
||||
int k = (g_frames - 4) / 6;
|
||||
|
||||
(void)ctx;
|
||||
if (g_frames >= 4 && (g_frames - 4) % 6 == 0 && k < (int)SDL_arraysize(keys))
|
||||
push_tap(app, keys[k]);
|
||||
if (g_frames >= 4 && (g_frames - 4) % 6 == 5 && k < (int)SDL_arraysize(keys)) {
|
||||
SDL_snprintf(line, sizeof line, "focus %s, selected %d, open %d%d%d%d%d%d",
|
||||
focused_name(app), sel, open[0], open[1], open[2], open[3],
|
||||
open[4], open[5]);
|
||||
note(line);
|
||||
}
|
||||
if (g_frames == 60) press_role(app, REAKTOR_A11Y_TREEITEM, "B");
|
||||
if (g_frames == 66) {
|
||||
const reaktor_a11y_node *t = app->a11y.node[1 - app->a11y.front];
|
||||
int n = app->a11y.count[1 - app->a11y.front], i;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
if (t[i].role == REAKTOR_A11Y_TREEITEM && SDL_strcmp(t[i].name, "B") == 0)
|
||||
push_click(app, t[i].bounds.x + 15.0f, t[i].bounds.y + t[i].bounds.h * 0.5f);
|
||||
}
|
||||
if (g_frames == 72) {
|
||||
SDL_snprintf(line, sizeof line, "clicked: selected %d, B open %d", sel, open[4]);
|
||||
note(line);
|
||||
}
|
||||
if (g_frames > 76) reaktor_quit(app, 0);
|
||||
REAKTOR_FREE(.w = (float)w, .h = (float)h) {
|
||||
reaktor_tree(&(reaktor_tree_spec){ .name = "Tree", .count = 6,
|
||||
.parent = tree_parent, .label = tree_label,
|
||||
.open = open, .selected = &sel,
|
||||
.box = { .w = (float)w, .h = (float)h } });
|
||||
}
|
||||
app->dirty = 1;
|
||||
reaktor_wake(app);
|
||||
}
|
||||
|
||||
static void
|
||||
find_page(App *app, struct nk_context *ctx, int w, int h)
|
||||
{
|
||||
static char *text, run[601];
|
||||
static int len, cap;
|
||||
struct nk_window *pw = nk_window_find(ctx, "page");
|
||||
char line[96];
|
||||
|
||||
if (g_frames == 3) {
|
||||
SDL_memset(run, 'x', 600);
|
||||
run[300] = '\n';
|
||||
press_role(app, REAKTOR_A11Y_TEXTBOX, "Doc");
|
||||
}
|
||||
if (g_frames == 8) push_text(app, run);
|
||||
if (g_frames == 70) {
|
||||
SDL_snprintf(line, sizeof line, "len %d, room %s", len, cap > len ? "kept" : "short");
|
||||
note(line);
|
||||
reaktor_field_select(app, text, 10, 20);
|
||||
}
|
||||
if (g_frames == 84 && pw) {
|
||||
SDL_snprintf(line, sizeof line, "active %d, selected %d to %d", pw->edit.active,
|
||||
pw->edit.sel_start, pw->edit.sel_end);
|
||||
note(line);
|
||||
}
|
||||
if (g_frames > 88) reaktor_quit(app, 0);
|
||||
REAKTOR_FREE(.w = (float)w, .h = (float)h) {
|
||||
reaktor_field(&(reaktor_field_spec){ .heap = &text, .heap_cap = &cap, .len = &len,
|
||||
.name = "Doc", .multiline = 1,
|
||||
.line_numbers = 1,
|
||||
.box = { .w = (float)w, .h = (float)h } });
|
||||
}
|
||||
app->dirty = 1;
|
||||
reaktor_wake(app);
|
||||
}
|
||||
|
||||
static void
|
||||
spin_page(App *app, struct nk_context *ctx, int w, int h)
|
||||
{
|
||||
static const char *const items[] = { "a", "b", "c" };
|
||||
static const SDL_Keycode keys[] = { SDLK_TAB, SDLK_RIGHT, SDLK_UP, SDLK_RIGHT,
|
||||
SDLK_LEFT, SDLK_TAB, SDLK_LEFT };
|
||||
static int one, two;
|
||||
int k = (g_frames - 4) / 6;
|
||||
char line[64];
|
||||
|
||||
(void)ctx;
|
||||
if (g_frames >= 4 && (g_frames - 4) % 6 == 0 && k < (int)SDL_arraysize(keys))
|
||||
push_tap(app, keys[k]);
|
||||
if (g_frames == 50) {
|
||||
SDL_snprintf(line, sizeof line, "stops at %d, wraps to %d", one, two);
|
||||
note(line);
|
||||
}
|
||||
if (g_frames > 54) reaktor_quit(app, 0);
|
||||
REAKTOR_FREE(.w = (float)w, .h = (float)h) {
|
||||
REAKTOR_COLUMN(.w = (float)w) {
|
||||
reaktor_spinner(&(reaktor_spinner_spec){ .name = "One", .items = items,
|
||||
.count = 3, .chosen = &one });
|
||||
reaktor_spinner(&(reaktor_spinner_spec){ .name = "Two", .items = items,
|
||||
.count = 3, .chosen = &two,
|
||||
.wrap = 1 });
|
||||
}
|
||||
}
|
||||
app->dirty = 1;
|
||||
reaktor_wake(app);
|
||||
}
|
||||
|
||||
static void
|
||||
date_page(App *app, struct nk_context *ctx, int w, int h)
|
||||
{
|
||||
static int y, m, d, hh = -1, mm;
|
||||
static const SDL_Keycode keys[] = { SDLK_TAB, SDLK_RETURN, SDLK_DOWN, SDLK_LEFT,
|
||||
SDLK_LEFT, SDLK_DOWN, SDLK_RETURN, SDLK_TAB,
|
||||
SDLK_RETURN, SDLK_UP, SDLK_ESCAPE };
|
||||
int k = (g_frames - 4) / 8;
|
||||
char line[96];
|
||||
|
||||
(void)ctx;
|
||||
if (g_frames >= 4 && (g_frames - 4) % 8 == 0 && k < (int)SDL_arraysize(keys))
|
||||
push_tap(app, keys[k]);
|
||||
if (g_frames == 16) note(d ? "set too early" : "open, not set");
|
||||
if (g_frames == 60) {
|
||||
SDL_snprintf(line, sizeof line, "hour %d, focus on %s", hh, focused_name(app));
|
||||
note(line);
|
||||
}
|
||||
if (g_frames == 100) {
|
||||
SDL_snprintf(line, sizeof line, "after escape: hour %d, focus on %s", hh,
|
||||
focused_name(app));
|
||||
note(line);
|
||||
}
|
||||
if (g_frames > 104) reaktor_quit(app, 0);
|
||||
REAKTOR_FREE(.w = (float)w, .h = (float)h) {
|
||||
REAKTOR_ROW(.w = (float)w, .h = 30.0f) {
|
||||
if (reaktor_date_pick(&(reaktor_date_spec){ .name = "Date", .year = &y,
|
||||
.month = &m, .day = &d })) {
|
||||
SDL_snprintf(line, sizeof line, "set %04d-%02d-%02d", y, m, d);
|
||||
note(line);
|
||||
}
|
||||
reaktor_time_pick(&(reaktor_time_spec){ .name = "Time", .hour = &hh,
|
||||
.minute = &mm });
|
||||
}
|
||||
}
|
||||
app->dirty = 1;
|
||||
reaktor_wake(app);
|
||||
}
|
||||
|
||||
static int g_undo_v;
|
||||
|
||||
static void undo_minus(void *d) { g_undo_v -= *(int *)d; }
|
||||
static void undo_plus(void *d) { g_undo_v += *(int *)d; }
|
||||
|
||||
static void
|
||||
push_chord(App *app, SDL_Keycode key, SDL_Keymod mod)
|
||||
{
|
||||
SDL_Event e;
|
||||
|
||||
SDL_zero(e);
|
||||
e.type = SDL_EVENT_KEY_DOWN;
|
||||
e.key.windowID = SDL_GetWindowID(app->win);
|
||||
e.key.key = key;
|
||||
e.key.mod = mod;
|
||||
e.key.down = true;
|
||||
SDL_PushEvent(&e);
|
||||
e.type = SDL_EVENT_KEY_UP;
|
||||
e.key.down = false;
|
||||
SDL_PushEvent(&e);
|
||||
}
|
||||
|
||||
static void
|
||||
undo_page(App *app)
|
||||
{
|
||||
static int one = 1;
|
||||
char line[128];
|
||||
|
||||
if (g_frames == 2) {
|
||||
reaktor_undo_step s = { "Add", undo_minus, undo_plus, NULL, &one, 0 };
|
||||
|
||||
reaktor_undo_push(app, &s); g_undo_v++;
|
||||
s.label = "Type"; s.merge = 7;
|
||||
reaktor_undo_push(app, &s); g_undo_v++;
|
||||
reaktor_undo_push(app, &s); g_undo_v++;
|
||||
reaktor_undo_group(app, 1);
|
||||
s.label = "Paste"; s.merge = 0;
|
||||
reaktor_undo_push(app, &s); g_undo_v++;
|
||||
reaktor_undo_push(app, &s); g_undo_v++;
|
||||
reaktor_undo_group(app, 0);
|
||||
reaktor_undo_saved(app);
|
||||
}
|
||||
if (g_frames == 6 || g_frames == 12) push_chord(app, SDLK_Z, SDL_KMOD_CTRL);
|
||||
if (g_frames == 18) push_chord(app, SDLK_Z, SDL_KMOD_CTRL | SDL_KMOD_SHIFT);
|
||||
if (g_frames == 4 || g_frames == 16 || g_frames == 24) {
|
||||
SDL_snprintf(line, sizeof line, "value %d, undo %s, redo %s, %s", g_undo_v,
|
||||
reaktor_undo_label(app) ? reaktor_undo_label(app) : "-",
|
||||
reaktor_redo_label(app) ? reaktor_redo_label(app) : "-",
|
||||
reaktor_undo_dirty(app) ? "changed" : "saved");
|
||||
note(line);
|
||||
}
|
||||
if (g_frames > 28) reaktor_quit(app, 0);
|
||||
app->dirty = 1;
|
||||
reaktor_wake(app);
|
||||
}
|
||||
|
||||
static void
|
||||
print_body(App *app, struct nk_context *ctx, int index, int w, int h, void *user)
|
||||
{
|
||||
char line[48];
|
||||
|
||||
(void)app; (void)ctx; (void)user;
|
||||
SDL_snprintf(line, sizeof line, "Page %d of 2", index + 1);
|
||||
REAKTOR_FREE(.w = (float)w, .h = (float)h) {
|
||||
REAKTOR_COLUMN(.w = (float)w, .gap = 12.0f, .ml = 48.0f, .mt = 48.0f) {
|
||||
reaktor_label(&(reaktor_label_spec){ .text = line, .style = "h4" });
|
||||
reaktor_label(&(reaktor_label_spec){
|
||||
.text = "Printed by Reaktor: the same layout and pixels as on screen." });
|
||||
reaktor_button(&(reaktor_button_spec){ .label = "A button on paper",
|
||||
.box = { .w = 180.0f } });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
printed(App *app, int ok, void *user)
|
||||
{
|
||||
(void)app;
|
||||
note(ok ? "printed" : "print failed");
|
||||
(void)user;
|
||||
}
|
||||
|
||||
static void
|
||||
print_page_test(App *app)
|
||||
{
|
||||
if (g_frames == 3) {
|
||||
char *pdf = NULL;
|
||||
|
||||
if (SDL_asprintf(&pdf, "%s.pdf", g_log ? g_log : "launchtest-print") < 0 ||
|
||||
!reaktor_print_pdf(app, pdf,
|
||||
&(reaktor_print_spec){ .title = "Test", .pages = 2,
|
||||
.page = print_body, .done = printed }))
|
||||
note("not queued");
|
||||
SDL_free(pdf);
|
||||
}
|
||||
if (g_frames > 40) reaktor_quit(app, 0);
|
||||
app->dirty = 1;
|
||||
reaktor_wake(app);
|
||||
}
|
||||
|
||||
static void
|
||||
confirm_page(App *app)
|
||||
{
|
||||
@@ -835,6 +1178,34 @@ page(App *app, struct nk_context *ctx, int w, int h)
|
||||
}
|
||||
if (is("confirm") || is("confirm-cancel")) confirm_page(app);
|
||||
if (SDL_strncmp(g_mode, "dialog-", 7) == 0) dialog_page(app);
|
||||
if (is("print-pdf")) {
|
||||
print_page_test(app);
|
||||
return;
|
||||
}
|
||||
if (is("undo")) {
|
||||
undo_page(app);
|
||||
return;
|
||||
}
|
||||
if (is("date-keys")) {
|
||||
date_page(app, ctx, w, h);
|
||||
return;
|
||||
}
|
||||
if (is("spin-keys")) {
|
||||
spin_page(app, ctx, w, h);
|
||||
return;
|
||||
}
|
||||
if (is("field-find")) {
|
||||
find_page(app, ctx, w, h);
|
||||
return;
|
||||
}
|
||||
if (is("tree-keys")) {
|
||||
tree_page(app, ctx, w, h);
|
||||
return;
|
||||
}
|
||||
if (is("menu-keys")) {
|
||||
menu_page(app, ctx, w, h);
|
||||
return;
|
||||
}
|
||||
if (SDL_strncmp(g_mode, "hold-", 5) == 0) {
|
||||
hold_page(app, ctx, w, h);
|
||||
return;
|
||||
|
||||
@@ -10,7 +10,7 @@ copy() {
|
||||
}
|
||||
|
||||
for f in assets/fonts/MPLUS1p-Regular.ttf assets/fonts/MPLUS1p-Notice.txt \
|
||||
assets/fonts/Aileron-Notice.txt external/simplecss/simple.css; do
|
||||
assets/fonts/Aileron-Notice.txt external/bamboocss/dist/bamboo.min.css; do
|
||||
copy "$f"
|
||||
done
|
||||
for f in "$root"/assets/locale/*.txt; do
|
||||
|
||||
@@ -19,6 +19,6 @@ fi
|
||||
: >"$dest/.reaktor-root"
|
||||
sh "$root/tools/assets.sh" "$root" "$dest"
|
||||
cp "$build/licenses/"*.txt "$dest/licenses/"
|
||||
cp "$root/external/simplecss/LICENSE" "$dest/licenses/simplecss.txt"
|
||||
cp "$root/external/bamboocss/LICENSE" "$dest/licenses/bamboocss.txt"
|
||||
cp "$root/docs/NOTICE.md" "$dest/"
|
||||
echo "packaged: $dest"
|
||||
|
||||