Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c42bdfe540 | ||
|
|
61534c087c | ||
|
|
b945683c42 | ||
|
|
9a6e59120b | ||
|
|
0d12e4d0d9 | ||
|
|
22489b65bd | ||
|
|
96e5641971 | ||
|
|
55dca9f496 | ||
|
|
e02539ea7b |
@@ -96,7 +96,7 @@ jobs:
|
||||
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
|
||||
run: |
|
||||
fail=0
|
||||
for t in onlaytest keytest a11ytest animtest localetest laytest texttest; do
|
||||
for t in onlaytest keytest a11ytest animtest localetest laytest texttest csstest; do
|
||||
echo "== $t"
|
||||
if ./build/$t </dev/null; then :; else echo "$t: exit status $?"; fail=1; fi
|
||||
done
|
||||
|
||||
@@ -86,7 +86,7 @@ jobs:
|
||||
run: |
|
||||
docker exec -i debian sh -u <<'EOF'
|
||||
fail=0
|
||||
for t in onlaytest keytest a11ytest animtest localetest laytest texttest; do
|
||||
for t in onlaytest keytest a11ytest animtest localetest laytest texttest csstest; do
|
||||
echo "== $t"
|
||||
if ./build/$t </dev/null; then :; else echo "$t: exit status $?"; fail=1; fi
|
||||
done
|
||||
@@ -191,6 +191,23 @@ jobs:
|
||||
tar -C dist -czf "dist/$name.tar.gz" "$name"
|
||||
EOF
|
||||
|
||||
- name: Check an app that embeds Reaktor
|
||||
if: ${{ !cancelled() && steps.build.outcome == 'success' && matrix.arch == 'x86-64' }}
|
||||
run: |
|
||||
docker exec -i debian sh -eu <<'EOF'
|
||||
cmake -S examples/embedded -B build-embedded -G Ninja -DCMAKE_BUILD_TYPE=Release </dev/null
|
||||
cmake --build build-embedded --target simple </dev/null
|
||||
mkdir -p check
|
||||
for from in "tree build/simple" "embedded build-embedded/simple"; do
|
||||
set -- $from
|
||||
timeout 600 dbus-run-session -- "$2" --theme light --video dummy \
|
||||
--shot "check/$1.bmp" --a11y-dump "check/$1.txt" </dev/null
|
||||
done
|
||||
for e in bmp txt; do
|
||||
cmp "check/tree.$e" "check/embedded.$e"
|
||||
done
|
||||
EOF
|
||||
|
||||
- name: Upload libreaktor
|
||||
if: ${{ !cancelled() && steps.libcheck.outcome == 'success' }}
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
|
||||
@@ -55,7 +55,7 @@ jobs:
|
||||
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
|
||||
run: |
|
||||
fail=0
|
||||
for t in onlaytest keytest a11ytest animtest localetest laytest texttest; do
|
||||
for t in onlaytest keytest a11ytest animtest localetest laytest texttest csstest; do
|
||||
echo "== $t"
|
||||
if ./build/$t </dev/null; then :; else echo "$t: exit status $?"; fail=1; fi
|
||||
done
|
||||
@@ -152,6 +152,21 @@ jobs:
|
||||
done
|
||||
ditto -c -k --keepParent "dist/$name" "dist/$name.zip"
|
||||
|
||||
- name: Check an app that embeds Reaktor
|
||||
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
|
||||
run: |
|
||||
cmake -S examples/embedded -B build-embedded -G Ninja -DCMAKE_BUILD_TYPE=Release </dev/null
|
||||
cmake --build build-embedded --target simple </dev/null
|
||||
mkdir -p check
|
||||
for from in "tree build/simple" "embedded build-embedded/simple"; do
|
||||
set -- $from
|
||||
"$2" --theme light --video dummy \
|
||||
--shot "check/$1.bmp" --a11y-dump "check/$1.txt" </dev/null
|
||||
done
|
||||
for e in bmp txt; do
|
||||
cmp "check/tree.$e" "check/embedded.$e"
|
||||
done
|
||||
|
||||
- name: Upload libreaktor
|
||||
if: ${{ !cancelled() && steps.libcheck.outcome == 'success' }}
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
|
||||
@@ -48,7 +48,7 @@ jobs:
|
||||
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
|
||||
run: |
|
||||
$fail = 0
|
||||
foreach ($t in 'onlaytest', 'keytest', 'a11ytest', 'animtest', 'localetest', 'laytest', 'texttest') {
|
||||
foreach ($t in 'onlaytest', 'keytest', 'a11ytest', 'animtest', 'localetest', 'laytest', 'texttest', 'csstest') {
|
||||
Write-Host "== $t"
|
||||
& "./${{ matrix.out }}/$t.exe"
|
||||
if ($LASTEXITCODE -ne 0) { Write-Host "${t}: exit status $LASTEXITCODE"; $fail = 1 }
|
||||
|
||||
@@ -11,6 +11,7 @@ build-x86/
|
||||
build-arm64/
|
||||
build-lib/
|
||||
build-consumer/
|
||||
build-embedded/
|
||||
.claude/settings.local.json
|
||||
.dart_tool/
|
||||
.gradle/
|
||||
|
||||
@@ -57,8 +57,9 @@ regression oracle for every layout or style change.
|
||||
- **A one-pixel stroke is two pixels here.** `nk_stroke_rect` casts its rect to
|
||||
`short`, so a half-pixel inset never reaches the draw list, and with line
|
||||
anti-aliasing on a stroke of thickness one is always two half-alpha rows.
|
||||
A border is `reaktor_edge_round`: fills for its runs, a ring mask for its
|
||||
corners, inside the box.
|
||||
A border is `reaktor_edge_round`, inside the box: a ring mask for its
|
||||
corners, and its runs cut from the mask's middle texels, which hold a
|
||||
straight band so a run is sharp and as thick as its corners at any scale.
|
||||
- **A rounded fill is jagged unless it is a mask.** Fill anti-aliasing is off
|
||||
on every renderer, so a fill with corners goes through `reaktor_fill_round`,
|
||||
and `reaktor_render` swaps each one Nuklear drew itself for masks, relinking
|
||||
|
||||
+14
-4
@@ -1,5 +1,5 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(reaktor VERSION 0.3.0 LANGUAGES C CXX)
|
||||
project(reaktor VERSION 0.4.0 LANGUAGES C CXX)
|
||||
|
||||
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
||||
set(_reaktor_top ON)
|
||||
@@ -239,6 +239,12 @@ if(REAKTOR_TESTS AND NOT EMSCRIPTEN)
|
||||
target_link_libraries(laytest PRIVATE onlay)
|
||||
set_target_properties(laytest PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
|
||||
|
||||
add_executable(csstest tools/csstest.c core/css/cssflat.c)
|
||||
target_include_directories(csstest PRIVATE core/css core/base)
|
||||
target_compile_definitions(csstest PRIVATE _CRT_SECURE_NO_WARNINGS)
|
||||
set_target_properties(csstest PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
|
||||
endif()
|
||||
|
||||
if(WIN32 AND NOT EMSCRIPTEN)
|
||||
@@ -293,11 +299,15 @@ elseif(WIN32)
|
||||
"${_a11y}/a11y_snapshot.c" "${_a11y}/a11y_win32.c")
|
||||
target_link_libraries(reaktor_a11y INTERFACE uiautomationcore ole32 oleaut32)
|
||||
elseif(APPLE)
|
||||
# Compiled here: an interface library's sources compile in the directory
|
||||
# of whoever links it, where Objective-C may not be enabled.
|
||||
enable_language(OBJC)
|
||||
add_library(reaktor_a11y_macos OBJECT "${_a11y}/a11y_macos.m")
|
||||
target_compile_options(reaktor_a11y_macos PRIVATE -fobjc-arc)
|
||||
target_compile_definitions(reaktor_a11y_macos PRIVATE REAKTOR_HAVE_NSACCESSIBILITY)
|
||||
target_link_libraries(reaktor_a11y_macos PRIVATE reaktor_runtime)
|
||||
target_sources(reaktor_a11y INTERFACE
|
||||
"${_a11y}/a11y_snapshot.c" "${_a11y}/a11y_macos.m")
|
||||
set_source_files_properties("${_a11y}/a11y_macos.m" PROPERTIES
|
||||
COMPILE_OPTIONS "-fobjc-arc")
|
||||
"${_a11y}/a11y_snapshot.c" "$<TARGET_OBJECTS:reaktor_a11y_macos>")
|
||||
target_compile_definitions(reaktor_a11y INTERFACE REAKTOR_HAVE_NSACCESSIBILITY)
|
||||
target_link_libraries(reaktor_a11y INTERFACE "-framework Cocoa")
|
||||
else()
|
||||
|
||||
@@ -39,8 +39,6 @@ void reaktor_free(void *p);
|
||||
|
||||
void reaktor_release_free_memory(void);
|
||||
|
||||
#define REAKTOR_BRAND "#6b4ee6"
|
||||
|
||||
#define REAKTOR_MARK "assets/icons/reaktor-icon.svg"
|
||||
|
||||
#endif
|
||||
|
||||
+172
-10
@@ -423,6 +423,111 @@ static void convert_units(const char *s, size_t len, float rem_px, float em_px,
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct calc_val { double v; int px; } calc_val;
|
||||
typedef struct calc_in { const char *s; size_t i, n; } calc_in;
|
||||
|
||||
static void calc_space(calc_in *c)
|
||||
{
|
||||
while (c->i < c->n && isspace((unsigned char)c->s[c->i])) c->i++;
|
||||
}
|
||||
|
||||
static int calc_sum(calc_in *c, calc_val *out);
|
||||
|
||||
static int calc_atom(calc_in *c, calc_val *out)
|
||||
{
|
||||
char *end;
|
||||
|
||||
calc_space(c);
|
||||
if (c->i < c->n && c->s[c->i] == '-') {
|
||||
c->i++;
|
||||
if (!calc_atom(c, out)) return 0;
|
||||
out->v = -out->v;
|
||||
return 1;
|
||||
}
|
||||
if (c->i + 5 <= c->n && strncmp(c->s + c->i, "calc(", 5) == 0) c->i += 4;
|
||||
if (c->i < c->n && c->s[c->i] == '(') {
|
||||
c->i++;
|
||||
if (!calc_sum(c, out)) return 0;
|
||||
calc_space(c);
|
||||
if (c->i >= c->n || c->s[c->i] != ')') return 0;
|
||||
c->i++;
|
||||
return 1;
|
||||
}
|
||||
if (c->i >= c->n || (!isdigit((unsigned char)c->s[c->i]) && c->s[c->i] != '.'))
|
||||
return 0;
|
||||
out->v = strtod(c->s + c->i, &end);
|
||||
c->i = (size_t)(end - c->s);
|
||||
out->px = c->i + 2 <= c->n && strncmp(c->s + c->i, "px", 2) == 0;
|
||||
if (out->px) c->i += 2;
|
||||
return c->i >= c->n || !(isalpha((unsigned char)c->s[c->i]) || c->s[c->i] == '%');
|
||||
}
|
||||
|
||||
static int calc_product(calc_in *c, calc_val *out)
|
||||
{
|
||||
calc_val r;
|
||||
char op;
|
||||
|
||||
if (!calc_atom(c, out)) return 0;
|
||||
for (;;) {
|
||||
calc_space(c);
|
||||
if (c->i >= c->n || (c->s[c->i] != '*' && c->s[c->i] != '/')) return 1;
|
||||
op = c->s[c->i++];
|
||||
if (!calc_atom(c, &r)) return 0;
|
||||
if (op == '*') {
|
||||
if (out->px && r.px) return 0;
|
||||
out->v *= r.v;
|
||||
out->px |= r.px;
|
||||
} else {
|
||||
if (r.px || r.v == 0.0) return 0;
|
||||
out->v /= r.v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int calc_sum(calc_in *c, calc_val *out)
|
||||
{
|
||||
calc_val r;
|
||||
char op;
|
||||
|
||||
if (!calc_product(c, out)) return 0;
|
||||
for (;;) {
|
||||
calc_space(c);
|
||||
if (c->i >= c->n || (c->s[c->i] != '+' && c->s[c->i] != '-')) return 1;
|
||||
op = c->s[c->i++];
|
||||
if (!calc_product(c, &r) || r.px != out->px) return 0;
|
||||
out->v += op == '+' ? r.v : -r.v;
|
||||
}
|
||||
}
|
||||
|
||||
/* calc() over pixels and plain numbers; one with any other unit is left. */
|
||||
static void calc_values(buf *b)
|
||||
{
|
||||
static const char fn[] = "calc(";
|
||||
size_t from = 0;
|
||||
char *at;
|
||||
|
||||
while (b->p && (at = strstr(b->p + from, fn))) {
|
||||
size_t s = (size_t)(at - b->p);
|
||||
calc_in c;
|
||||
calc_val v;
|
||||
char out[64];
|
||||
buf r;
|
||||
|
||||
c.s = b->p;
|
||||
c.i = s;
|
||||
c.n = b->len;
|
||||
if (!calc_atom(&c, &v)) { from = s + 1; continue; }
|
||||
snprintf(out, sizeof(out), v.px ? "%gpx" : "%g", v.v);
|
||||
memset(&r, 0, sizeof(r));
|
||||
buf_add(&r, b->p, s);
|
||||
buf_str(&r, out);
|
||||
buf_add(&r, b->p + c.i, b->len - c.i);
|
||||
free(b->p);
|
||||
*b = r;
|
||||
from = s + strlen(out);
|
||||
}
|
||||
}
|
||||
|
||||
static void strip_comments(char *s)
|
||||
{
|
||||
char *r = s, *w = s;
|
||||
@@ -446,12 +551,32 @@ static void trim(const char *s, size_t *start, size_t *end)
|
||||
while (*end > *start && isspace((unsigned char)s[*end - 1])) (*end)--;
|
||||
}
|
||||
|
||||
/* Every widget that asks is enabled; a disabled one asks for :disabled. */
|
||||
static int enabled_at(const char *s, size_t len, size_t i)
|
||||
{
|
||||
return len - i >= 8 && memcmp(s + i, ":enabled", 8) == 0 &&
|
||||
(i + 8 == len || !(isalnum((unsigned char)s[i + 8]) || s[i + 8] == '-'));
|
||||
}
|
||||
|
||||
static int names_enabled(const char *s, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
if (enabled_at(s, len, i)) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static size_t selector_rewrite(const char *s, size_t len, char *out,
|
||||
size_t cap)
|
||||
{
|
||||
size_t i = 0, n = 0;
|
||||
|
||||
while (i < len) {
|
||||
if (enabled_at(s, len, i)) {
|
||||
i += 8;
|
||||
continue;
|
||||
}
|
||||
if (s[i] != '[') {
|
||||
if (n + 1 >= cap) return 0;
|
||||
out[n++] = s[i++];
|
||||
@@ -461,7 +586,15 @@ static size_t selector_rewrite(const char *s, size_t len, char *out,
|
||||
size_t j = i + 1, eq, ve, vs;
|
||||
|
||||
while (j < len && s[j] != ']' && s[j] != '=') j++;
|
||||
if (j >= len || s[j] != '=') return 0;
|
||||
if (j >= len) return 0;
|
||||
if (s[j] == ']') {
|
||||
if (j == i + 1 || n + 1 + (j - i - 1) >= cap) return 0;
|
||||
out[n++] = '.';
|
||||
memcpy(out + n, s + i + 1, j - i - 1);
|
||||
n += j - i - 1;
|
||||
i = j + 1;
|
||||
continue;
|
||||
}
|
||||
if (j > i + 1 && strchr("^$*|~", s[j - 1])) return 0;
|
||||
eq = j;
|
||||
vs = eq + 1;
|
||||
@@ -501,6 +634,32 @@ static int selector_unsupported(const char *s, size_t len)
|
||||
return len == 0;
|
||||
}
|
||||
|
||||
static int name_start(char c) { return c == '.' || c == ':' || c == '#'; }
|
||||
|
||||
static size_t name_end(const char *s, size_t i, size_t len)
|
||||
{
|
||||
for (i++; i < len && !name_start(s[i]) && !isspace((unsigned char)s[i]); i++) {}
|
||||
return i;
|
||||
}
|
||||
|
||||
/* LCUI goes on using a node's list after freeing it when one compound names
|
||||
* the same class or pseudo-class twice - as two :not() do, read its way. */
|
||||
static int selector_repeats(const char *s, size_t len)
|
||||
{
|
||||
size_t a, ae, b, be;
|
||||
|
||||
for (a = 0; a < len; a = ae) {
|
||||
if (!name_start(s[a])) { ae = a + 1; continue; }
|
||||
ae = name_end(s, a, len);
|
||||
for (b = ae; b < len && !isspace((unsigned char)s[b]); b = be) {
|
||||
if (!name_start(s[b])) { be = b + 1; continue; }
|
||||
be = name_end(s, b, len);
|
||||
if (be - b == ae - a && memcmp(s + a, s + b, ae - a) == 0) return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int is_theme_selector(const char *s, size_t len, const char *theme)
|
||||
{
|
||||
char want[64];
|
||||
@@ -663,6 +822,7 @@ static void emit_one(void *c, const char *p, size_t plen,
|
||||
} else {
|
||||
convert_units(tmp.p ? tmp.p : "", tmp.len,
|
||||
ctx->rem_px, ctx->em_px, &conv);
|
||||
calc_values(&conv);
|
||||
}
|
||||
|
||||
buf_add(ctx->out, p, plen);
|
||||
@@ -835,17 +995,19 @@ static char *flatten(char *src, const char *theme, reaktor_cssvars **out_vars)
|
||||
if (part < sel_e) part++;
|
||||
trim(src, &ps, &pe);
|
||||
if (selector_unsupported(src + ps, pe - ps)) continue;
|
||||
if (memchr(src + ps, '[', pe - ps)) {
|
||||
char rw[256];
|
||||
size_t rn = selector_rewrite(src + ps, pe - ps,
|
||||
rw, sizeof(rw));
|
||||
{
|
||||
char rw[256];
|
||||
const char *t = src + ps;
|
||||
size_t tn = pe - ps;
|
||||
|
||||
if (!rn) continue;
|
||||
if (memchr(t, '[', tn) || names_enabled(t, tn)) {
|
||||
tn = selector_rewrite(t, tn, rw, sizeof(rw));
|
||||
t = rw;
|
||||
if (!tn) continue;
|
||||
}
|
||||
if (selector_repeats(t, tn)) continue;
|
||||
if (n_emitted) buf_str(&sel, ", ");
|
||||
buf_add(&sel, rw, rn);
|
||||
} else {
|
||||
if (n_emitted) buf_str(&sel, ", ");
|
||||
buf_add(&sel, src + ps, pe - ps);
|
||||
buf_add(&sel, t, tn);
|
||||
}
|
||||
n_emitted++;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ static struct {
|
||||
reaktor_cssvars *vars;
|
||||
css_computed_style_t root;
|
||||
int root_ready;
|
||||
unsigned generation;
|
||||
} g;
|
||||
|
||||
static void rgba_of(css_color_value_t c, unsigned char out[4])
|
||||
@@ -64,6 +65,7 @@ static int style_load(const char *const *css_paths, int count,
|
||||
css_init_library();
|
||||
}
|
||||
g.cache_n = 0;
|
||||
g.generation++;
|
||||
base_reset();
|
||||
|
||||
reaktor_cssvars_free(g.vars);
|
||||
@@ -132,6 +134,11 @@ void reaktor_style_shutdown(void)
|
||||
g.cache_n = 0;
|
||||
}
|
||||
|
||||
unsigned reaktor_style_generation(void)
|
||||
{
|
||||
return g.generation;
|
||||
}
|
||||
|
||||
int reaktor_style_token(const char *name, unsigned char rgba[4])
|
||||
{
|
||||
return reaktor_cssvars_color(g.vars, name, rgba);
|
||||
@@ -159,6 +166,7 @@ static void resolve(const char *selector, reaktor_style *out)
|
||||
css_computed_style_t computed;
|
||||
|
||||
memset(out, 0, sizeof(*out));
|
||||
out->opacity = 1.0f;
|
||||
if (!g.ready || !selector) return;
|
||||
|
||||
sel = css_selector_create(selector);
|
||||
@@ -235,6 +243,11 @@ static void resolve(const char *selector, reaktor_style *out)
|
||||
out->max_height = px_of(computed.max_height,
|
||||
computed.unit_bits.max_height);
|
||||
|
||||
out->opacity = computed.type_bits.opacity == CSS_OPACITY_SET
|
||||
? computed.opacity : 1.0f;
|
||||
if (out->opacity < 0.0f) out->opacity = 0.0f;
|
||||
if (out->opacity > 1.0f) out->opacity = 1.0f;
|
||||
|
||||
out->line_height = 0.0f;
|
||||
switch (computed.type_bits.line_height) {
|
||||
case CSS_LINE_HEIGHT_NUMBER: {
|
||||
|
||||
@@ -6,5 +6,7 @@
|
||||
int reaktor_style_init(const char *const *css_paths, int count,
|
||||
const char *theme);
|
||||
void reaktor_style_shutdown(void);
|
||||
/* Counts loads, so a layout can tell its sizes come from an older sheet. */
|
||||
unsigned reaktor_style_generation(void);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -264,6 +264,18 @@ round_mask(App *app, int r, int t)
|
||||
p[3] = (unsigned char)((hit * 255) / (ss * ss));
|
||||
}
|
||||
}
|
||||
/* A border's straight runs are cut from the middle texels, which sit
|
||||
* half a texel off the arc's apex, so they carry the straight band. */
|
||||
if (t > 0) {
|
||||
for (y = 0; y < d; y++)
|
||||
for (x = r - 1; x <= r; x++)
|
||||
px[(size_t)y * surf->pitch + x * 4 + 3] =
|
||||
y < t || y >= d - t ? 255 : 0;
|
||||
for (x = 0; x < d; x++)
|
||||
for (y = r - 1; y <= r; y++)
|
||||
px[(size_t)y * surf->pitch + x * 4 + 3] =
|
||||
x < t || x >= d - t ? 255 : 0;
|
||||
}
|
||||
tex = SDL_CreateTextureFromSurface(app->ren, surf);
|
||||
SDL_DestroySurface(surf);
|
||||
}
|
||||
@@ -363,6 +375,74 @@ reaktor_render(App *app)
|
||||
? NK_ANTI_ALIASING_ON : NK_ANTI_ALIASING_OFF);
|
||||
}
|
||||
|
||||
/* The last command so far, or none: what reaktor_fade_since starts after. */
|
||||
nk_size
|
||||
reaktor_fade_mark(const struct nk_command_buffer *cv)
|
||||
{
|
||||
return cv->begin == cv->end ? (nk_size)-1 : cv->last;
|
||||
}
|
||||
|
||||
static void
|
||||
fade(struct nk_color *c, float opacity)
|
||||
{
|
||||
c->a = (nk_byte)((float)c->a * opacity + 0.5f);
|
||||
}
|
||||
|
||||
/* Every command drawn since the mark, at the opacity a rule gave it. */
|
||||
void
|
||||
reaktor_fade_since(struct nk_context *ctx, const struct nk_command_buffer *cv,
|
||||
nk_size mark, float opacity)
|
||||
{
|
||||
nk_byte *base = (nk_byte *)ctx->memory.memory.ptr;
|
||||
nk_size at;
|
||||
|
||||
if (cv->begin == cv->end || cv->last == mark) return;
|
||||
at = mark == (nk_size)-1 ? cv->begin
|
||||
: ((const struct nk_command *)(base + mark))->next;
|
||||
for (;;) {
|
||||
struct nk_command *c = (struct nk_command *)(base + at);
|
||||
|
||||
switch (c->type) {
|
||||
case NK_COMMAND_LINE: fade(&((struct nk_command_line *)c)->color, opacity); break;
|
||||
case NK_COMMAND_CURVE: fade(&((struct nk_command_curve *)c)->color, opacity); break;
|
||||
case NK_COMMAND_RECT: fade(&((struct nk_command_rect *)c)->color, opacity); break;
|
||||
case NK_COMMAND_RECT_FILLED:
|
||||
fade(&((struct nk_command_rect_filled *)c)->color, opacity); break;
|
||||
case NK_COMMAND_RECT_MULTI_COLOR: {
|
||||
struct nk_command_rect_multi_color *m = (struct nk_command_rect_multi_color *)c;
|
||||
fade(&m->left, opacity); fade(&m->top, opacity);
|
||||
fade(&m->right, opacity); fade(&m->bottom, opacity);
|
||||
break;
|
||||
}
|
||||
case NK_COMMAND_CIRCLE: fade(&((struct nk_command_circle *)c)->color, opacity); break;
|
||||
case NK_COMMAND_CIRCLE_FILLED:
|
||||
fade(&((struct nk_command_circle_filled *)c)->color, opacity); break;
|
||||
case NK_COMMAND_ARC: fade(&((struct nk_command_arc *)c)->color, opacity); break;
|
||||
case NK_COMMAND_ARC_FILLED:
|
||||
fade(&((struct nk_command_arc_filled *)c)->color, opacity); break;
|
||||
case NK_COMMAND_TRIANGLE:
|
||||
fade(&((struct nk_command_triangle *)c)->color, opacity); break;
|
||||
case NK_COMMAND_TRIANGLE_FILLED:
|
||||
fade(&((struct nk_command_triangle_filled *)c)->color, opacity); break;
|
||||
case NK_COMMAND_POLYGON:
|
||||
fade(&((struct nk_command_polygon *)c)->color, opacity); break;
|
||||
case NK_COMMAND_POLYGON_FILLED:
|
||||
fade(&((struct nk_command_polygon_filled *)c)->color, opacity); break;
|
||||
case NK_COMMAND_POLYLINE:
|
||||
fade(&((struct nk_command_polyline *)c)->color, opacity); break;
|
||||
case NK_COMMAND_TEXT: {
|
||||
struct nk_command_text *t = (struct nk_command_text *)c;
|
||||
fade(&t->background, opacity); fade(&t->foreground, opacity);
|
||||
break;
|
||||
}
|
||||
case NK_COMMAND_IMAGE: fade(&((struct nk_command_image *)c)->col, opacity); break;
|
||||
default: break;
|
||||
}
|
||||
if (at == cv->last) break;
|
||||
at = c->next;
|
||||
}
|
||||
}
|
||||
|
||||
struct nk_rect
|
||||
reaktor_rect_trunc(struct nk_rect b)
|
||||
{
|
||||
|
||||
+74
-17
@@ -21,6 +21,7 @@ static float g_ox, g_oy;
|
||||
static struct nk_rect g_boxrect[REAKTOR_LAY_DEPTH + 1];
|
||||
static unsigned char g_boxok[REAKTOR_LAY_DEPTH + 1];
|
||||
static unsigned g_boxid[REAKTOR_LAY_DEPTH + 1];
|
||||
static unsigned char g_boxdir[REAKTOR_LAY_DEPTH + 1];
|
||||
|
||||
void
|
||||
reaktor_frame_begin(App *app, struct nk_context *ctx, struct nk_rect area)
|
||||
@@ -43,6 +44,11 @@ reaktor_frame_end(void)
|
||||
if (g_space) { nk_layout_space_end(g_ctx); g_space = 0; }
|
||||
reaktor_layout_end(&g_app->lay);
|
||||
|
||||
/* This frame's rectangles were laid out with the sizes of an older sheet. */
|
||||
if (g_app->style_gen != reaktor_style_generation()) {
|
||||
g_app->style_gen = reaktor_style_generation();
|
||||
g_unsettled++;
|
||||
}
|
||||
g_app->settled_run = g_unsettled ? 0 : g_app->settled_run + 1;
|
||||
if (!g_unsettled) {
|
||||
g_app->settle_tries = 0;
|
||||
@@ -107,7 +113,10 @@ reaktor_box_open(unsigned char dir, const reaktor_box *b)
|
||||
id = reaktor_note_push(g_app, REAKTOR_A11Y_GROUP, box.name, NULL, 0u,
|
||||
nk_rect(0, 0, 0, 0));
|
||||
reaktor_layout_open(&g_app->lay, id, &box);
|
||||
if (g_depth < REAKTOR_LAY_DEPTH) g_boxid[g_depth + 1] = id;
|
||||
if (g_depth < REAKTOR_LAY_DEPTH) {
|
||||
g_boxid[g_depth + 1] = id;
|
||||
g_boxdir[g_depth + 1] = dir;
|
||||
}
|
||||
|
||||
if (g_widths < (int)(sizeof(g_width) / sizeof(g_width[0]))) {
|
||||
float w = box.w > 0.0f ? box.w : g_width[g_widths - 1];
|
||||
@@ -328,10 +337,28 @@ box_from_style(reaktor_box *box, const char *text, const char *selector,
|
||||
}
|
||||
|
||||
if (st.matched) {
|
||||
if (box->mt <= 0.0f) box->mt = st.margin[REAKTOR_SIDE_TOP];
|
||||
if (box->mr <= 0.0f) box->mr = st.margin[REAKTOR_SIDE_RIGHT];
|
||||
if (box->mb <= 0.0f) box->mb = st.margin[REAKTOR_SIDE_BOTTOM];
|
||||
if (box->ml <= 0.0f) box->ml = st.margin[REAKTOR_SIDE_LEFT];
|
||||
/* A rule's margin parts a widget from its neighbors along its row or
|
||||
* column; across it, the page has sized the box. */
|
||||
unsigned char dir = g_depth > 0 && g_depth <= REAKTOR_LAY_DEPTH
|
||||
? g_boxdir[g_depth] : REAKTOR_LAY_COLUMN;
|
||||
int down = dir != REAKTOR_LAY_ROW, across = dir != REAKTOR_LAY_COLUMN;
|
||||
|
||||
if (box->mt <= 0.0f && down) {
|
||||
box->mt = st.margin[REAKTOR_SIDE_TOP];
|
||||
box->flags |= REAKTOR_LAY_SHEET_T;
|
||||
}
|
||||
if (box->mr <= 0.0f && across) {
|
||||
box->mr = st.margin[REAKTOR_SIDE_RIGHT];
|
||||
box->flags |= REAKTOR_LAY_SHEET_R;
|
||||
}
|
||||
if (box->mb <= 0.0f && down) {
|
||||
box->mb = st.margin[REAKTOR_SIDE_BOTTOM];
|
||||
box->flags |= REAKTOR_LAY_SHEET_B;
|
||||
}
|
||||
if (box->ml <= 0.0f && across) {
|
||||
box->ml = st.margin[REAKTOR_SIDE_LEFT];
|
||||
box->flags |= REAKTOR_LAY_SHEET_L;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -390,14 +417,32 @@ reaktor_soak(void)
|
||||
(void)place(REAKTOR_A11Y_NONE, NULL, NULL, 0u, NULL, &box, NULL);
|
||||
}
|
||||
|
||||
/* A disabled button wears its sheet's :disabled rule at that rule's opacity;
|
||||
* one the sheet does not tell apart is faded by half. */
|
||||
static float
|
||||
disabled_opacity(const char *sel, const char *dsel)
|
||||
{
|
||||
reaktor_style on, off;
|
||||
|
||||
reaktor_style_get(sel, &on);
|
||||
reaktor_style_get(dsel, &off);
|
||||
if (!off.matched) return 0.5f;
|
||||
if (off.opacity < 1.0f) return off.opacity;
|
||||
return memcmp(on.bg, off.bg, 4) || memcmp(on.fg, off.fg, 4) ||
|
||||
memcmp(on.border_col, off.border_col, 4) ? 1.0f : 0.5f;
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_button(const reaktor_button_spec *s)
|
||||
{
|
||||
reaktor_box box;
|
||||
struct nk_rect r;
|
||||
const char *sel;
|
||||
char dsel[96];
|
||||
unsigned id = 0;
|
||||
int hit, styled, fitted;
|
||||
float fade = 1.0f;
|
||||
nk_size mark = 0;
|
||||
|
||||
if (!g_app || !s) return 0;
|
||||
box = s->box;
|
||||
@@ -415,9 +460,17 @@ reaktor_button(const reaktor_button_spec *s)
|
||||
r = nk_widget_bounds(g_ctx);
|
||||
|
||||
sel = rule_or(s->style, "button");
|
||||
if (s->disabled) {
|
||||
SDL_snprintf(dsel, sizeof(dsel), "%s.disabled:disabled", sel);
|
||||
fade = disabled_opacity(sel, dsel);
|
||||
sel = dsel;
|
||||
}
|
||||
styled = push_style_font(s->style);
|
||||
if (s->repeat) nk_button_set_behavior(g_ctx, NK_BUTTON_REPEATER);
|
||||
if (s->disabled) nk_widget_disable_begin(g_ctx);
|
||||
if (s->disabled) {
|
||||
nk_widget_disable_begin(g_ctx);
|
||||
mark = reaktor_fade_mark(nk_window_get_canvas(g_ctx));
|
||||
}
|
||||
fitted = reaktor_fit_label(g_app, g_ctx, r);
|
||||
reaktor_note_mute(g_app, 1);
|
||||
if (s->icon && !s->label) {
|
||||
@@ -428,13 +481,17 @@ reaktor_button(const reaktor_button_spec *s)
|
||||
px, s->name);
|
||||
} else if (s->icon)
|
||||
hit = reaktor_button_icon_as(g_app, g_ctx, sel, s->icon, s->label);
|
||||
else if (s->accent)
|
||||
else if (s->accent && !s->disabled)
|
||||
hit = reaktor_button_accent_as(g_app, g_ctx, sel, s->label);
|
||||
else
|
||||
hit = reaktor_button_label_as(g_app, g_ctx, sel, s->label);
|
||||
reaktor_note_mute(g_app, 0);
|
||||
reaktor_unfit_label(g_ctx, fitted);
|
||||
if (s->disabled) nk_widget_disable_end(g_ctx);
|
||||
if (s->disabled) {
|
||||
nk_widget_disable_end(g_ctx);
|
||||
if (fade < 1.0f)
|
||||
reaktor_fade_since(g_ctx, nk_window_get_canvas(g_ctx), mark, fade);
|
||||
}
|
||||
if (s->repeat) nk_button_set_behavior(g_ctx, NK_BUTTON_DEFAULT);
|
||||
if (styled) nk_style_pop_font(g_ctx);
|
||||
|
||||
@@ -618,8 +675,7 @@ reaktor_icon(const reaktor_icon_spec *s)
|
||||
px = (int)box.w;
|
||||
|
||||
im = s->accent
|
||||
? reaktor_ionicon_col(g_app, s->name, px,
|
||||
reaktor_token("--links", g_app->text))
|
||||
? reaktor_ionicon_col(g_app, s->name, px, g_app->accent)
|
||||
: reaktor_ionicon(g_app, s->name, px);
|
||||
|
||||
if (!place(REAKTOR_A11Y_NONE, NULL, NULL, 0u, NULL, &box, NULL)) return;
|
||||
@@ -634,7 +690,8 @@ reaktor_field(const reaktor_field_spec *s)
|
||||
|
||||
if (!g_app || !s || !s->buf || !s->len) return;
|
||||
box = s->box;
|
||||
box_from_style(&box, NULL, s->style, "input", 0.0f, 10.0f);
|
||||
box_from_style(&box, NULL, s->style ? s->style : "input.type-text", "input",
|
||||
0.0f, 10.0f);
|
||||
|
||||
if (!place(REAKTOR_A11Y_TEXTBOX, s->name ? s->name : s->hint,
|
||||
NULL, 0u, NULL, &box, &id))
|
||||
@@ -810,8 +867,7 @@ reaktor_select(const reaktor_select_spec *s)
|
||||
reaktor_select_arm(b, s->on, rs.matched ? rs.rounding
|
||||
: g_ctx->style.selectable.rounding);
|
||||
if (s->icon) {
|
||||
struct nk_color accent = reaktor_token("--links",
|
||||
g_ctx->style.text.color);
|
||||
struct nk_color accent = g_app->accent;
|
||||
struct nk_color ink = *s->on
|
||||
? reaktor_on(accent)
|
||||
: reaktor_token("--text-muted", g_ctx->style.text.color);
|
||||
@@ -940,7 +996,8 @@ reaktor_property(const reaktor_property_spec *s)
|
||||
else SDL_snprintf(text, sizeof(text), "%.2f", now);
|
||||
|
||||
box = s->box;
|
||||
box_from_style(&box, NULL, s->style, "input", 0.0f, 7.0f);
|
||||
box_from_style(&box, NULL, s->style ? s->style : "input.type-text", "input",
|
||||
0.0f, 7.0f);
|
||||
|
||||
if (!place(REAKTOR_A11Y_SPINBUTTON, s->name ? s->name : s->label, text,
|
||||
0u, NULL, &box, &id))
|
||||
@@ -981,7 +1038,7 @@ reaktor_combo_open(const reaktor_combo_spec *s)
|
||||
reaktor_box field;
|
||||
|
||||
memset(&field, 0, sizeof(field));
|
||||
box_from_style(&field, NULL, NULL, "input", 0.0f, 10.0f);
|
||||
box_from_style(&field, NULL, "input.type-text", "input", 0.0f, 10.0f);
|
||||
if (field.h > box.h) box.h = field.h;
|
||||
}
|
||||
|
||||
@@ -1147,11 +1204,11 @@ nav_list(const reaktor_nav_spec *s, int across)
|
||||
nav_look_of(&look[0], item);
|
||||
nav_look_of(&look[1], across ? ".tab-current" : ".sidebar-current");
|
||||
reaktor_style_get(across ? ".tab-edge" : ".sidebar-edge", &edge);
|
||||
list = s->box;
|
||||
reaktor_box_open(across ? REAKTOR_LAY_ROW : REAKTOR_LAY_COLUMN, &list);
|
||||
memset(&down, 0, sizeof(down));
|
||||
down.flags = REAKTOR_LAY_FILL_X;
|
||||
if (!across) box_from_style(&down, NULL, NULL, item, 12.0f, 8.0f);
|
||||
list = s->box;
|
||||
reaktor_box_open(across ? REAKTOR_LAY_ROW : REAKTOR_LAY_COLUMN, &list);
|
||||
id = reaktor_note_push(g_app, list_role[kind], s->name, NULL, 0u,
|
||||
reaktor_box_rect(&r) ? r : nk_rect(0, 0, 0, 0));
|
||||
if (s->list_keys) reaktor_note_keys(g_app, id, s->list_keys);
|
||||
|
||||
@@ -58,6 +58,7 @@ 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; }
|
||||
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));
|
||||
@@ -142,12 +143,51 @@ slot_of(reaktor_layout *l, unsigned id)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* A stylesheet's margin only parts a widget from its neighbors. The one
|
||||
* leading a child moves to the end of the child before it, so every wrapped
|
||||
* line starts at the edge, and the last child's trailing one is dropped. */
|
||||
static void
|
||||
part_neighbors(reaktor_layout *l, lay_id box)
|
||||
{
|
||||
lay_id c, prev = LAY_INVALID_ID;
|
||||
int lead, trail;
|
||||
|
||||
if (box >= REAKTOR_LAY_MAX || l->dir[box] == REAKTOR_LAY_FREE) return;
|
||||
lead = l->dir[box] == REAKTOR_LAY_ROW ? 0 : 1;
|
||||
trail = lead + 2;
|
||||
|
||||
for (c = lay_first_child(&l->ctx, box); c != LAY_INVALID_ID;
|
||||
prev = c, c = lay_next_sibling(&l->ctx, c)) {
|
||||
lay_scalar m[4], p[4];
|
||||
|
||||
if (c >= REAKTOR_LAY_MAX || !(l->flags[c] & (REAKTOR_LAY_SHEET_L << lead)))
|
||||
continue;
|
||||
lay_get_margins_ltrb(&l->ctx, c, &m[0], &m[1], &m[2], &m[3]);
|
||||
if (prev != LAY_INVALID_ID) {
|
||||
lay_get_margins_ltrb(&l->ctx, prev, &p[0], &p[1], &p[2], &p[3]);
|
||||
p[trail] += m[lead];
|
||||
lay_set_margins_ltrb(&l->ctx, prev, p[0], p[1], p[2], p[3]);
|
||||
}
|
||||
m[lead] = 0;
|
||||
lay_set_margins_ltrb(&l->ctx, c, m[0], m[1], m[2], m[3]);
|
||||
}
|
||||
if (prev != LAY_INVALID_ID && prev < REAKTOR_LAY_MAX
|
||||
&& (l->flags[prev] & (REAKTOR_LAY_SHEET_L << trail))) {
|
||||
lay_scalar m[4];
|
||||
|
||||
lay_get_margins_ltrb(&l->ctx, prev, &m[0], &m[1], &m[2], &m[3]);
|
||||
m[trail] = 0;
|
||||
lay_set_margins_ltrb(&l->ctx, prev, m[0], m[1], m[2], m[3]);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_layout_end(reaktor_layout *l)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!l->started || !l->count) return;
|
||||
for (i = 0; i < l->count; i++) part_neighbors(l, l->item[i]);
|
||||
lay_run_context(&l->ctx);
|
||||
|
||||
l->gen++;
|
||||
|
||||
@@ -9,6 +9,12 @@
|
||||
#define REAKTOR_LAY_DEPTH 32
|
||||
#define REAKTOR_LAY_SLOTS 512
|
||||
|
||||
/* Sides whose margin a stylesheet set, in Onlay's left, top, right, bottom order. */
|
||||
#define REAKTOR_LAY_SHEET_L (1u << 28)
|
||||
#define REAKTOR_LAY_SHEET_T (1u << 29)
|
||||
#define REAKTOR_LAY_SHEET_R (1u << 30)
|
||||
#define REAKTOR_LAY_SHEET_B (1u << 31)
|
||||
|
||||
typedef struct reaktor_lay_slot {
|
||||
unsigned id;
|
||||
unsigned gen;
|
||||
@@ -23,6 +29,9 @@ typedef struct reaktor_layout {
|
||||
lay_id item[REAKTOR_LAY_MAX];
|
||||
int count;
|
||||
|
||||
unsigned flags[REAKTOR_LAY_MAX];
|
||||
unsigned char dir[REAKTOR_LAY_MAX];
|
||||
|
||||
lay_id stack[REAKTOR_LAY_DEPTH];
|
||||
int depth;
|
||||
|
||||
|
||||
+38
-24
@@ -47,6 +47,8 @@ static struct {
|
||||
const nk_bool *on;
|
||||
struct nk_style_item *slot, saved;
|
||||
float *border, border_was;
|
||||
int edges;
|
||||
struct nk_color edge_hover, edge_active;
|
||||
} g_chrome;
|
||||
|
||||
static void
|
||||
@@ -74,6 +76,7 @@ void
|
||||
reaktor_chrome_disarm(void)
|
||||
{
|
||||
g_chrome.armed = 0;
|
||||
g_chrome.edges = 0;
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -94,16 +97,20 @@ button_chrome_begin(struct nk_command_buffer *out, nk_handle user)
|
||||
App *app = (App *)user.ptr;
|
||||
struct nk_style_button *st = &app->ctx->style.button;
|
||||
nk_flags state = app->ctx->last_widget_state;
|
||||
struct nk_color col;
|
||||
struct nk_color col, edge = st->border_color;
|
||||
|
||||
if (!g_chrome.armed ||
|
||||
!chrome_take((state & NK_WIDGET_STATE_HOVER) ? &st->hover
|
||||
: (state & NK_WIDGET_STATE_ACTIVED) ? &st->active
|
||||
: &st->normal, &col))
|
||||
return;
|
||||
/* Nuklear keeps one border color; a rule can give each state its own. */
|
||||
if (g_chrome.edges)
|
||||
edge = (state & NK_WIDGET_STATE_HOVER) ? g_chrome.edge_hover
|
||||
: (state & NK_WIDGET_STATE_ACTIVED) ? g_chrome.edge_active : edge;
|
||||
reaktor_paint_surface(app, out, g_chrome.b, &(reaktor_surface){
|
||||
nk_rgb_factor(col, st->color_factor_background),
|
||||
nk_rgb_factor(st->border_color, st->color_factor_background),
|
||||
nk_rgb_factor(edge, st->color_factor_background),
|
||||
st->border, st->rounding });
|
||||
g_chrome.border = &st->border;
|
||||
g_chrome.border_was = st->border;
|
||||
@@ -173,6 +180,9 @@ push_button_look(App *app, struct nk_context *ctx, const reaktor_button_look *k)
|
||||
nk_style_push_color(ctx, &ctx->style.button.border_color,
|
||||
col_of(s.border_col));
|
||||
f.colors = 4;
|
||||
g_chrome.edges = 1;
|
||||
g_chrome.edge_hover = col_of(hov->matched ? hov->border_col : s.border_col);
|
||||
g_chrome.edge_active = col_of(act->matched ? act->border_col : s.border_col);
|
||||
|
||||
nk_style_push_float(ctx, &ctx->style.button.rounding, s.rounding);
|
||||
nk_style_push_float(ctx, &ctx->style.button.border, s.border);
|
||||
@@ -317,7 +327,7 @@ reaktor_visible(struct nk_color want, struct nk_color behind,
|
||||
|
||||
int
|
||||
css_button_accent(App *app, struct nk_context *ctx, const char *selector,
|
||||
const char *label, const char *token)
|
||||
const char *label, struct nk_color accent)
|
||||
{
|
||||
style_frame f, a = { 0, 0, 0, 0, 0 };
|
||||
unsigned char c[4];
|
||||
@@ -328,7 +338,8 @@ css_button_accent(App *app, struct nk_context *ctx, const char *selector,
|
||||
|
||||
f = push_button_style(app, ctx, selector);
|
||||
|
||||
if (reaktor_style_token(token, c)) {
|
||||
c[0] = accent.r; c[1] = accent.g; c[2] = accent.b; c[3] = accent.a;
|
||||
{
|
||||
unsigned char hov[4];
|
||||
memcpy(hov, c, 4);
|
||||
reaktor_style_darken(hov, 0.12f);
|
||||
@@ -341,6 +352,7 @@ css_button_accent(App *app, struct nk_context *ctx, const char *selector,
|
||||
nk_style_item_color(col_of(hov)));
|
||||
a.items = 3;
|
||||
nk_style_push_color(ctx, &ctx->style.button.border_color, col_of(c));
|
||||
g_chrome.edge_hover = g_chrome.edge_active = col_of(c);
|
||||
|
||||
{
|
||||
struct nk_color label_col =
|
||||
@@ -395,11 +407,15 @@ css_button_icon(App *app, struct nk_context *ctx, const char *selector,
|
||||
clicked = nk_button_label(ctx, label);
|
||||
reaktor_chrome_disarm();
|
||||
if (drawn) {
|
||||
const struct nk_style_button *bs = &ctx->style.button;
|
||||
nk_flags state = ctx->last_widget_state;
|
||||
struct nk_image im = icon(app, icon_src, 18);
|
||||
struct nk_color ink = (state & NK_WIDGET_STATE_HOVER) ? bs->text_hover
|
||||
: (state & NK_WIDGET_STATE_ACTIVED) ? bs->text_active
|
||||
: bs->text_normal;
|
||||
|
||||
nk_draw_image(nk_window_get_canvas(ctx), at, &im,
|
||||
nk_rgb_factor(nk_rgb(255, 255, 255),
|
||||
ctx->style.button.color_factor_background));
|
||||
nk_rgb_factor(ink, bs->color_factor_text));
|
||||
}
|
||||
pop_style(ctx, f);
|
||||
return clicked;
|
||||
@@ -461,8 +477,8 @@ push_edit_style(struct nk_context *ctx, reaktor_style *out, int inset)
|
||||
style_frame f = { 0, 0, 0, 0, 0 };
|
||||
unsigned char body[4];
|
||||
|
||||
reaktor_style_get("input", &s);
|
||||
reaktor_style_get("input:focus", &foc);
|
||||
reaktor_style_get("input.type-text", &s);
|
||||
reaktor_style_get("input.type-text:focus", &foc);
|
||||
reaktor_style_get("button", &btn);
|
||||
if (btn.matched) s.rounding = btn.rounding;
|
||||
s.pad_x += s.border;
|
||||
@@ -702,26 +718,26 @@ apply_widget_style(App *app)
|
||||
struct nk_color on_accent, thumb, thumb_hi;
|
||||
struct nk_style_item i_none, i_base, i_hover, i_accent;
|
||||
reaktor_style btn, btn_hov, inp, sel, det, sum, dlg;
|
||||
reaktor_style rng, acc;
|
||||
reaktor_style rng;
|
||||
unsigned char c[4], ac[4];
|
||||
|
||||
if (!app->ctx) return;
|
||||
ctx = app->ctx;
|
||||
st = &ctx->style;
|
||||
|
||||
body = reaktor_token("--background-body", app->page);
|
||||
body = app->page;
|
||||
base = reaktor_token("--background", app->card_bg);
|
||||
hover = reaktor_token("--background-hover", base);
|
||||
text = reaktor_token("--text-main", app->text);
|
||||
text = app->text;
|
||||
muted = reaktor_token("--text-muted", text);
|
||||
bright = reaktor_token("--text-bright", text);
|
||||
accent = reaktor_token("--links", text);
|
||||
accent = app->accent;
|
||||
focus = reaktor_token("--focus", accent);
|
||||
|
||||
edge = hover;
|
||||
|
||||
on_accent = reaktor_style_token("--links", ac)
|
||||
? readable_on(ac, "--text-bright", "--background-body") : bright;
|
||||
ac[0] = accent.r; ac[1] = accent.g; ac[2] = accent.b; ac[3] = accent.a;
|
||||
on_accent = readable_on(ac, "--text-bright", "--background-body");
|
||||
|
||||
thumb = nk_rgba(muted.r, muted.g, muted.b, 110);
|
||||
thumb_hi = nk_rgba(muted.r, muted.g, muted.b, 175);
|
||||
@@ -756,8 +772,10 @@ apply_widget_style(App *app)
|
||||
st->button.userdata = nk_handle_ptr(app);
|
||||
st->button.draw_begin = button_chrome_begin;
|
||||
st->button.draw_end = chrome_end;
|
||||
/* A disabled button is faded, not darkened: see reaktor_button. */
|
||||
st->button.disabled_factor = 1.0f;
|
||||
|
||||
reaktor_style_get("input", &inp);
|
||||
reaktor_style_get("input.type-text", &inp);
|
||||
if (inp.matched) {
|
||||
struct nk_color sel_text = reaktor_style_token("--focus", c)
|
||||
? readable_on(c, "--text-bright",
|
||||
@@ -802,7 +820,6 @@ apply_widget_style(App *app)
|
||||
st->selectable.image_padding = nk_vec2(7.0f, 7.0f);
|
||||
|
||||
reaktor_style_get("input", &rng);
|
||||
reaktor_style_get("a", &acc);
|
||||
|
||||
st->slider.normal = i_none;
|
||||
st->slider.hover = i_none;
|
||||
@@ -810,9 +827,8 @@ apply_widget_style(App *app)
|
||||
st->slider.bar_normal = rng.matched ? col_of(rng.bg) : edge;
|
||||
st->slider.bar_hover = st->slider.bar_normal;
|
||||
st->slider.bar_active = st->slider.bar_normal;
|
||||
st->slider.bar_filled = acc.matched ? col_of(acc.fg) : accent;
|
||||
st->slider.cursor_normal = acc.matched
|
||||
? nk_style_item_color(col_of(acc.fg)) : i_accent;
|
||||
st->slider.bar_filled = accent;
|
||||
st->slider.cursor_normal = i_accent;
|
||||
st->slider.cursor_hover = nk_style_item_color(focus);
|
||||
st->slider.cursor_active = nk_style_item_color(focus);
|
||||
st->slider.border_color = rng.matched ? col_of(rng.border_col) : edge;
|
||||
@@ -830,7 +846,7 @@ apply_widget_style(App *app)
|
||||
st->knob.knob_hover = hover;
|
||||
st->knob.knob_active = hover;
|
||||
st->knob.knob_border_color = btn.matched ? col_of(btn.border_col) : edge;
|
||||
st->knob.cursor_normal = acc.matched ? col_of(acc.fg) : accent;
|
||||
st->knob.cursor_normal = accent;
|
||||
st->knob.cursor_hover = focus;
|
||||
st->knob.cursor_active = focus;
|
||||
st->knob.border_color = btn.matched ? col_of(btn.border_col) : edge;
|
||||
@@ -840,14 +856,12 @@ apply_widget_style(App *app)
|
||||
: i_base;
|
||||
st->progress.hover = st->progress.normal;
|
||||
st->progress.active = st->progress.normal;
|
||||
st->progress.cursor_normal = acc.matched
|
||||
? nk_style_item_color(col_of(acc.fg))
|
||||
: i_accent;
|
||||
st->progress.cursor_normal = i_accent;
|
||||
st->progress.cursor_hover = nk_style_item_color(focus);
|
||||
st->progress.cursor_active = nk_style_item_color(focus);
|
||||
st->progress.border_color = rng.matched ? col_of(rng.border_col)
|
||||
: edge;
|
||||
st->progress.cursor_border_color = acc.matched ? col_of(acc.fg) : accent;
|
||||
st->progress.cursor_border_color = accent;
|
||||
st->progress.border = 0.0f;
|
||||
st->progress.cursor_border = 0.0f;
|
||||
{
|
||||
|
||||
+5
-7
@@ -133,7 +133,7 @@ reaktor_link_label(App *app, struct nk_context *ctx, const char *label, int acti
|
||||
clicked = 1;
|
||||
}
|
||||
|
||||
col = active ? reaktor_token("--links", app->text)
|
||||
col = active ? app->accent
|
||||
: reaktor_token("--text-muted", app->text);
|
||||
|
||||
nk_style_push_color(ctx, &ctx->style.text.color, col);
|
||||
@@ -497,7 +497,7 @@ int
|
||||
reaktor_button_accent_as(App *app, struct nk_context *ctx, const char *sel,
|
||||
const char *label)
|
||||
{
|
||||
return css_button_accent(app, ctx, sel, label, "--links");
|
||||
return css_button_accent(app, ctx, sel, label, app->accent);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -507,15 +507,14 @@ reaktor_button_icon_as(App *app, struct nk_context *ctx, const char *sel,
|
||||
char src[192];
|
||||
|
||||
SDL_snprintf(src, sizeof(src),
|
||||
"external/ionicons/src/svg/%s.svg?stroke=%s",
|
||||
ionicon, app->icon_hex);
|
||||
"external/ionicons/src/svg/%s.svg?stroke=#ffffff", ionicon);
|
||||
return css_button_icon(app, ctx, sel, src, label);
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_button_accent(App *app, struct nk_context *ctx, const char *label)
|
||||
{
|
||||
return css_button_accent(app, ctx, "button", label, "--links");
|
||||
return css_button_accent(app, ctx, "button", label, app->accent);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -579,8 +578,7 @@ reaktor_button_icon(App *app, struct nk_context *ctx, const char *ionicon,
|
||||
char src[192];
|
||||
|
||||
SDL_snprintf(src, sizeof(src),
|
||||
"external/ionicons/src/svg/%s.svg?stroke=%s",
|
||||
ionicon, app->icon_hex);
|
||||
"external/ionicons/src/svg/%s.svg?stroke=#ffffff", ionicon);
|
||||
return css_button_icon(app, ctx, "button", src, label);
|
||||
}
|
||||
|
||||
|
||||
+46
-15
@@ -230,8 +230,9 @@ wrap it in `REAKTOR_FREE` to inset it.
|
||||
before computed, found by accessibility id, and a box seen for the first time
|
||||
waits a frame. So a size that depends on content takes a frame to settle, and
|
||||
a widget whose text changes every frame needs a stable `.name` or it never has
|
||||
a rectangle. After sixteen unsettled frames the runtime stops redrawing and
|
||||
logs the box.
|
||||
a rectangle. The first frame after the stylesheets load counts as unsettled
|
||||
too, since its rectangles were laid out with the old sheet's sizes. After
|
||||
sixteen unsettled frames the runtime stops redrawing and logs the box.
|
||||
|
||||
## Layers
|
||||
|
||||
@@ -356,9 +357,10 @@ if (s.matched) { /* s.bg, s.fg, s.border, s.rounding, s.pad[4], s.font_px */ }
|
||||
|
||||
| Widget | Reads |
|
||||
| --- | --- |
|
||||
| Button | `button`; an accent one fills with `--links` |
|
||||
| Button | `button`; an accent one fills with the accent, a disabled one reads `button.disabled:disabled` |
|
||||
| Link | `a` |
|
||||
| Field, check, radio, property | `input` |
|
||||
| Field, property | `input.type-text`: a sheet's `input` rule and its `[type=text]` one |
|
||||
| Check, radio | `input` |
|
||||
| Slider | `input.type-range` |
|
||||
| Progress | `progress` |
|
||||
| Select, combo | `select` |
|
||||
@@ -366,21 +368,43 @@ if (s.matched) { /* s.bg, s.fg, s.border, s.rounding, s.pad[4], s.font_px */ }
|
||||
| Toast | `.toast`, `.toast-button`, `.toast-close` |
|
||||
| Sidebar, tabs | `.sidebar-item`, `.sidebar-current`, `.sidebar-edge`; `.tab`, `.tab-current`, `.tab-edge` |
|
||||
|
||||
With `:hover` and `:active` where a widget has those states. Controls a
|
||||
document lacks borrow from what they resemble: a slider's rail from `input`,
|
||||
the accent from `a`, a knob's body from `button` — reading the accent off `a`
|
||||
rather than a token is what lets a sheet that never declares `--links` work.
|
||||
With `:hover` and `:active` where a widget has those states, a button's
|
||||
border included. Controls a document lacks borrow from what they resemble: a
|
||||
slider's rail from `input`, the accent from `a:link` (which a plain `a` rule
|
||||
answers too), a knob's body from `button` — reading the accent off the link
|
||||
rule rather than a token is what lets a sheet that never declares `--links`
|
||||
work, and it fills accent buttons, sliders, progress, checks and the accent
|
||||
icons. The page and the text on it come from `body` the same way, and
|
||||
`reaktor_page_color` and `reaktor_accent_color` hand an application the page
|
||||
and the accent. An icon on a button takes its label's color.
|
||||
|
||||
- **A size set in code beats the sheet.** A `.box = { .h = N }` locks CSS out of
|
||||
that axis, the usual reason a rule "only changes the color".
|
||||
- **A disabled button wears the sheet's own rule.** It reads
|
||||
`button.disabled:disabled`, so `button:disabled` and `button[disabled]` both
|
||||
count, and that rule's `opacity` fades everything the button draws, as a
|
||||
browser fades it. A sheet that does not tell a disabled button apart gets
|
||||
half. Nuklear's own dimming, which multiplies colors toward black, is off.
|
||||
- **A rule's margin only parts a widget from its neighbors.** Across its row
|
||||
or column the page has sized the box, so in a row a rule's top and bottom
|
||||
margins are skipped, and in a column its left and right ones. Along it the
|
||||
margins go between widgets, never before the first or after the last, so a
|
||||
row of buttons starts and ends where the field below it does, and each line
|
||||
of a row that wraps starts at the edge. A margin set in code always counts,
|
||||
and a `REAKTOR_FREE` box keeps all four.
|
||||
- **libcss is not a browser.** `cssflat.c` resolves `var()`, works out
|
||||
`color-mix(in srgb, …)`, writes every `rgb()` as `rgba()` with four
|
||||
arguments, clamped, turns `em` and `rem` into pixels, keeps the
|
||||
`@media (prefers-color-scheme)` branch for the active scheme and drops width
|
||||
and print queries, and rewrites `[type=range]` as `.type-range`. An operator
|
||||
arguments, clamped, turns `em` and `rem` into pixels, works out `calc()`
|
||||
over pixels and plain numbers (one with a percentage is left, and dropped),
|
||||
keeps the `@media (prefers-color-scheme)` branch for the active scheme and
|
||||
drops width and print queries, rewrites `[type=range]` as `.type-range`
|
||||
and `[disabled]` as `.disabled`, and drops `:enabled`, since every widget
|
||||
that asks is enabled and a disabled one asks for `:disabled`. An operator
|
||||
form like `[href^="http"]` cannot be expressed, and its rule is dropped, as
|
||||
is a declaration with a color it cannot read. Sheets are read in the C
|
||||
locale's numbers whatever the program's locale.
|
||||
is a declaration with a color it cannot read, and a selector that names a
|
||||
class or pseudo-class twice in one compound: given two `:not()`, libcss
|
||||
frees a list and goes on using it. Sheets are read in the C locale's numbers
|
||||
whatever the program's locale.
|
||||
reaktor.css uses the scheme branch to strengthen light hovers and tint the
|
||||
current sidebar entry from `--links`.
|
||||
|
||||
@@ -469,7 +493,7 @@ declared page. [`include/reaktor/ui.h`](../include/reaktor/ui.h) has the pieces
|
||||
|
||||
| Helper | For |
|
||||
| --- | --- |
|
||||
| `reaktor_token`, `reaktor_col`, `reaktor_on`, `reaktor_visible` | Colors from the sheet; readable text on a background |
|
||||
| `reaktor_token`, `reaktor_col`, `reaktor_on`, `reaktor_visible`, `reaktor_page_color`, `reaktor_accent_color` | Colors from the sheet; readable text on a background; the page and the accent |
|
||||
| `reaktor_font`, `reaktor_style_font` | A baked face, by size or by selector |
|
||||
| `reaktor_ionicon`, `reaktor_ionicon_exact`, `reaktor_glyph_at` | An Ionicon as an `nk_image`, in any color, or drawn into a rectangle |
|
||||
| `reaktor_svg`, `REAKTOR_MARK` | Any SVG asset, recolored by `?stroke=#rrggbb&fill=&sw=`; the mark's name |
|
||||
@@ -629,6 +653,12 @@ reaktor_add_app(myapp SOURCES main.c)
|
||||
Under another project Reaktor builds none of its samples or tests and
|
||||
installs nothing (`REAKTOR_SAMPLES`, `REAKTOR_TESTS` and `REAKTOR_INSTALL`
|
||||
default to on only at the top), and its settings stay in its own directory.
|
||||
A module's sources compile in the app's directory, so the one that needs a
|
||||
language of its own, the macOS accessibility bridge in Objective-C, is
|
||||
compiled in Reaktor's instead: the app needs no Objective-C, and no ARC flag.
|
||||
[`examples/embedded`](../examples/embedded) declares Simple this way from a
|
||||
directory of its own; the macOS jobs and Linux x86-64 build it and check it
|
||||
draws as the in-tree build does.
|
||||
|
||||
**libreaktor.** Each release carries `libreaktor-<version>-<system>-<arch>`
|
||||
for every platform above, and `-wasm`. Build one yourself with:
|
||||
@@ -645,7 +675,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.3 REQUIRED)
|
||||
find_package(reaktor 0.4 REQUIRED)
|
||||
add_executable(app WIN32 main.c)
|
||||
target_link_libraries(app PRIVATE reaktor::reaktor)
|
||||
```
|
||||
@@ -768,6 +798,7 @@ 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 |
|
||||
| `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`), 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) |
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(consumer C)
|
||||
|
||||
find_package(reaktor 0.3 REQUIRED)
|
||||
find_package(reaktor 0.4 REQUIRED)
|
||||
|
||||
add_executable(simple WIN32 ../../samples/simple/simple.c)
|
||||
target_link_libraries(simple PRIVATE reaktor::reaktor)
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(embedded C)
|
||||
|
||||
add_subdirectory(../.. reaktor)
|
||||
|
||||
reaktor_add_app(simple SOURCES ../../samples/simple/simple.c)
|
||||
@@ -22,6 +22,7 @@ typedef struct reaktor_style {
|
||||
float min_width, min_height;
|
||||
float max_width, max_height;
|
||||
float line_height;
|
||||
float opacity;
|
||||
|
||||
int font_px;
|
||||
int bold;
|
||||
|
||||
@@ -26,6 +26,10 @@ struct nk_color reaktor_token(const char *name,
|
||||
struct nk_color reaktor_visible(struct nk_color want,
|
||||
struct nk_color behind,
|
||||
struct nk_color fallback);
|
||||
/* The body rule's background, or --background-body when no sheet sets one. */
|
||||
struct nk_color reaktor_page_color(App *app);
|
||||
/* The link rule's color, or --links when no sheet sets one. */
|
||||
struct nk_color reaktor_accent_color(App *app);
|
||||
const struct nk_user_font *reaktor_font(App *app, int px, int bold);
|
||||
|
||||
struct nk_image reaktor_ionicon(App *app, const char *name, int px);
|
||||
|
||||
+36
-9
@@ -215,23 +215,38 @@ load_theme(App *app)
|
||||
app->style_ms_x100 = (int)(100000.0 * (double)(t1 - t0) /
|
||||
(double)SDL_GetPerformanceFrequency());
|
||||
|
||||
app->page = reaktor_style_token("--background-body", c)
|
||||
? nk_rgba(c[0], c[1], c[2], c[3]) : nk_rgb(247, 247, 247);
|
||||
{
|
||||
reaktor_style body;
|
||||
|
||||
reaktor_style_get("body", &body);
|
||||
app->page = body.matched && body.bg[3]
|
||||
? nk_rgba(body.bg[0], body.bg[1], body.bg[2], body.bg[3])
|
||||
: reaktor_style_token("--background-body", c)
|
||||
? nk_rgba(c[0], c[1], c[2], c[3]) : nk_rgb(247, 247, 247);
|
||||
app->text = body.matched && body.fg[3]
|
||||
? nk_rgba(body.fg[0], body.fg[1], body.fg[2], body.fg[3])
|
||||
: reaktor_style_token("--text-main", c)
|
||||
? nk_rgba(c[0], c[1], c[2], c[3]) : nk_rgb(51, 51, 51);
|
||||
}
|
||||
{
|
||||
reaktor_style link;
|
||||
|
||||
reaktor_style_get("a:link", &link);
|
||||
app->accent = link.matched && link.fg[3]
|
||||
? nk_rgba(link.fg[0], link.fg[1], link.fg[2], link.fg[3])
|
||||
: reaktor_style_token("--links", c)
|
||||
? nk_rgba(c[0], c[1], c[2], c[3]) : app->text;
|
||||
}
|
||||
app->card_bg = reaktor_style_token("--background", c)
|
||||
? nk_rgba(c[0], c[1], c[2], c[3]) : nk_rgb(226, 226, 226);
|
||||
app->text = reaktor_style_token("--text-main", c)
|
||||
? nk_rgba(c[0], c[1], c[2], c[3]) : nk_rgb(51, 51, 51);
|
||||
if (reaktor_style_token("--text-muted", c))
|
||||
SDL_snprintf(app->icon_hex, sizeof(app->icon_hex),
|
||||
"#%02x%02x%02x", c[0], c[1], c[2]);
|
||||
else
|
||||
SDL_strlcpy(app->icon_hex, "#6a6a6a", sizeof(app->icon_hex));
|
||||
|
||||
if (reaktor_style_token("--links", c))
|
||||
SDL_snprintf(app->accent_hex, sizeof(app->accent_hex),
|
||||
"#%02x%02x%02x", c[0], c[1], c[2]);
|
||||
else
|
||||
SDL_strlcpy(app->accent_hex, REAKTOR_BRAND, sizeof(app->accent_hex));
|
||||
SDL_snprintf(app->accent_hex, sizeof(app->accent_hex), "#%02x%02x%02x",
|
||||
app->accent.r, app->accent.g, app->accent.b);
|
||||
|
||||
reaktor_window_set_dark(app->win, app->dark);
|
||||
|
||||
@@ -1947,6 +1962,18 @@ reaktor_dark(App *app)
|
||||
return app && app->dark;
|
||||
}
|
||||
|
||||
struct nk_color
|
||||
reaktor_page_color(App *app)
|
||||
{
|
||||
return app ? app->page : nk_rgb(247, 247, 247);
|
||||
}
|
||||
|
||||
struct nk_color
|
||||
reaktor_accent_color(App *app)
|
||||
{
|
||||
return app ? app->accent : nk_rgb(0, 112, 224);
|
||||
}
|
||||
|
||||
reaktor_theme
|
||||
reaktor_get_theme(App *app)
|
||||
{
|
||||
|
||||
@@ -48,6 +48,7 @@ take_look(App *a, const App *m)
|
||||
a->page = m->page;
|
||||
a->card_bg = m->card_bg;
|
||||
a->text = m->text;
|
||||
a->accent = m->accent;
|
||||
a->clear = m->clear;
|
||||
SDL_memcpy(a->icon_hex, m->icon_hex, sizeof a->icon_hex);
|
||||
SDL_memcpy(a->accent_hex, m->accent_hex, sizeof a->accent_hex);
|
||||
|
||||
+40
-13
@@ -10,6 +10,9 @@ typedef struct shell_style { int items, colors, floats, vec2s, fonts; } shell_st
|
||||
static struct nk_rect g_ctl[3];
|
||||
static int g_ctl_n;
|
||||
static int g_show_contact;
|
||||
static float g_card_h;
|
||||
static float g_nav_room;
|
||||
static int g_nav_over;
|
||||
|
||||
static void
|
||||
pop_style(struct nk_context *ctx, shell_style f)
|
||||
@@ -271,7 +274,7 @@ login_card(App *app, struct nk_context *ctx, float body_x, float body_w,
|
||||
float body_y, float body_h)
|
||||
{
|
||||
struct nk_rect at;
|
||||
float card_h = card_height(g_show_contact);
|
||||
float card_h = g_card_h > 0.0f ? g_card_h : card_height(g_show_contact);
|
||||
float card_w = body_w - 16.0f < (float)CARD_W ? body_w - 16.0f : (float)CARD_W;
|
||||
float side = body_x + (body_w - card_w) * 0.5f;
|
||||
float top = body_y + (body_h - card_height(0)) * 0.5f;
|
||||
@@ -292,7 +295,14 @@ login_card(App *app, struct nk_context *ctx, float body_x, float body_w,
|
||||
nk_style_push_vec2(ctx, &ctx->style.window.group_padding, nk_vec2(0, 0));
|
||||
if (nk_group_begin(ctx, "card", NK_WINDOW_NO_SCROLLBAR)) {
|
||||
REAKTOR_COLUMN(.name = "Proceed with login",
|
||||
.w = card_w, .h = card_h, .gap = ROW_GAP) {
|
||||
.w = card_w, .gap = ROW_GAP) {
|
||||
struct nk_rect laid;
|
||||
|
||||
/* The card is as tall as a sheet's margins make its rows. */
|
||||
if (reaktor_box_rect(&laid) && laid.h != g_card_h) {
|
||||
g_card_h = laid.h;
|
||||
reaktor_wake(app);
|
||||
}
|
||||
REAKTOR_ROW(.h = ROW_BRAND, .gap = 10, .flags = REAKTOR_LAY_FILL_X,
|
||||
.ml = CARD_PAD_X, .mr = CARD_PAD_X, .mt = CARD_PAD_Y) {
|
||||
reaktor_icon(&(reaktor_icon_spec){
|
||||
@@ -335,7 +345,8 @@ login_card(App *app, struct nk_context *ctx, float body_x, float body_w,
|
||||
.text = g_show_contact ? "hide contact" : "contact",
|
||||
.style = ".card-link",
|
||||
.box = { .h = ROW_SMALL, .flags = REAKTOR_LAY_FILL_X,
|
||||
.ml = CARD_PAD_X, .mr = CARD_PAD_X } }))
|
||||
.ml = CARD_PAD_X, .mr = CARD_PAD_X,
|
||||
.mb = g_show_contact ? 0.0f : CARD_PAD_Y } }))
|
||||
g_show_contact = !g_show_contact;
|
||||
|
||||
if (g_show_contact) {
|
||||
@@ -350,7 +361,8 @@ login_card(App *app, struct nk_context *ctx, float body_x, float body_w,
|
||||
reaktor_label(&(reaktor_label_spec){
|
||||
.text = lines[i], .style = ".card-link", .align = REAKTOR_CENTRE,
|
||||
.box = { .h = ROW_SMALL, .flags = REAKTOR_LAY_FILL_X,
|
||||
.ml = CARD_PAD_X, .mr = CARD_PAD_X } });
|
||||
.ml = CARD_PAD_X, .mr = CARD_PAD_X,
|
||||
.mb = i == CONTACT_ROWS - 1 ? CARD_PAD_Y : 0.0f } });
|
||||
}
|
||||
}
|
||||
nk_group_end(ctx);
|
||||
@@ -386,7 +398,8 @@ int
|
||||
sample_option(App *app, struct nk_context *ctx, const char *label, float w,
|
||||
int on)
|
||||
{
|
||||
struct nk_color fg = reaktor_token(on ? "--links" : "--text-muted", text_main());
|
||||
struct nk_color fg = on ? reaktor_accent_color(app)
|
||||
: reaktor_token("--text-muted", text_main());
|
||||
struct nk_rect b;
|
||||
shell_style look;
|
||||
unsigned id;
|
||||
@@ -420,7 +433,7 @@ toggle_titlebar(App *app)
|
||||
#endif
|
||||
|
||||
static void
|
||||
nav(App *app, float w, float h)
|
||||
nav(App *app, float w, float inner_w, float h)
|
||||
{
|
||||
static const char *const icons[TAB_COUNT] = {
|
||||
"person-outline", "tablet-landscape-outline", "create-outline",
|
||||
@@ -444,16 +457,31 @@ nav(App *app, float w, float h)
|
||||
}
|
||||
sample_tablist_keys(all, (int)sizeof(all));
|
||||
|
||||
REAKTOR_FREE(.w = w, .h = h)
|
||||
REAKTOR_COLUMN(.w = w - 16.0f, .h = h - 16.0f, .ml = 8.0f, .mt = 8.0f,
|
||||
REAKTOR_FREE(.w = inner_w)
|
||||
REAKTOR_COLUMN(.w = inner_w - 16.0f, .ml = 8.0f, .mt = 8.0f, .mb = 8.0f,
|
||||
.gap = 2.0f) {
|
||||
struct nk_rect laid;
|
||||
|
||||
/* The scheme sits at the foot when the window has room for both
|
||||
* lists; when it has none, the sidebar scrolls. */
|
||||
if (reaktor_box_rect(&laid)) {
|
||||
float room = h - 16.0f - (laid.h - g_nav_room);
|
||||
int over = room < 0.0f;
|
||||
|
||||
if (over) room = 0.0f;
|
||||
if (room != g_nav_room || over != g_nav_over) {
|
||||
g_nav_room = room;
|
||||
g_nav_over = over;
|
||||
reaktor_wake(app);
|
||||
}
|
||||
}
|
||||
if (reaktor_sidebar(&(reaktor_sidebar_spec){
|
||||
.items = reaktor_tab_names, .icons = icons, .keys = key_of,
|
||||
.count = TAB_COUNT, .chosen = &tab, .name = "Pages",
|
||||
.list_keys = all, .narrow = narrow,
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X } }))
|
||||
set_tab(app, tab);
|
||||
REAKTOR_COLUMN(.flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y) {}
|
||||
REAKTOR_COLUMN(.h = g_nav_room, .flags = REAKTOR_LAY_FILL_X) {}
|
||||
if (reaktor_sidebar(&(reaktor_sidebar_spec){
|
||||
.items = schemes, .icons = scheme_icons, .count = 3,
|
||||
.chosen = &scheme, .name = "Color scheme",
|
||||
@@ -590,8 +618,7 @@ page_shell(App *app, struct nk_context *ctx, int win_w, int win_h)
|
||||
|
||||
nk_fill_rect(cv, nk_rect(0.0f, 0.0f, (float)win_w, (float)win_h), 0.0f,
|
||||
card);
|
||||
reaktor_fill_round(app, cv, panel, PANEL_R,
|
||||
reaktor_token("--background-body", nk_rgb(247, 247, 247)));
|
||||
reaktor_fill_round(app, cv, panel, PANEL_R, reaktor_page_color(app));
|
||||
}
|
||||
|
||||
nk_layout_space_begin(ctx, NK_STATIC, (float)win_h, 3);
|
||||
@@ -609,8 +636,8 @@ page_shell(App *app, struct nk_context *ctx, int win_w, int win_h)
|
||||
nk_style_item_color(card));
|
||||
nk_style_push_vec2(ctx, &ctx->style.window.group_padding, nk_vec2(0, 0));
|
||||
nk_layout_space_push(ctx, nk_rect(0, top, nav_w, body_h));
|
||||
if (nk_group_begin(ctx, "nav", NK_WINDOW_NO_SCROLLBAR)) {
|
||||
nav(app, nav_w, body_h);
|
||||
if (nk_group_begin(ctx, "nav", g_nav_over ? 0 : NK_WINDOW_NO_SCROLLBAR)) {
|
||||
nav(app, nav_w, nk_window_get_content_region_size(ctx).x, body_h);
|
||||
nk_group_end(ctx);
|
||||
}
|
||||
nk_style_pop_vec2(ctx);
|
||||
|
||||
+12
-14
@@ -74,7 +74,7 @@ api(App *app, struct nk_context *ctx, const char *text)
|
||||
nk_layout_row_dynamic(ctx, 18.0f, 1);
|
||||
reaktor_note_here(app, ctx, REAKTOR_A11Y_LABEL, text, 0);
|
||||
nk_label_colored(ctx, text, NK_TEXT_LEFT,
|
||||
reaktor_token("--links", ctx->style.text.color));
|
||||
reaktor_accent_color(app));
|
||||
nk_style_pop_font(ctx);
|
||||
nk_layout_row_dynamic(ctx, 4.0f, 1);
|
||||
nk_spacer(ctx);
|
||||
@@ -139,7 +139,7 @@ draw_tooltip(App *app, struct nk_context *ctx, const char *const *lines,
|
||||
struct nk_color ink = reaktor_token("--text-main", nk_rgb(247, 247, 247));
|
||||
struct nk_color edge = reaktor_token("--text-muted",
|
||||
nk_rgb(192, 192, 192));
|
||||
struct nk_color acc = reaktor_token("--links", nk_rgb(86, 199, 255));
|
||||
struct nk_color acc = reaktor_accent_color(app);
|
||||
float pad = 10.0f, line = f->height + 6.0f;
|
||||
float w = 0.0f, h = 2.0f * pad + (float)n * line;
|
||||
struct nk_rect r;
|
||||
@@ -177,9 +177,7 @@ draw_tooltip(App *app, struct nk_context *ctx, const char *const *lines,
|
||||
if (bar >= 0.0f) {
|
||||
struct nk_rect track = nk_rect(r.x + pad, r.y + h - pad - 6.0f,
|
||||
r.w - 2.0f * pad, 6.0f);
|
||||
reaktor_fill_round(app, canvas, track, 3.0f,
|
||||
reaktor_token("--background-body",
|
||||
nk_rgb(37, 37, 37)));
|
||||
reaktor_fill_round(app, canvas, track, 3.0f, reaktor_page_color(app));
|
||||
track.w *= bar;
|
||||
reaktor_fill_round(app, canvas, track, 3.0f, acc);
|
||||
}
|
||||
@@ -832,8 +830,8 @@ section_grid(App *app, struct nk_context *ctx)
|
||||
even = reaktor_token("--table-bg-alt", nk_rgb(37, 37, 37));
|
||||
|
||||
{
|
||||
struct nk_color page = reaktor_token("--background-body", nk_rgb(37, 37, 37));
|
||||
struct nk_color accent = reaktor_token("--links", nk_rgb(0, 112, 224));
|
||||
struct nk_color page = reaktor_page_color(app);
|
||||
struct nk_color accent = reaktor_accent_color(app);
|
||||
struct nk_color want = head_s.matched && head_s.bg[3]
|
||||
? reaktor_col(head_s.bg)
|
||||
: reaktor_token("--table", accent);
|
||||
@@ -1803,8 +1801,8 @@ ease_plot(App *app, struct nk_context *ctx, struct nk_rect slot,
|
||||
unsigned char curve, float head, int strong)
|
||||
{
|
||||
struct nk_command_buffer *cv = nk_window_get_canvas(ctx);
|
||||
struct nk_color line = reaktor_token(strong ? "--links" : "--text-muted",
|
||||
nk_rgb(0, 112, 224));
|
||||
struct nk_color line = strong ? reaktor_accent_color(app)
|
||||
: reaktor_token("--text-muted", nk_rgb(0, 112, 224));
|
||||
struct nk_color grid = reaktor_token("--background-hover",
|
||||
nk_rgba(128, 128, 128, 90));
|
||||
const float over = 0.28f;
|
||||
@@ -1857,7 +1855,7 @@ track_at(App *app, struct nk_context *ctx, struct nk_rect r, float where,
|
||||
+ where * (r.w - box - 2.0f * inset),
|
||||
r.y + inset, box, r.h - 2.0f * inset),
|
||||
5.0f,
|
||||
lit ? reaktor_token("--links", nk_rgb(0, 112, 224))
|
||||
lit ? reaktor_accent_color(app)
|
||||
: reaktor_token("--text-muted",
|
||||
nk_rgb(140, 140, 140)));
|
||||
}
|
||||
@@ -1946,7 +1944,7 @@ clip_demo(App *app, struct nk_context *ctx)
|
||||
struct nk_command_buffer *cv = nk_window_get_canvas(ctx);
|
||||
struct nka_stagger_grid_opts grid = nka_stagger_grid_opts_default();
|
||||
struct nk_colorf rest = nk_color_cf(well_color());
|
||||
struct nk_colorf lit = nk_color_cf(reaktor_token("--links", nk_rgb(0, 112, 224)));
|
||||
struct nk_colorf lit = nk_color_cf(reaktor_accent_color(app));
|
||||
int cols = (int)(r.w / cell), n;
|
||||
float x0;
|
||||
|
||||
@@ -2098,7 +2096,7 @@ path_demo(App *app, struct nk_context *ctx, showcase_state *s)
|
||||
tip = nk_vec2(p.x + 18.0f * cosf(angle), p.y + 18.0f * sinf(angle));
|
||||
nk_stroke_line(cv, p.x, p.y, tip.x, tip.y, 2.0f, well_ink(1.0f));
|
||||
reaktor_fill_round(app, cv, nk_rect(p.x - 8.0f, p.y - 8.0f, 16.0f, 16.0f), 8.0f,
|
||||
reaktor_token("--links", nk_rgb(0, 112, 224)));
|
||||
reaktor_accent_color(app));
|
||||
reaktor_fill_round(app, cv, nk_rect(tip.x - 3.0f, tip.y - 3.0f, 6.0f, 6.0f), 3.0f,
|
||||
well_ink(1.0f));
|
||||
}
|
||||
@@ -2166,7 +2164,7 @@ fx_demo(App *app, struct nk_context *ctx, showcase_state *s)
|
||||
float ax = r.w * 0.34f, ay = (r.h - 24.0f) * 0.36f;
|
||||
struct nk_vec2 c = nk_vec2(r.x + r.w * 0.5f, r.y + (r.h - 24.0f) * 0.5f);
|
||||
struct nk_vec2 d = nk_vec2(0.0f, 0.0f);
|
||||
struct nk_color dot = reaktor_token("--links", nk_rgb(0, 112, 224));
|
||||
struct nk_color dot = reaktor_accent_color(app);
|
||||
int j;
|
||||
|
||||
reaktor_fill_round(app, cv, r, 6.0f, well_color());
|
||||
@@ -2542,7 +2540,7 @@ page_animation(App *app, struct nk_context *ctx, showcase_state *s)
|
||||
struct nk_command_buffer *cv = nk_window_get_canvas(ctx);
|
||||
const struct nk_user_font *f = ctx->style.font;
|
||||
struct nk_colorf rest = nk_color_cf(reaktor_token("--background-alt", nk_rgb(48, 48, 48)));
|
||||
struct nk_colorf lit = nk_color_cf(reaktor_token("--links", nk_rgb(0, 112, 224)));
|
||||
struct nk_colorf lit = nk_color_cf(reaktor_accent_color(app));
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
REAKTOR_ROW(.name = word[i], .flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y) {
|
||||
|
||||
+6
-2
@@ -161,7 +161,7 @@ struct App {
|
||||
|
||||
int theme_mode;
|
||||
int theme_pending;
|
||||
struct nk_color page, card_bg, text;
|
||||
struct nk_color page, card_bg, text, accent;
|
||||
char icon_hex[10];
|
||||
char accent_hex[10];
|
||||
|
||||
@@ -236,6 +236,7 @@ struct App {
|
||||
int shot_failed, dump_failed;
|
||||
int secondary;
|
||||
int settled_run, settle_tries;
|
||||
unsigned style_gen;
|
||||
int build_ms_x100, render_ms_x100, present_ms_x100;
|
||||
};
|
||||
|
||||
@@ -278,7 +279,7 @@ void pop_style(struct nk_context *ctx, style_frame f);
|
||||
void css_field(App *app, struct nk_context *ctx, char *buf, int *len, int cap,
|
||||
const char *hint);
|
||||
int css_button_accent(App *app, struct nk_context *ctx, const char *selector,
|
||||
const char *label, const char *token);
|
||||
const char *label, struct nk_color 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,
|
||||
@@ -305,6 +306,9 @@ reaktor_surface reaktor_rule_surface(const reaktor_style *s, float radius);
|
||||
void reaktor_paint_surface(App *app, struct nk_command_buffer *cv, struct nk_rect r,
|
||||
const reaktor_surface *s);
|
||||
struct nk_rect reaktor_rect_trunc(struct nk_rect b);
|
||||
nk_size reaktor_fade_mark(const struct nk_command_buffer *cv);
|
||||
void reaktor_fade_since(struct nk_context *ctx, const struct nk_command_buffer *cv,
|
||||
nk_size mark, float opacity);
|
||||
|
||||
App *reaktor_main_app(void);
|
||||
const char *reaktor_asset_name(const reaktor_asset *a, const char *fallback);
|
||||
|
||||
+2
-2
@@ -17,9 +17,9 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<string>@PROJECT_VERSION@</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<string>@PROJECT_VERSION@</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>10.13</string>
|
||||
<key>NSHighResolutionCapable</key>
|
||||
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "cssflat.h"
|
||||
|
||||
static int g_fail;
|
||||
|
||||
static const char g_sheet[] =
|
||||
"input:not([type=\"a\"]):not([type=\"b\"]) { color: #ff0000; }\n"
|
||||
"a.x.x { color: #00ff00; }\n"
|
||||
"a:hover:hover { color: #00ff00; }\n"
|
||||
"button.x:hover, input[type=\"range\"] { color: #0000ff; }\n"
|
||||
"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";
|
||||
|
||||
char *
|
||||
reaktor_asset_load(const char *name, size_t *len)
|
||||
{
|
||||
char *out = NULL;
|
||||
long n = 0;
|
||||
|
||||
if (strcmp(name, "test.css") == 0) {
|
||||
n = (long)strlen(g_sheet);
|
||||
out = malloc((size_t)n + 1);
|
||||
if (out) memcpy(out, g_sheet, (size_t)n + 1);
|
||||
} else {
|
||||
FILE *f = fopen(name, "rb");
|
||||
|
||||
if (!f) return NULL;
|
||||
fseek(f, 0, SEEK_END);
|
||||
n = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
out = n >= 0 ? malloc((size_t)n + 1) : NULL;
|
||||
if (out && fread(out, 1, (size_t)n, f) == (size_t)n) {
|
||||
out[n] = 0;
|
||||
} else {
|
||||
free(out);
|
||||
out = NULL;
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
if (out && len) *len = (size_t)n;
|
||||
return out;
|
||||
}
|
||||
|
||||
static void
|
||||
ok(const char *what, int got)
|
||||
{
|
||||
if (!got) g_fail++;
|
||||
printf(" %-52s %s\n", what, got ? "ok" : "FAILED");
|
||||
}
|
||||
|
||||
static int
|
||||
not_twice(const char *css)
|
||||
{
|
||||
const char *p = css, *q;
|
||||
|
||||
while ((p = strstr(p, ":not(")) != NULL) {
|
||||
for (q = p + 5; *q && !strchr(" \t\r\n,{", *q); q++)
|
||||
if (strncmp(q, ":not(", 5) == 0) return 1;
|
||||
p += 5;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
static const char *const test[1] = { "test.css" };
|
||||
static const char *const simple[1] = { "external/simplecss/simple.css" };
|
||||
char *out;
|
||||
int i;
|
||||
|
||||
out = reaktor_css_flatten(test, 1, "light", NULL);
|
||||
ok("a sheet flattens", out != NULL);
|
||||
if (out) {
|
||||
ok("two :not() in one compound are dropped", !strstr(out, "not("));
|
||||
ok("a class named twice is dropped", !strstr(out, ".x.x"));
|
||||
ok("a pseudo-class named twice is dropped", !strstr(out, ":hover:hover"));
|
||||
ok("the rest of a selector list stays", strstr(out, "button.x:hover") != NULL);
|
||||
ok("an attribute value becomes a class", strstr(out, "input.type-range") != NULL);
|
||||
ok("a bare attribute becomes a class", strstr(out, "button.disabled") != NULL);
|
||||
ok(":enabled is dropped", strstr(out, "button:hover") != NULL && !strstr(out, ":enabled"));
|
||||
ok("calc() over pixels is worked out", strstr(out, "padding: 12px 4px;") != NULL);
|
||||
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);
|
||||
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 != NULL && strstr(out, "button") != NULL);
|
||||
ok(" and no compound in it holds two :not()", out != NULL && !not_twice(out));
|
||||
free(out);
|
||||
}
|
||||
|
||||
printf("\n%s\n", g_fail ? "FAILED" : "css: all checks passed");
|
||||
return g_fail ? 1 : 0;
|
||||
}
|
||||
Reference in New Issue
Block a user