Docs, an MIT licence, and a typeface that carries its own
The repository had no README, no licence and two design documents that had stopped being true: FINDINGS still chose litehtml as the engine and discussed pico.css and USWDS, and PLAN's milestones had been superseded several times over. Both are deleted. In their place: a README, MIT, a CONTRIBUTING modelled on CHMate's, and docs/ with DEVELOPMENT (how the CSS reaches the widgets, and fifteen Nuklear behaviours that each cost an afternoon), PERFORMANCE (measured on Windows, with the other platforms marked as expectations rather than buried) and NOTICE (every dependency, its licence read from its own licence file, and its pinned revision). Writing NOTICE turned up the one real licensing problem: the UI face was Karla, taken from inside the Nuklear submodule, which ships that .ttf with no licence anywhere near it - terms that can only be read off a different project are not something to build a distributable on. The face is now Aileron, CC0, vendored under assets/fonts/ along with the runner-up. Its download has no licence file either, so the terms were traced to their source and written down: Aileron-Notice.txt quotes the declaration in the font's own name table, cites the foundry page that matches it, says plainly that this project assembled the file, and reproduces the CC0 legal code. Metadata inside the file the designer built is better provenance than a text file beside it. Aileron is an OTF, which costs nothing - stb_truetype reads CFF outlines - but it did expose that the WebAssembly packager only scanned third_party/ for .css and .ttf. It would have silently dropped the font and fallen back to Nuklear's bitmap default; it now scans assets/ and accepts .otf. Two things found while looking at the pages: a tree header is drawn as two fills, the border rect at a literal 0 rounding and the background at tab.rounding, so the corners show square however round the stylesheet asks for - the same literal 0 that nk_combo_begin_color has. Painting that rect in the surface behind it leaves the rounded fill on its own. And the checkbox and radio grids now sit their box at the right of the cell the way the Edit menu does, through three cell helpers rather than eight hand-written triples of hover-widget-spacer. Section captions go to 16px and the tab strip to 16px; both were too small to read comfortably at the sizes the pages are written for. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
+12
-10
@@ -36,11 +36,13 @@ foreach(sub AUDIO JOYSTICK HAPTIC HIDAPI SENSOR CAMERA POWER GPU TRAY OFFSCREEN)
|
||||
set(SDL_${sub} OFF CACHE BOOL "" FORCE)
|
||||
endforeach()
|
||||
|
||||
# And the render backends this app can never end up on. SDL probes its list
|
||||
# in order and stops at the first that works - on Windows that is Direct3D 11
|
||||
# - so Direct3D 9, Direct3D 12 and Vulkan are compiled in, and their loaders
|
||||
# probed at startup, only to be passed over. Metal and the GL drivers stay:
|
||||
# they are the first choice on macOS, on Linux and under Emscripten.
|
||||
# And the render backends this app can never end up on. SDL tries its list in
|
||||
# order and stops at the first that constructs - on Windows that is Direct3D
|
||||
# 11, which comes first - so Direct3D 9, Direct3D 12 and Vulkan are never
|
||||
# reached at runtime and cost nothing at startup. What they cost is build time
|
||||
# and space in the binary, which is the whole of the saving here. Metal and
|
||||
# the GL drivers stay: they are the first choice on macOS, on Linux and under
|
||||
# Emscripten.
|
||||
foreach(drv RENDER_D3D RENDER_D3D12 RENDER_VULKAN VULKAN)
|
||||
set(SDL_${drv} OFF CACHE BOOL "" FORCE)
|
||||
endforeach()
|
||||
@@ -208,15 +210,15 @@ if(EMSCRIPTEN)
|
||||
target_compile_options(curie_core PRIVATE -Oz)
|
||||
|
||||
# Every asset the app opens is named by a string literal in src/*.c, so
|
||||
# the package is built from those rather than from a directory: the font
|
||||
# directory alone is 1 MB of typefaces against the one that is loaded, and
|
||||
# a hand-written list would go stale the first time a path changed.
|
||||
# the package is built from those rather than from a directory: assets/fonts
|
||||
# holds several faces against the one that is loaded, and a hand-written
|
||||
# list would go stale the first time a path changed.
|
||||
set(WASM_ASSETS "")
|
||||
file(GLOB _curie_srcs "${CMAKE_CURRENT_SOURCE_DIR}/src/*.c")
|
||||
foreach(_s IN LISTS _curie_srcs)
|
||||
file(STRINGS "${_s}" _lines REGEX "third_party/[^\"]*\.(css|ttf)")
|
||||
file(STRINGS "${_s}" _lines REGEX "(third_party|assets)/[^\"]*\.(css|ttf|otf)")
|
||||
foreach(_l IN LISTS _lines)
|
||||
string(REGEX MATCHALL "third_party/[A-Za-z0-9_/.-]*\.(css|ttf)"
|
||||
string(REGEX MATCHALL "(third_party|assets)/[A-Za-z0-9_/.-]*\.(css|ttf|otf)"
|
||||
_paths "${_l}")
|
||||
list(APPEND WASM_ASSETS ${_paths})
|
||||
endforeach()
|
||||
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
# Contributing to Curie
|
||||
|
||||
Pull requests are welcome, and so is an issue that just says "this looks
|
||||
wrong" with a screenshot — a good half of the work in this repository has come
|
||||
from someone pointing at a control and saying it looked off.
|
||||
|
||||
## Getting started
|
||||
|
||||
You need the submodules and a C compiler:
|
||||
|
||||
```bash
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
|
||||
Then `.\build.ps1` on Windows, or `cmake -S . -B build && cmake --build build
|
||||
--parallel` anywhere else. `.\build-wasm.ps1` builds the web target, which is
|
||||
worth doing before you send anything: it uses the same sources and catches
|
||||
assumptions the native build lets through.
|
||||
|
||||
[docs/DEVELOPMENT.md](docs/DEVELOPMENT.md) explains how the CSS reaches the
|
||||
widgets, and lists the Nuklear behaviours that have already cost somebody an
|
||||
afternoon. Read that first if you are touching drawing code.
|
||||
|
||||
## Review process — talk to the maintainer, not the bot
|
||||
|
||||
Automated review is a first pass, not the decision. It is good at spotting a
|
||||
missing bounds check and bad at knowing that a widget is drawn the way it is
|
||||
because the alternative was tried and looked wrong. If a change touches
|
||||
layout, styling or the pacing of frames, say what you tried and what it looked
|
||||
like, and expect a conversation rather than a checklist.
|
||||
|
||||
## Code conventions
|
||||
|
||||
- **C99, and portable.** No compiler extensions in `src/`. Platform code goes
|
||||
behind `_WIN32` / `__EMSCRIPTEN__` / POSIX in the one file that needs it —
|
||||
today that is only `src/util.c`.
|
||||
- **Around 79 columns**, four-space indent, no tabs. Headers keep to it
|
||||
strictly; a source line may run over where breaking it would read worse.
|
||||
- **Comments say why, not what.** The code already says what it does. A
|
||||
comment earns its place by recording the reason, the measurement, or the
|
||||
thing that was tried first and failed.
|
||||
- **`curie_` prefixes** anything crossing a translation unit. Anything that
|
||||
does not cross one is `static`.
|
||||
- **No new dependency without a licence check.** See below.
|
||||
|
||||
## Decisions of record
|
||||
|
||||
These came out of earlier reviews. Treat them as binding unless you make the
|
||||
case for changing one.
|
||||
|
||||
- **Submodules are read, never edited and never quoted.** Everything in
|
||||
`third_party/` is used as it ships. No colour, path, metric or other value
|
||||
is copied out of a submodule into this tree — the app opens the file at
|
||||
runtime and reads it. If you find yourself typing a hex code you saw in a
|
||||
submodule, that is the signal to load the file instead.
|
||||
- **The stylesheet is the source of style.** A colour, radius, border width or
|
||||
padding that appears as a literal in `src/` needs a reason next to it. The
|
||||
legitimate ones are fallbacks for when a stylesheet fails to load.
|
||||
- **MIT-preferred for anything vendored.** Permissive is the requirement; MIT
|
||||
is the default. Record the licence in [docs/NOTICE.md](docs/NOTICE.md) in
|
||||
the same change, read from the project's own licence file rather than from
|
||||
its README.
|
||||
- **Nothing is drawn when nothing has changed.** SDL waits on events and a
|
||||
frame is built only when a widget's state, the pointer's hot region or the
|
||||
window itself has moved. Do not add a timer, a polling loop or an
|
||||
unconditional repaint to make something update; make the thing that changed
|
||||
mark the frame dirty.
|
||||
- **Nuklear fires buttons on press unless told otherwise.** The build defines
|
||||
`NK_BUTTON_TRIGGER_ON_RELEASE` because the default needs a frame while the
|
||||
mouse is held, and a browser delivers press and release in the same task, so
|
||||
that frame never exists. Leave it defined.
|
||||
|
||||
## Security
|
||||
|
||||
Curie reads files at startup and while running: stylesheets through libcss,
|
||||
SVG through plutosvg, fonts through Nuklear's baker. All of them are parsers,
|
||||
and all of them are pointed at paths derived from the application root.
|
||||
|
||||
- Keep every path going through `curie_path()`. It resolves against the root
|
||||
marker, which is what stops a relative path escaping the install.
|
||||
- Do not add a code path that loads a stylesheet, font or image from a
|
||||
location the user has not chosen, and do not add a network fetch.
|
||||
- If you extend the CSS pass in `src/cssflat.c`, remember it runs on input
|
||||
before libcss validates any of it. Bound your reads.
|
||||
|
||||
## Tests
|
||||
|
||||
There is no test suite, and adding one for a UI drawn by an immediate-mode
|
||||
library is not obviously the right thing — so verification here is manual and
|
||||
we would rather it were honest about that.
|
||||
|
||||
For a change of any size, say in the pull request:
|
||||
|
||||
- that both targets build — native and WebAssembly;
|
||||
- which tabs you drove, and what you clicked;
|
||||
- what the Diagnostics tab said before and after, if you touched anything that
|
||||
could affect frame time or memory;
|
||||
- a screenshot, if the change is visible. Set `CURIE_TAB`, `CURIE_SCROLL` and
|
||||
`CURIE_THEME` to land on the same view every time rather than clicking your
|
||||
way there — see [docs/DEVELOPMENT.md](docs/DEVELOPMENT.md).
|
||||
|
||||
Claims about performance want a number from the Diagnostics tab or from the
|
||||
process, not an expectation. Several plausible optimisations in this codebase
|
||||
turned out to be measurably worse.
|
||||
-939
@@ -1,939 +0,0 @@
|
||||
# Curie — Findings
|
||||
|
||||
Research log for a **portable desktop UI that renders real HTML/CSS through
|
||||
Nuklear**. Every claim below was verified against source or a live API, not
|
||||
recalled from memory. Date: 2026-09-05.
|
||||
|
||||
**Governing constraint:** all external sources are **git submodules read
|
||||
dynamically at runtime**. No values are transcribed or code-generated into C
|
||||
headers — upstream stays the single source of truth.
|
||||
|
||||
---
|
||||
|
||||
## 1. Toolchain (verified on this machine)
|
||||
|
||||
| Tool | Version | Note |
|
||||
|---|---|---|
|
||||
| MSVC | 14.44.35207 | VS 2022 Build Tools |
|
||||
| Windows SDK | 10.0.26100 | also 10.0.22621 |
|
||||
| node / npm | 24.16.0 / 11.13.0 | research + asset inspection only |
|
||||
| git | 2.54.0.windows.1 | |
|
||||
| Python | 3.13.13 | |
|
||||
| Emscripten | **absent** | not needed for the native target |
|
||||
|
||||
`build.ps1` locates MSVC via `vswhere`, emits a temp `.bat` (avoids
|
||||
PowerShell→cmd quote mangling) and compiles with `/TC`.
|
||||
|
||||
> **Gotcha:** with `/TC`, `.lib` files **must** follow `/link`, or `cl` treats
|
||||
> them as C source files.
|
||||
|
||||
**Status: `build\curie.exe` compiles and runs** — Nuklear + GDI, zero external
|
||||
runtime dependencies (`user32` / `gdi32` / `Msimg32` only).
|
||||
|
||||
---
|
||||
|
||||
## 2. The pipeline, and who does each stage
|
||||
|
||||
An HTML/CSS renderer decomposes into six stages. The central question of this
|
||||
research was which are available and which we must write.
|
||||
|
||||
| Stage | Provider | Status |
|
||||
|---|---|---|
|
||||
| HTML → DOM | engine | ✅ |
|
||||
| CSS parse | engine | ✅ |
|
||||
| Cascade → computed properties | engine | ✅ |
|
||||
| **Layout (boxes → x/y/w/h)** | engine | ⚠️ **only litehtml** |
|
||||
| Paint | Nuklear canvas | ✅ |
|
||||
| Interaction / behavior | engine + us | ⚠️ **only litehtml** |
|
||||
|
||||
### 2.1 Nuklear must be used as a canvas, not a widget toolkit
|
||||
|
||||
CSS box layout and Nuklear's immediate-mode row/column layout are
|
||||
fundamentally incompatible. `nk_button_label` and friends are unusable here.
|
||||
The supported approach is `nk_window_get_canvas()` → `nk_fill_rect` /
|
||||
`nk_stroke_rect` / `nk_draw_text`. Nuklear still supplies the window, input,
|
||||
fonts, clipping and the draw-command buffer.
|
||||
|
||||
The GDI backend's command coverage was checked and is sufficient:
|
||||
`LINE RECT RECT_FILLED CIRCLE CIRCLE_FILLED ARC ARC_FILLED TRIANGLE POLYGON
|
||||
POLYGON_FILLED POLYLINE TEXT CURVE RECT_MULTI_COLOR IMAGE CUSTOM SCISSOR`.
|
||||
|
||||
### 2.2 CSS carries no behavior
|
||||
|
||||
`:hover` / `:focus` / `:active` are *selectors*. Something must still decide
|
||||
when an element is hovered or focused and drive keyboard navigation. litehtml
|
||||
supplies mouse-driven hover/active state; keyboard navigation and widget
|
||||
semantics remain ours (see §7).
|
||||
|
||||
---
|
||||
|
||||
## 3. 🔴 Blocker that decided the engine: custom properties
|
||||
|
||||
pico.css is built **entirely** on CSS custom properties — **501 declarations**,
|
||||
plus 63 `calc()` and 69 `::before/::after`. Support is therefore
|
||||
make-or-break, and it was measured directly:
|
||||
|
||||
| Engine | `var()` / custom properties | Layout | Verdict |
|
||||
|---|---|---|---|
|
||||
| **libcss** (NetSurf) | **none** — 0 matches in 246 source files | none | ❌ pico renders as nothing |
|
||||
| **htmlcss** | **none** | none | ❌ |
|
||||
| **litehtml** | **yes** — `style.cpp`, `html_tag.cpp` | **yes** | ✅ |
|
||||
|
||||
The libcss result was confirmed against a working control grep
|
||||
(`CSS_PROP_COLOR` matches; `custom` does not), so it is a true negative, not a
|
||||
path error. libcss supports 126 CSS properties, none of them custom.
|
||||
|
||||
**Consequence:** with libcss or htmlcss, every color, spacing and radius in
|
||||
pico.css resolves to unset and the page renders as effectively nothing. Making
|
||||
pico work on those engines would require writing a `var()` substitution pass, a
|
||||
`calc()` evaluator, pseudo-element box generation, a full block/inline layout
|
||||
engine *and* flexbox.
|
||||
|
||||
---
|
||||
|
||||
## 4. Engine decision: **litehtml**
|
||||
|
||||
Given the delegation to pick the best library for interpreting pico.css,
|
||||
litehtml wins unambiguously — it is the only candidate covering the whole
|
||||
pico.css feature surface:
|
||||
|
||||
| pico.css requires | litehtml | evidence |
|
||||
|---|---|---|
|
||||
| 501 custom properties / `var()` | ✅ | `src/style.cpp`, `src/html_tag.cpp` |
|
||||
| 63 `calc()` | ✅ | 5 modules incl. `css_properties.cpp` |
|
||||
| 69 `::before` / `::after` | ✅ | `src/el_before_after.cpp` |
|
||||
| block + inline layout | ✅ | `render_block.cpp`, `render_inline_context.cpp` |
|
||||
| 4 flex rules | ✅ | `render_flex.cpp`, `flex_item.cpp`, `flex_line.cpp` |
|
||||
| 1 grid rule | ⚠️ **must be handled** | no `render_grid` — silently degrades to block. Scope and a ~5-line flexbox shim in **PLAN §7** |
|
||||
| tables | ✅ | `render_table.cpp` |
|
||||
|
||||
### 4.1 It also solves the two biggest risks
|
||||
|
||||
Choosing litehtml **eliminates the layout engine** — previously the single
|
||||
largest work item — and supplies mouse-driven `:hover`/`:active` state.
|
||||
|
||||
### 4.2 The integration surface is a clean fit for Nuklear
|
||||
|
||||
`document_container` is a 34-virtual interface that maps almost 1:1:
|
||||
|
||||
| litehtml callback | Nuklear |
|
||||
|---|---|
|
||||
| `draw_text` | `nk_draw_text` |
|
||||
| `draw_solid_fill` | `nk_fill_rect` |
|
||||
| `draw_borders` | `nk_stroke_rect` |
|
||||
| `draw_linear_gradient` | `nk_fill_rect_multi_color` |
|
||||
| `set_clip` / `del_clip` | `nk_push_scissor` |
|
||||
| `draw_image` | plutosvg → `nk_image` |
|
||||
| `create_font` / `split_text` | GDI font + `nk_font` metrics |
|
||||
| `on_mouse_event` / `on_element_click` / `set_cursor` | Nuklear input |
|
||||
|
||||
It builds with **CMake**, which is MSVC-friendly — unlike NetSurf's Makefile
|
||||
buildsystem.
|
||||
|
||||
### 4.3 ⚠️ The cost: this is no longer strictly "pure C"
|
||||
|
||||
litehtml is **C++ and BSD-3-Clause**, not C and MIT. The mitigation is that it
|
||||
is the *only* C++ component: application logic stays in C, and
|
||||
`document_container` is implemented in a single C++ translation unit that
|
||||
forwards into Nuklear and exposes a C API. The realistic shape is
|
||||
**"pure C app + one C++ binding shim."**
|
||||
|
||||
The alternative — staying strictly pure C on libcss — means writing
|
||||
var()/calc()/layout/flexbox by hand, with pico.css as the hardest possible
|
||||
first target. That is thousands of lines before a single pixel is correct.
|
||||
|
||||
### 4.4 Full candidate comparison
|
||||
|
||||
| Library | License | Lang | Cascade | var() | Layout | Verdict |
|
||||
|---|---|---|---|---|---|---|
|
||||
| **litehtml** | BSD-3 | C++ | ✅ | ✅ | ✅ | **Chosen** |
|
||||
| NetSurf libcss | MIT | C | ✅ | ❌ | ❌ | pure-C fallback |
|
||||
| katana-parser | MIT | C | ❌ parse tree only | ❌ | ❌ | lightweight fallback |
|
||||
| htmlcss | Apache-2.0 | C | ✅ | ❌ | ❌ | dropped |
|
||||
| lexbor | Apache-2.0 | C | ✅ | — | ❌ | license |
|
||||
| gumbo-parser | Apache-2.0 | C | ❌ HTML only | — | ❌ | license |
|
||||
|
||||
### 4.5 htmlcss, for the record
|
||||
|
||||
`run.h` — its "Block run header", i.e. the layout module — declares **zero
|
||||
types and zero functions**. Started, never implemented. What it *does* provide
|
||||
is real: `hcHTMLImport`, `hcCSSImport`, `hcHTMLFindNode`, and a 3411-line
|
||||
`css-compute.c` exposing `hcNodeComputeCSSBox` / `CSSText` / `CSSDisplay`,
|
||||
producing populated `hc_box_t` and `hc_text_t`. Rejected on Apache-2.0 plus
|
||||
the missing var() and layout support.
|
||||
|
||||
### 4.6 The NetSurf stack, for the record
|
||||
|
||||
All MIT, all pure C, all actively maintained — the strongest pure-C option if
|
||||
the C++ dependency is ever ruled out:
|
||||
|
||||
| Repo | Role | Last push |
|
||||
|---|---|---|
|
||||
| `netsurf-browser/libcss` | CSS parser + selection/cascade | 2026-01 |
|
||||
| `netsurf-browser/libdom` | DOM | 2026-01 |
|
||||
| `netsurf-browser/libhubbub` | HTML5 parser | 2026-01 |
|
||||
| `netsurf-browser/libparserutils` | input streams, encodings | 2026-01 |
|
||||
| `netsurf-browser/libwapcaplet` | string interning | 2026-02 |
|
||||
|
||||
---
|
||||
|
||||
## 5. CSS primitive libraries — measured, not guessed
|
||||
|
||||
Every file parsed directly. All are MIT (verified via npm registry).
|
||||
|
||||
| Library | KB | rules | flex | grid | vars | media | `::before/after` | calc |
|
||||
|---|---|---|---|---|---|---|---|---|
|
||||
| 98.css | 26 | 143 | 7 | 0 | **0** | **1** | **0** | 1 |
|
||||
| simple.css | 13 | 124 | 1 | 1 | 26 | 7 | 5 | 3 |
|
||||
| xp.css / 7.css | 250* | 207 | 7 | 0 | **0** | **0** | **0** | 2 |
|
||||
| water.css | 32 | 313 | 1 | 0 | 42 | 92 | 5 | 10 |
|
||||
| **pico.css** ← chosen | 91 | 409 | 4 | 1 | **501** | 18 | **69** | **63** |
|
||||
| nes.css | 276 | 488 | 6 | 0 | 0 | 13 | **169** | 3 |
|
||||
| bulma | 746 | 4502 | 80 | 11 | **5891** | 251 | 37 | 272 |
|
||||
| open-props | 8 | 81 | 1 | 2 | 1 | 2 | 2 | 3 |
|
||||
|
||||
\* xp.css's size is inflated by base64 image assets, which need image decode.
|
||||
|
||||
- **pico.css — selected.** Viable *because* litehtml handles var/calc/pseudo.
|
||||
- **98.css** — most tractable (zero vars, zero pseudo-elements); would have
|
||||
been the bring-up target on a hand-written engine. litehtml removes the need.
|
||||
- **bulma** rejected: 5891 custom properties, 251 media queries.
|
||||
- **nes.css** rejected: its pixel art *is* 169 `::before/::after` + box-shadow.
|
||||
- **CCSS** (`sathify/CCSS`) rejected: MIT, but last commit **2014-11-28**, and
|
||||
it is a CSS *architecture methodology*, not a component library.
|
||||
|
||||
### USWDS — dropped, for the record
|
||||
|
||||
`uswds.css` measures 645 KB / 7706 rules / 424 media queries / 252
|
||||
pseudo-elements — bulma's weight class. Separately, **`uswds/uswds` ships no
|
||||
`dist/`** (API returns 404): compiled CSS exists only in the npm package, and
|
||||
no C engine parses SCSS. Replaced by Open-Color.
|
||||
|
||||
---
|
||||
|
||||
## 6. Resolved component choices
|
||||
|
||||
| Concern | Choice | License |
|
||||
|---|---|---|
|
||||
| Renderer | Nuklear (as canvas, §2.1) | MIT / public domain |
|
||||
| **Platform backend** | **SDL3 3.5.0** + Nuklear's `nuklear_sdl3_renderer.h` | **Zlib** |
|
||||
| HTML/CSS engine | **litehtml** | BSD-3-Clause |
|
||||
| CSS primitives | **pico.css** | MIT |
|
||||
| Colors | **Open-Color** v1.9.1 | MIT |
|
||||
| Icons | **Ionicons** v8.1.0 — 1357 SVGs at `src/svg/` | MIT |
|
||||
| SVG raster | **plutosvg** v0.0.8 + plutovg | MIT |
|
||||
| Font | **open** — see §8 | |
|
||||
|
||||
**Open-Color** ships `open-color.json` beside `open-color.css` at the repo
|
||||
root. The JSON path avoids CSS parsing entirely for palette lookups — useful
|
||||
regardless of engine.
|
||||
|
||||
---
|
||||
|
||||
## 7. Behavior layer
|
||||
|
||||
litehtml covers mouse hover/active. Keyboard navigation, focus management and
|
||||
widget semantics (roving tabindex, menu/combobox/tabs behavior) remain ours.
|
||||
Evaluated sources for the *specification* of that behavior:
|
||||
|
||||
| Source | License | Portability to C |
|
||||
|---|---|---|
|
||||
| **Zag.js** (Ark UI engine) | MIT | **Best** — explicit FSMs, DOM isolated per component |
|
||||
| Ariakit | MIT | `.d.ts` gives state shape; behavior spread across React hooks |
|
||||
| Radix / Base UI / Headless UI | MIT | behavior welded to React components |
|
||||
| React Aria | Apache-2.0 | broad, fails license filter |
|
||||
|
||||
Zag ships 20 primitives split into `anatomy` / `machine` / `connect` / `props`
|
||||
/ `dom`. A machine is literally `states → on → {guard, target, actions}`,
|
||||
which transliterates into a C `switch` table. TypeScript is an *asset* here:
|
||||
the types are the machine-readable contract.
|
||||
|
||||
---
|
||||
|
||||
## 8. Fonts
|
||||
|
||||
### 8.1 CC0 is MIT-friendly — in fact strictly more permissive
|
||||
|
||||
**CC0 is a public domain dedication, not a licence with conditions.** It waives
|
||||
copyright and neighbouring rights worldwide, so it grants *everything* MIT
|
||||
grants and then removes MIT's one obligation: the attribution / licence-notice
|
||||
requirement. Anything CC0 can therefore be vendored into an MIT-licensed
|
||||
project without adding a single condition, and there is no compatibility
|
||||
question to resolve. **CC0 satisfies the project's single-MIT policy.**
|
||||
|
||||
Practical consequence: CC0 assets need no `NOTICE` entry and no licence header
|
||||
propagation, though crediting the author remains courteous.
|
||||
|
||||
### 8.2 Selected: GGBotNet CC0 fonts
|
||||
|
||||
All three verified directly from their itch.io pages — each states *"This Font
|
||||
Software is licensed under the Creative Commons Zero v1"*:
|
||||
|
||||
| Font | Licence | Type | Source |
|
||||
|---|---|---|---|
|
||||
| **Zerove** ← chosen | **CC0 v1** ✅ | display / UI | `ggbot.itch.io/zerove-font` |
|
||||
| **Jupiteroid** | **CC0 v1** ✅ | techno sans | `ggbot.itch.io/jupiteroid-font` |
|
||||
| **Unitblock** | **CC0 v1** ✅ | **monospace** | `ggbot.itch.io/unitblock-font` |
|
||||
|
||||
Unitblock being monospace makes it the natural pairing for any code or tabular
|
||||
UI alongside Zerove.
|
||||
|
||||
### 8.3 ⚠️ Distribution wrinkle
|
||||
|
||||
itch.io is **not a git host**, so these fonts cannot be git submodules — the
|
||||
one exception to the project's submodule rule. Options: vendor the `.ttf`
|
||||
into the repo (CC0 makes this unencumbered), or add a fetch step to
|
||||
`build.ps1`. Vendoring is recommended; CC0 imposes no redistribution terms.
|
||||
|
||||
### 8.4 Alternatives considered, for the record
|
||||
|
||||
| Font | Licence | Type |
|
||||
|---|---|---|
|
||||
| Hack | **MIT** | monospace |
|
||||
| Go Regular / Go Mono | BSD-3 | proportional + mono |
|
||||
| Inter, Public Sans, Fira Sans | OFL-1.1 | proportional |
|
||||
| JetBrains Mono | OFL-1.1 | monospace |
|
||||
|
||||
Hack's licence text confirms: *"The work in the Hack project is Copyright 2018
|
||||
Source Foundry Authors and licensed under the MIT License"* (bundled DejaVu is
|
||||
public domain; the Bitstream Vera portion carries reserved font names).
|
||||
|
||||
Worth recording: **MIT *proportional* UI fonts are essentially nonexistent** —
|
||||
SIL OFL is the fonts world's standard, so an MIT-only filter would have
|
||||
excluded nearly every good UI typeface. For embedding a font in an
|
||||
application, OFL is not meaningfully more restrictive than MIT either; it
|
||||
forbids only selling the font by itself and requires renaming modified
|
||||
versions carrying reserved names. The CC0 route sidesteps the question
|
||||
entirely.
|
||||
|
||||
### 8.5 Bundling mechanics
|
||||
|
||||
With the Nuklear GDI backend a private TTF loads via
|
||||
`AddFontResourceExW(path, FR_PRIVATE, 0)` — pure C + Win32, no new deps.
|
||||
litehtml's `create_font` / `split_text` / `get_text_width` must then be wired
|
||||
to the same GDI metrics, or text will mis-wrap (see §11).
|
||||
|
||||
---
|
||||
|
||||
## 8bis. Platform backends and FreeBSD
|
||||
|
||||
### Licences (read from each project's LICENSE file, not inferred)
|
||||
|
||||
| Backend | Licence | Copyright |
|
||||
|---|---|---|
|
||||
| **SDL3** | **Zlib** | Sam Lantinga, 1997–2026 |
|
||||
| **GLFW** | **Zlib/libpng** | Marcus Geelnard; Camilla Löwy |
|
||||
| **sokol** | **zlib/libpng** (stated verbatim) | Andre Weissflog, 2018 |
|
||||
|
||||
**Zlib is MIT-compatible and marginally more permissive.** Its three
|
||||
conditions are: don't misrepresent the origin, mark modified versions, don't
|
||||
strip the notice from *source* distributions. Unlike MIT it requires **no
|
||||
attribution in binary distributions** — so, as with CC0 (§8.1), it satisfies
|
||||
the single-MIT policy rather than straining it.
|
||||
|
||||
### FreeBSD
|
||||
|
||||
Yes — the stack runs on FreeBSD. Verified against the FreeBSD ports tree and
|
||||
each project's platform gating:
|
||||
|
||||
| Component | FreeBSD | Evidence |
|
||||
|---|---|---|
|
||||
| Nuklear | ✅ | zero platform code in `nuklear.h`; the `x11` backend is native |
|
||||
| **SDL3** | ✅ | `devel/sdl3` in ports; `__FreeBSD__` in `SDL_platform_defines.h` |
|
||||
| **GLFW** | ✅ | `graphics/glfw` in ports; CMake gates X11/Wayland on `UNIX;NOT APPLE` |
|
||||
| **sokol** | ⚠️ | gate is `__linux__ \|\| __unix__` and FreeBSD defines `__unix__`, so it compiles down the X11 path — but BSD is neither referenced nor advertised (0 hits for `__FreeBSD__` in 15k lines of `sokol_app.h`) |
|
||||
| plutovg / plutosvg | ✅ | `graphics/plutovg`, `graphics/plutosvg` both in ports |
|
||||
| litehtml | ✅ | not packaged (`www/litehtml` absent), but portable C++ built from our submodule |
|
||||
| pico.css, Open-Color, Ionicons | ✅ | data files |
|
||||
| OpenGL / X11 | ✅ | `graphics/mesa-libs`, `x11/libX11` in ports |
|
||||
|
||||
**Consequence for the backend choice:** SDL3 and GLFW have first-class
|
||||
FreeBSD support; sokol would probably work but is the only one carrying BSD
|
||||
risk. If FreeBSD is a real target rather than a nice-to-have, that breaks the
|
||||
tie in favour of **SDL3**.
|
||||
|
||||
### SDL3 also solves system theming portably — decisive
|
||||
|
||||
Discovered while implementing the dark title bar. SDL3 ships exactly the API
|
||||
`src/theme.c` hand-rolls per platform:
|
||||
|
||||
| SDL3 symbol | Replaces |
|
||||
|---|---|
|
||||
| `SDL_GetSystemTheme()` → `SDL_SYSTEM_THEME_LIGHT/DARK/UNKNOWN` | registry read, `AppleInterfaceStyle`, XDG portal over D-Bus |
|
||||
| `SDL_EVENT_SYSTEM_THEME_CHANGED` | `WM_SETTINGCHANGE` / `WM_THEMECHANGED` and their per-platform analogues |
|
||||
| `DwmSetWindowAttribute` inside `SDL_windowswindow.c` (4 call sites) | our dark-frame call |
|
||||
|
||||
So adopting SDL3 **deletes the whole per-platform theming layer**, including
|
||||
the two unimplemented paths: the macOS Objective-C translation unit and the
|
||||
Linux/FreeBSD XDG-portal + `_GTK_THEME_VARIANT` work. Combined with
|
||||
first-class macOS and FreeBSD support and Nuklear's ready-made
|
||||
`sdl3_renderer` / `sdl3_opengl3` backends, **SDL3 is the recommendation**.
|
||||
|
||||
Residual gap unchanged by any of this: under Wayland a client still cannot
|
||||
theme a decoration it does not draw.
|
||||
|
||||
### Why a portable backend was sought at all — and when it is *not* worth it
|
||||
|
||||
Recorded because it justifies the project's first external runtime
|
||||
dependency, and the answer is conditional.
|
||||
|
||||
Nuklear already ships **native, zero-dependency** backends for Windows
|
||||
(`gdi`) and Linux/FreeBSD (`x11`). Those three platforms need nothing added.
|
||||
**macOS is the entire reason a portable layer came up**: no native backend
|
||||
exists, so without one you write a Cocoa/Metal backend yourself.
|
||||
|
||||
Beyond windowing, SDL3 also supplies five services Nuklear deliberately does
|
||||
not — the same ones raised as objections #3, #4 and #6 in §13:
|
||||
|
||||
| Service | Hand-rolled | SDL3 |
|
||||
|---|---|---|
|
||||
| System theme + change events | registry / `AppleInterfaceStyle` / XDG portal | `SDL_GetSystemTheme`, `SDL_EVENT_SYSTEM_THEME_CHANGED` |
|
||||
| File dialogs | 3 native implementations | `SDL_ShowOpenFileDialog` / `SaveFile` / `OpenFolder` |
|
||||
| Clipboard | 3 native implementations | `SDL_GetClipboardText` / `SetClipboardText` |
|
||||
| IME / composition | 3 native implementations, genuinely hard | `SDL_StartTextInput`, `SDL_EVENT_TEXT_EDITING(_CANDIDATES)` |
|
||||
| HiDPI scale | 3 native implementations | `SDL_GetWindowDisplayScale`, `SDL_GetWindowPixelDensity` |
|
||||
|
||||
**The decision therefore hinges on one question — is macOS a target?**
|
||||
|
||||
- **No (Windows + Linux + FreeBSD only):** SDL3 buys little. Use `gdi` +
|
||||
`x11`, keep **zero external runtime dependencies**, and implement the five
|
||||
services twice. Windows theming is already done (`src/theme.c`); IME is the
|
||||
costly one. This fits the project's stated instincts best.
|
||||
- **Yes:** SDL3 pays for itself twice — a Cocoa backend nobody writes, plus
|
||||
~15 platform implementations (5 services × 3 platforms) collapsed into 5
|
||||
calls.
|
||||
|
||||
Cost either way: `curie.exe` currently links only `user32` / `gdi32` /
|
||||
`msimg32`. SDL3 would be the first real external dependency in the tree.
|
||||
|
||||
---
|
||||
|
||||
## 9. License ledger
|
||||
|
||||
| Component | License | Filter |
|
||||
|---|---|---|
|
||||
| Nuklear | MIT / public domain | ✅ |
|
||||
| pico.css | MIT | ✅ |
|
||||
| Open-Color | MIT | ✅ |
|
||||
| Ionicons | MIT | ✅ |
|
||||
| plutosvg / plutovg | MIT | ✅ |
|
||||
| **Zerove / Jupiteroid / Unitblock** | **CC0 v1** | ✅ more permissive than MIT (§8.1) |
|
||||
| Hack | MIT | ✅ |
|
||||
| Zag.js | MIT | ✅ |
|
||||
| NetSurf stack (libcss et al.) | MIT | ✅ |
|
||||
| katana-parser | MIT | ✅ |
|
||||
| **litehtml** | **BSD-3-Clause** | ⚠️ permissive, not MIT |
|
||||
| SDL3 / GLFW / sokol | **Zlib** | ✅ more permissive than MIT (§8bis) |
|
||||
| htmlcss | Apache-2.0 | ❌ dropped |
|
||||
| lexbor, gumbo | Apache-2.0 | ❌ |
|
||||
| USWDS | CC0 + Apache-2.0/OFL assets | ❌ dropped |
|
||||
|
||||
---
|
||||
|
||||
## 10. Open decisions
|
||||
|
||||
1. **Accept BSD-3 + C++ for litehtml?** It removes the layout engine entirely.
|
||||
The pure-C alternative (libcss) cannot render pico.css without a large
|
||||
hand-written CSS subsystem. This is the only remaining fork.
|
||||
|
||||
Resolved: engine → litehtml (§4); CSS → pico.css (§5); colours → Open-Color
|
||||
(§6); font → Zerove, CC0 (§8).
|
||||
|
||||
## 11. Risks
|
||||
|
||||
- **C++ boundary** — one shim TU; keep litehtml's types out of the C headers.
|
||||
- **Font metrics** — `create_font` / `split_text` / `get_text_width` must agree
|
||||
with the GDI backend's metrics or text will mis-wrap.
|
||||
- **`display:grid`** — litehtml has no grid renderer; pico's 1 grid rule
|
||||
degrades to block layout.
|
||||
- **Scrolling / viewport** — litehtml renders to a size we choose; scrolling is
|
||||
ours.
|
||||
|
||||
---
|
||||
|
||||
## 12. Repository state
|
||||
|
||||
| Path | Pin | Key asset | Status |
|
||||
|---|---|---|---|
|
||||
| `third_party/nuklear` | master | `nuklear.h`, `demo/gdi/nuklear_gdi.h` | ✅ |
|
||||
| `third_party/litehtml` | master | CMake lib, `document_container.h` | ✅ added |
|
||||
| `third_party/pico` | master | `css/pico.css` (committed) | ✅ added |
|
||||
| `third_party/open-color` | master | `open-color.json` + `.css` | ✅ added |
|
||||
| `third_party/ionicons` | v8.1.0 | `src/svg/` — 1357 SVGs | ✅ |
|
||||
| `third_party/plutosvg` | v0.0.8 | + nested plutovg | ✅ |
|
||||
| `third_party/98css` | main | `style.css` | ⚪ unused, retained as fallback |
|
||||
| ~~`third_party/htmlcss`~~ | — | — | ⛔ removed (§4.5) |
|
||||
| Zerove font | — | `.ttf` | ➕ pending, not a git host (§8.3) |
|
||||
|
||||
`build.ps1` compiles all of `src/*.c`; the build is currently green.
|
||||
|
||||
### Next step
|
||||
|
||||
Vertical slice: implement `document_container` over Nuklear's canvas, load
|
||||
`third_party/pico/css/pico.css` plus a small HTML fragment, and render one
|
||||
real styled button with working `:hover`/`:active`. That validates fonts,
|
||||
metrics, painting and hit-testing in one screen; everything after is
|
||||
incremental.
|
||||
|
||||
---
|
||||
|
||||
## 13. Nuklear: carried-over evaluation
|
||||
|
||||
Imported from a sibling project's assessment (a git client on `libgiturbo`,
|
||||
weighing Nuklear against NAppGUI). Some framing is specific to that project —
|
||||
its `src/sys/` rule, its USWDS palette — but the substance applies here, so it
|
||||
is recorded to be worked through. Each point is annotated with its status
|
||||
**given the decisions already taken in this document**: SDL3 as backend
|
||||
(§8bis), litehtml as engine (§4), plutovg already in-tree.
|
||||
|
||||
### For
|
||||
|
||||
| # | Point | Status here |
|
||||
|---|---|---|
|
||||
| 1 | Best licence on the list: MIT **or** Unlicense, caller's choice. The Unlicense arm is zero-obligation — nothing downstream must carry. NAppGUI's MIT obliges a notice; Nuklear need not | ✅ holds |
|
||||
| 2 | Vendoring is trivial: one header, no build system, no CMake integration | ✅ confirmed — it is a submodule here and `nuklear.h` compiles with two `#define`s |
|
||||
| 3 | Zero dependencies by construction — never opens a window or calls the OS | ✅ confirmed — 31k lines, **zero** platform includes (§2.1) |
|
||||
| 4 | Immediate mode fits a UI that is a projection of state, re-derived each frame | ✅ holds, and more so here: litehtml re-lays-out from the DOM, so the frame is already a projection |
|
||||
| 5 | One code path, three platforms; no per-platform behaviour to test | ✅ strengthened — SDL3 extends this to four (incl. FreeBSD) |
|
||||
| 6 | Design tokens reach **every** pixel, which native widgets structurally cannot | ✅ holds — here it is pico.css + Open-Color rather than USWDS, but the argument is the same, and stronger since litehtml paints everything |
|
||||
|
||||
### Against
|
||||
|
||||
| # | Objection | Status here |
|
||||
|---|---|---|
|
||||
| 1 | You supply the backend; Nuklear's are demos, not a supported portable layer | ⚠️ **Mitigated.** SDL3 *is* a supported portable layer; Nuklear ships `sdl3_renderer`. The glue is ours but thin, and the platform `#ifdef`s collapse to almost none |
|
||||
| 2 | Text is the hard part: font atlas, **no shaping** | ⚠️ **Partly resolved.** Nuklear's atlas is not needed — **plutovg is already in-tree and is a full TTF renderer** (`plutovg_font_face_load_from_file/data`, `plutovg_canvas_fill_text`, `plutovg_font_face_get_metrics`), and litehtml requires its own text path regardless. CJK needs glyph coverage, not shaping, so `目录/文件.txt` is fine. **Complex-script shaping (Arabic, Indic) remains genuinely absent** — that would need HarfBuzz |
|
||||
| 3 | No file dialog | ✅ **Resolved.** SDL3 ships `SDL_ShowOpenFileDialog`, `SDL_ShowSaveFileDialog`, `SDL_ShowOpenFolderDialog` |
|
||||
| 4 | Edit widget has no IME composition and no system clipboard | ✅ **Resolved.** SDL3 ships `SDL_GetClipboardText`/`SDL_SetClipboardText`/`SDL_HasClipboardText`, and `SDL_StartTextInput` / `SDL_SetTextInputArea` with `SDL_EVENT_TEXT_INPUT`, `SDL_EVENT_TEXT_EDITING`, `SDL_EVENT_TEXT_EDITING_CANDIDATES`. Wiring these into the text field is ours |
|
||||
| 5 | **No accessibility on any platform. Not partial — none** | ❌ **Open and unresolved.** Nothing in this stack provides it. litehtml computes ARIA-relevant semantics from the DOM but exposes them to nothing; there is no UIA / AT-SPI / NSAccessibility bridge. This is the one objection no decision here answers |
|
||||
| 6 | HiDPI is manual; redraws every frame; gating is yours | ⚠️ **Partly resolved.** SDL3 supplies `SDL_GetWindowDisplayScale`, `SDL_GetDisplayContentScale`, `SDL_GetWindowPixelDensity`. Applying scale to layout and **gating redraw on input** stay ours |
|
||||
|
||||
### What actually remains open
|
||||
|
||||
1. **Accessibility (#5)** — genuinely nothing, on any platform. If it is a
|
||||
requirement rather than a nice-to-have, it argues against this entire
|
||||
architecture, not against Nuklear specifically. Worth deciding early.
|
||||
2. **Complex-script shaping (#2)** — absent. CJK is fine; Arabic/Indic would
|
||||
need HarfBuzz. Acceptable if the target text is Latin/CJK.
|
||||
3. **Redraw gating and DPI-aware layout (#6)** — ours to write, but bounded.
|
||||
|
||||
### 13.1 Status after the SDL3 decision
|
||||
|
||||
The backend is settled (SDL3 3.5.0, vendored at `third_party/SDL`), which
|
||||
closes several objections outright. What is left, ranked by risk:
|
||||
|
||||
| # | Objection | Now |
|
||||
|---|---|---|
|
||||
| 1 | You supply the backend | ✅ **Closed.** SDL3 is a supported portable layer, and Nuklear ships `nuklear_sdl3_renderer.h`. `SDL_Renderer` selects D3D11/12, Metal or OpenGL/Vulkan per platform, so no GL context is ours to manage |
|
||||
| 3 | No file dialog | ✅ **Closed.** `SDL_ShowOpenFileDialog` / `SaveFile` / `OpenFolder` |
|
||||
| 6 | HiDPI | ⚠️ **Half closed.** SDL3 reports the scale factors; **applying** scale to litehtml layout and **gating redraw on input** remain ours — bounded work |
|
||||
| 4 | IME + clipboard | ⚠️ **API closed, wiring open.** SDL3 supplies the events and clipboard. But Nuklear's edit widget is unusable here (litehtml owns content, §2.1), so a **caret, selection and text-input model over litehtml is ours to build**. Larger than it first appears |
|
||||
| 2 | Text / shaping | ⚠️ **Partly open.** plutovg (already in-tree) renders TTF; CJK needs coverage, not shaping. **Complex scripts — Arabic, Indic — remain unsupported** and would need HarfBuzz. Separately, font *metrics* must agree between `get_text_width`/`split_text` and what is drawn, or text mis-wraps |
|
||||
| 5 | **Accessibility** | ❌ **Fully open, unchanged.** SDL3 does not provide it either. No UIA / AT-SPI / NSAccessibility bridge exists anywhere in this stack |
|
||||
|
||||
**The two that need a decision rather than just work:**
|
||||
|
||||
1. **Accessibility (#5).** Nothing in this architecture provides it, and SDL3
|
||||
did not change that. If it is a requirement, it argues against the whole
|
||||
approach, not against Nuklear. Decide before M2, not after.
|
||||
2. **Complex-script shaping (#2).** Acceptable to skip for Latin/CJK targets;
|
||||
adding HarfBuzz later is possible but is a C++ dependency of its own.
|
||||
|
||||
---
|
||||
|
||||
## 14. Target API/SDK shape
|
||||
|
||||
**Goal recorded; details to be elaborated later.** The developer-facing API
|
||||
that Curie exposes should read like these three, all MIT:
|
||||
|
||||
| Reference | Language | Why it is a model |
|
||||
|---|---|---|
|
||||
| [LCUI](https://github.com/lc-soft/LCUI) | **C** | The closest existing analogue: a C library that builds interfaces from **CSS and XML**. Same premise as Curie — a stylesheet-driven UI in C — so its API decomposition is the most directly transferable |
|
||||
| [NAppGUI](https://nappgui.com/en/home/web/home.html) | **ANSI-C** | An SDK, not just a library: a coherent cross-platform application framework in plain C, with an opinionated object/lifecycle model worth borrowing |
|
||||
| [Freya](https://github.com/marc2332/freya) | Rust (Skia) | Declarative, component-oriented, non-web GUI — the *ergonomics* target, even though the language differs |
|
||||
| [LVGL](https://github.com/lvgl/lvgl) | **C** | MIT, ★24.6k, actively developed. Not an engine alternative — it has no CSS parser, only its own style API — but the **most mature pure-C GUI codebase available**, and a reference for three specific open problems (below) |
|
||||
|
||||
**LVGL is worth singling out** because it answers open items rather than just
|
||||
modelling an API:
|
||||
|
||||
| Our gap | What LVGL has |
|
||||
|---|---|
|
||||
| `display: grid` (PLAN §7) | **`src/layouts/grid`** — a pure-C CSS-grid-style layout, alongside `src/layouts/flex`. If the flexbox shim proves insufficient, this is a portable MIT reference implementation |
|
||||
| Text input (§15.3) | `src/widgets/textarea`, `src/widgets/ime`, `src/widgets/keyboard` — a second reference beside LCUI |
|
||||
| Fonts | `src/font/` with FreeType binding, a font manager, subpixel rendering and binary font loading |
|
||||
|
||||
Taken together these point at: a **C SDK** (not a bare rendering library),
|
||||
stylesheet-driven, with a declarative surface over the retained DOM that
|
||||
litehtml already maintains — rather than exposing `document_container` or
|
||||
Nuklear primitives to callers.
|
||||
|
||||
Open questions deferred to that later elaboration: whether markup is authored
|
||||
as HTML/XML or constructed through C calls; how application state binds to
|
||||
the DOM; and where the Zag-derived behaviour machines (§7) surface in the
|
||||
public API.
|
||||
|
||||
### 14.1 Developer tools — inspect the live tree
|
||||
|
||||
**Wanted, modelled on Freya's devtools** ("examine the component tree in
|
||||
real-time"): a panel that shows the running UI's element tree and lets you
|
||||
select a node and see what the engine actually computed for it.
|
||||
|
||||
This is a natural fit here, and worth noting *why*: litehtml maintains a
|
||||
**retained DOM with computed styles**, so the tree already exists and is
|
||||
already annotated. An immediate-mode UI has no such structure to inspect —
|
||||
the widget tree is gone by the end of the frame. Choosing an HTML/CSS engine
|
||||
buys inspectability essentially for free.
|
||||
|
||||
What it can surface, all from data litehtml already holds:
|
||||
|
||||
| Panel | Source |
|
||||
|---|---|
|
||||
| Element tree | the litehtml DOM |
|
||||
| Computed styles per node | `css_properties` after the cascade |
|
||||
| Box model (margin / border / padding / content) | the render tree's boxes |
|
||||
| Which rule won, and from which stylesheet | the cascade |
|
||||
| Highlight-on-hover overlay | box rects → Nuklear canvas |
|
||||
|
||||
**Notable consequence for §2.1.** The rule "no Nuklear widgets" applies to
|
||||
*application content*, where CSS layout and immediate-mode layout conflict.
|
||||
It does **not** apply to devtools: a tool panel is exactly what Nuklear's own
|
||||
widgets are good at (`nk_tree_push` for the DOM tree, property rows for
|
||||
computed values, a splitter for the layout). So devtools can be built quickly
|
||||
with plain Nuklear while content goes through litehtml — the two coexist
|
||||
cleanly because they occupy different windows.
|
||||
|
||||
Delivery options, to be decided later: a second SDL window (closest to
|
||||
Freya's separate devtools app), or an overlay toggled inside the main window.
|
||||
Either way it should be compile-time gated so release builds carry none of it.
|
||||
|
||||
---
|
||||
|
||||
## 15. Resolutions for the four open objections
|
||||
|
||||
Researched rather than assumed; each claim verified against source.
|
||||
|
||||
### 15.1 #5 Accessibility — what it actually means
|
||||
|
||||
The concern is not "no keyboard support" — that we can write. It is that
|
||||
**assistive technology cannot see the UI at all.**
|
||||
|
||||
A screen reader does not read pixels. It queries an OS accessibility API —
|
||||
NSAccessibility (macOS), UI Automation (Windows), AT-SPI over D-Bus
|
||||
(Linux/BSD) — asking "what is on screen?". A native button answers because
|
||||
the OS widget registers itself in that tree. **Everything Curie draws is a
|
||||
rectangle on a canvas.** To the OS there is one opaque window with nothing
|
||||
inside it.
|
||||
|
||||
| | Native toolkit | Curie today |
|
||||
|---|---|---|
|
||||
| Screen reader announces a button | ✅ automatic | ❌ silent |
|
||||
| Focus ring visible to AT | ✅ | ❌ |
|
||||
| OS zoom / high-contrast modes | ✅ honoured | ❌ ignored |
|
||||
| UI automation (Appium, WinAppDriver) | ✅ can drive it | ❌ finds no elements |
|
||||
| Dictation, switch access, braille | ✅ | ❌ |
|
||||
|
||||
**Why it is architectural rather than a component choice.** No swap fixes it:
|
||||
SDL3 exposes no accessibility API, Nuklear has no widget identity to publish,
|
||||
and litehtml computes ARIA-relevant semantics but publishes them nowhere. Any
|
||||
GUI that paints its own pixels inherits this — Dear ImGui, Nuklear, Freya and
|
||||
essentially every game UI are in the same position. It is the standing trade
|
||||
for total visual control.
|
||||
|
||||
**One mitigation worth knowing.** We are better placed than a typical
|
||||
immediate-mode UI, because litehtml keeps a **retained DOM with roles and
|
||||
semantics already in it**, so a bridge is *possible*: walk the DOM and publish
|
||||
it to UIA / AT-SPI / NSAccessibility. But that is one provider per platform,
|
||||
and a body of work comparable to the rest of the app.
|
||||
|
||||
**The decision:** if assistive-technology support or accessibility-driven UI
|
||||
automation is a real requirement, this architecture is the wrong one and
|
||||
native widgets (NAppGUI's approach) is the honest answer. If the target is a
|
||||
self-contained visual tool, this is the normal accepted trade — but record it
|
||||
deliberately rather than discover it late.
|
||||
|
||||
### 15.2 #2 Complex-script shaping — use HarfBuzz, do not port rustybuzz
|
||||
|
||||
The premise that HarfBuzz fails the licence filter was **wrong**:
|
||||
|
||||
| Option | Licence | Language | Verdict |
|
||||
|---|---|---|---|
|
||||
| **HarfBuzz** | **"Old MIT"** — MIT-family | C++ with a **pure C API** (`hb.h`) | ✅ **Recommended** |
|
||||
| libraqm | MIT, C | wraps HarfBuzz + FriBidi | convenience layer, not an alternative |
|
||||
| SheenFigure | **Apache-2.0**, C | OpenType shaping, ★34 | fails filter; tiny community |
|
||||
| SheenBidi | **Apache-2.0**, C | bidi only | fails filter |
|
||||
| FriBidi | **LGPL-2.1**, C | bidi only | copyleft — excluded |
|
||||
| rustybuzz | MIT, Rust | a *port of* HarfBuzz | see below |
|
||||
|
||||
**The rustybuzz port was measured: 74 files, 29,232 lines of Rust** — and the
|
||||
bulk is exactly what cannot be skipped: `unicode_norm.rs` 3,063 lines,
|
||||
`tag_table.rs` 2,483, `buffer.rs` 1,894, `ot_shaper_indic.rs` 1,883,
|
||||
`ot_layout_gsubgpos.rs` 1,360. It would also be a Rust→C reimplementation *of
|
||||
HarfBuzz*, undertaken to avoid depending on HarfBuzz — which is already MIT
|
||||
and already exposes a C API.
|
||||
|
||||
Decisive: **the C++ concession was already made for litehtml**, so HarfBuzz
|
||||
adds no new category of dependency. There is no pure-C, MIT, production-grade
|
||||
shaper; SheenFigure is the only real candidate and it is Apache-2.0 with 34
|
||||
stars.
|
||||
|
||||
**Plan:** ship without shaping — Latin and CJK are correct without it — and
|
||||
add HarfBuzz behind the same `document_container` text seam if a complex
|
||||
script is ever required. Nothing in the current design forecloses it.
|
||||
|
||||
#### Candidates that are not shapers
|
||||
|
||||
Three further suggestions were checked. **All three solve rasterization, not
|
||||
shaping** — the next stage down the pipeline, and not a substitute:
|
||||
|
||||
- **Shaping** (HarfBuzz): Unicode + font tables (GSUB/GPOS) to positioned
|
||||
glyph IDs — ligatures, contextual forms, mark positioning, Arabic joining,
|
||||
Indic reordering.
|
||||
- **Rasterization** (these three): a glyph outline to pixels.
|
||||
|
||||
| Library | Licence | What it is | Relationship to HarfBuzz |
|
||||
|---|---|---|---|
|
||||
| **VEFontCache** | MIT, C | single-header **GPU glyph atlas / renderer** (stb_truetype, utf8.h, rectpack2D) | *Consumer.* README: "cached text shaping **with HarfBuzz** with simple Latin-style fallback", and "**TODO: HarfBuzz not supported yet, coming soon!!**" — only a Latin fallback shaper exists today |
|
||||
| **Sluggish** | Unlicense, C | **toy/experimental** implementation of Eric Lengyel's Slug rendering algorithm; author calls it "a quick prototype … a useful learning resource" | None. Also **Windows x64 only**, requiring OpenGL 3.2 + GLEW + SDL2. Carries a patent history (README states it no longer applies) |
|
||||
| **Tehreer-Android** | Apache-2.0, Java/Android | Android text engine | *Consumer.* README: "a wrapper over C libraries, FreeType, SheenBidi and **HarfBuzz**" |
|
||||
|
||||
This **reinforces** the recommendation rather than challenging it: two of the
|
||||
three depend on HarfBuzz, and the third is a single-platform prototype. Most
|
||||
telling, Tehreer-Android is by the **SheenFigure author**, who nonetheless
|
||||
chose HarfBuzz over their own shaper for a production Android engine.
|
||||
|
||||
**Separate, genuinely useful takeaway:** VEFontCache is a credible option for
|
||||
a *different* problem — GPU glyph caching — if text rasterization ever becomes
|
||||
a bottleneck. It is not needed now (plutovg already renders TTF via
|
||||
stb_truetype), and a GPU atlas would cut across `SDL_Renderer`'s abstraction,
|
||||
so it is noted rather than adopted.
|
||||
|
||||
Three further candidates were checked, with the same result:
|
||||
|
||||
| Library | Licence | Language | What it actually is |
|
||||
|---|---|---|---|
|
||||
| **trex** | MIT | C++, ★38 | Rasterizer + atlas + shaping — but by its own README it "uses **FreeType**" and "**integrates HarfBuzz** to shape text". A convenience wrapper over both |
|
||||
| **parley** | **Apache-2.0 OR MIT** (dual — it does pass the filter) | Rust, ★723 | Rich-text **layout**. Its four dependencies are Fontique, **HarfRust**, Skrifa and ICU4X; HarfRust is "a Rust port of HarfBuzz" |
|
||||
| **crowbar** | Apache-2.0 | TypeScript, ★48 | Not a library at all — a **shaping debugger** that visualises how GSUB/GPOS lookups transform a string |
|
||||
|
||||
### 15.2.1 The options, stated plainly
|
||||
|
||||
Across all six suggestions, every one either **wraps** HarfBuzz, **ports**
|
||||
HarfBuzz, **debugs** HarfBuzz's output, or solves rasterization instead. That
|
||||
is the finding: there is no production-grade pure-C shaping alternative.
|
||||
|
||||
| # | Option | Verdict |
|
||||
|---|---|---|
|
||||
| **A** | **Ship without shaping** | ✅ **Recommended now.** Latin and CJK are already correct. Adds nothing; forecloses nothing |
|
||||
| **B** | **HarfBuzz directly** | ✅ Old MIT, C API; the C++ concession is already made. Everything else in this table wraps it. The mature choice |
|
||||
| **B2** | **hamza** — see below | ✅ **The pure-C MIT option, and it fits this project's style** |
|
||||
| C | trex | ❌ Pulls in FreeType **and** HarfBuzz, duplicating plutovg's rasterization. ★38 |
|
||||
| D | VEFontCache | ➖ Rasterization, not shaping; its HarfBuzz support is an unimplemented TODO |
|
||||
| E | Port rustybuzz / HarfRust to C | ❌ 29,232 LOC of Rust, to reimplement HarfBuzz and avoid HarfBuzz |
|
||||
| F | SheenFigure | ➖ The only true pure-C shaper, and Apache-2.0 *is* permissive — but **Arabic only**, and dormant. See below |
|
||||
| G | parley | ❌ Right licence, wrong layer and language: Rust + FFI, and it duplicates litehtml's layout role |
|
||||
|
||||
**Bookmark:** crowbar is worth remembering as a *diagnostic* if shaping ever
|
||||
misbehaves — it shows lookup-by-lookup what a shaper does to a string. A tool
|
||||
to reach for, never a dependency.
|
||||
|
||||
#### Correction: there *is* a pure-C **MIT** shaper — hamza
|
||||
|
||||
Stated twice above that none exists. That was wrong.
|
||||
[hamza](https://github.com/saidwho12/hamza) is a **header-only C99
|
||||
Unicode/OpenType shaping library under MIT** — `#define HZ_IMPLEMENTATION`,
|
||||
then include `hz.h`. It vendors exactly like `nuklear.h`, which is precisely
|
||||
this project's preferred shape.
|
||||
|
||||
| | hamza | HarfBuzz |
|
||||
|---|---|---|
|
||||
| Licence | **MIT** | Old MIT |
|
||||
| Language | **C99, header-only** | C++ with a C API |
|
||||
| Integration | drop one header into `third_party/` | CMake/meson subproject |
|
||||
| Optional | `HZ_NO_STDLIB` | — |
|
||||
| Maturity | ★53, one author, last pushed **2025-03** | every browser and OS ships it |
|
||||
| Script coverage | Arabic-focused; broader claims unverified | complete |
|
||||
| Unicode data | generated UCD headers, regenerable from unicode.org | bundled |
|
||||
|
||||
**So the real trade is maturity versus fit**, not licence or language. hamza
|
||||
matches the project's pure-C / MIT / header-only instincts better than
|
||||
anything else found; HarfBuzz is the one every shipping product relies on.
|
||||
|
||||
Nothing forces the choice yet — option A (ship without shaping) stands, and
|
||||
both plug in behind the same `document_container` text seam. Revisit when a
|
||||
complex script becomes a requirement, and prefer hamza if the target scripts
|
||||
are within its coverage.
|
||||
|
||||
#### Correction: there *is* one pure-C permissive shaper
|
||||
|
||||
Stated too broadly above. **SheenFigure is pure C and Apache-2.0 — which is a
|
||||
permissive licence**, in the same family as the BSD-3 and Zlib dependencies
|
||||
already accepted here. So the accurate claim is narrower: there is no pure-C
|
||||
**MIT** shaper, and only one pure-C permissive one. What actually disqualifies
|
||||
it is capability and maintenance, not licence:
|
||||
|
||||
| Property | SheenFigure |
|
||||
|---|---|
|
||||
| Language / deps | pure C; only SheenBidi plus `stddef/stdint/stdlib/string.h` — genuinely minimal |
|
||||
| Licence | Apache-2.0 (permissive) |
|
||||
| Script coverage | **Arabic only** — its README: "Currently, it only supports Arabic script and a subset of GDEF, GSUB and GPOS tables" |
|
||||
| Last commit | **2023-11-17** (~3 years stale); CI still points at the defunct Travis |
|
||||
| Community | ★34, 4 open issues |
|
||||
|
||||
**So it depends what "complex script" means.** If the requirement were
|
||||
*specifically Arabic*, SheenFigure is a legitimate pure-C, permissive,
|
||||
dependency-light answer and worth reconsidering. For Indic, Thai, Khmer or
|
||||
anything broader it does not implement the shaping engines at all, and
|
||||
HarfBuzz remains the only option.
|
||||
|
||||
### 15.3 #4 Text input — the plan, and why no engine swap helps
|
||||
|
||||
**First, is there a better engine? Checked, and no.**
|
||||
|
||||
| Engine | Text editing built in? | Renders pico.css? |
|
||||
|---|---|---|
|
||||
| litehtml | ❌ none — an `<input>` is just a box | ✅ yes |
|
||||
| **LCUI** | ✅ `textinput` + `textcaret` + IME | ❌ **no** — see below |
|
||||
| libcss / htmlcss | ❌ | ❌ |
|
||||
|
||||
LCUI was genuinely promising: MIT, pure C, with `textinput.h`, `textcaret.h`
|
||||
and a per-platform IME layer. But its CSS engine cannot render pico.css.
|
||||
Grepping `lib/css/` for custom properties returns **three matches that are all
|
||||
C decrement operators** (`--i`, `--right`), and the three `calc` hits are a
|
||||
**comment stating calc() is deliberately unimplemented**. That is the same
|
||||
blocker that eliminated libcss (§3). **Swapping engines would trade a working
|
||||
renderer for a text widget — a clear regression.**
|
||||
|
||||
**So the model is ours, and LCUI shows the right shape.** Its platform seam is
|
||||
a five-function vtable (`prockey`, `totext`, `open`, `close`, `setcaret`) plus
|
||||
`ptk_ime_commit(wchar_t*, len)` and `ptk_ime_set_caret(x, y)`. **We do not
|
||||
need that seam** — SDL3 already is it — so only the consumer side is ours:
|
||||
|
||||
| Piece | Approach | Rough size |
|
||||
|---|---|---|
|
||||
| Focus registry | which DOM node has focus; litehtml supplies hit-testing | ~50 LOC |
|
||||
| Edit model | per editable node: UTF-8 buffer, caret index, selection anchor/extent | ~250 LOC |
|
||||
| Key handling | arrows, Home/End, word jumps, Backspace/Delete, shift-select | ~150 LOC |
|
||||
| Clipboard | `SDL_GetClipboardText` / `SDL_SetClipboardText` on Ctrl+C/V/X | ~40 LOC |
|
||||
| IME pre-edit | `SDL_EVENT_TEXT_EDITING` draws composition underlined; `SDL_EVENT_TEXT_INPUT` commits | ~100 LOC |
|
||||
| Caret follow | `SDL_SetTextInputArea` so the candidate window tracks the caret | ~20 LOC |
|
||||
| Hit-test x to caret index | **must reuse the `get_text_width` measure path** | ~60 LOC |
|
||||
|
||||
**That estimate is pessimistic — most of it already exists.** Nuklear embeds a
|
||||
**stb_textedit-derived state machine**: `nk_textedit_init` / `_text` /
|
||||
`_delete` / `_delete_selection` / `_cut` / `_paste` / `_select_all`,
|
||||
**`nk_textedit_undo` and `_redo`** backed by `NK_TEXTEDIT_UNDOSTATECOUNT`,
|
||||
selection state (`select_start`, `select_end`, `has_preferred_x`), and
|
||||
`nk_plugin_copy` / `nk_plugin_paste` hooks. Caret motion, word boundaries,
|
||||
selection and undo — the parts that are genuinely hard to get right — are
|
||||
already in the tree, already tested, and under Nuklear's MIT/public-domain
|
||||
terms. What remains is glue: supply a measurement callback, draw the caret and
|
||||
selection into litehtml's box, and route SDL events in.
|
||||
|
||||
#### The three options
|
||||
|
||||
| | Approach | Cost | Gets you |
|
||||
|---|---|---|---|
|
||||
| **A** ⭐ | **Drive `nk_textedit_*` with our own layout.** Reuse the state machine; supply measurement, drawing and event routing | **~250–300 LOC glue** | Caret, selection, word motion, undo/redo, cut/paste free. No new dependency |
|
||||
| **B** | **Native overlay widget.** On focus, position a real OS control over the box — Win32 `EDIT`, `NSTextField`, GTK `Entry`, and on WASM a real DOM `<input>` | 4 platform implementations | IME, clipboard, undo, spellcheck **and accessibility** for text, all free and locale-correct |
|
||||
| **C** | **Full in-house editor.** Write the model, motion, selection and undo from scratch | ~650+ LOC | Total control; needed only for bidi-aware editing stb_textedit cannot express |
|
||||
|
||||
**Recommended: A now, B as the accessibility lever later.**
|
||||
|
||||
A is clearly cheapest and adds nothing to the dependency set. Its limit is
|
||||
that stb_textedit assumes a single-font, single-direction row model — fine for
|
||||
`<input>` and simple `<textarea>`, strained by bidi or mixed fonts.
|
||||
|
||||
B deserves a second look for one reason: **it is the only option that yields
|
||||
any accessibility at all** (§15.1). A native text control registers itself
|
||||
with the platform's accessibility tree, so screen readers can read and edit
|
||||
that field even though the rest of the UI is opaque pixels. On WASM it is also
|
||||
the *easiest* option, since overlaying a real DOM `<input>` is trivial. If
|
||||
partial accessibility ever becomes a goal, focused text fields are the highest
|
||||
-value place to start, and B is the mechanism.
|
||||
|
||||
C is not justified unless complex-script editing becomes a requirement.
|
||||
|
||||
**Two design rules matter more than the line count:**
|
||||
|
||||
1. **Keep the edit buffer outside litehtml.** Edit in our own model, write the
|
||||
value back to the node and re-layout on change. This is what browsers do —
|
||||
an input's shadow tree is not the document — and it avoids re-entering
|
||||
layout on every keystroke.
|
||||
2. **One measurement path.** Caret placement, hit-testing and drawing must all
|
||||
call the same measure function. Two paths means the caret drifts from the
|
||||
glyphs, the classic failure in hand-rolled editors.
|
||||
|
||||
### 15.4 #6 HiDPI — LCUI's model, and it really is small
|
||||
|
||||
LCUI's `lib/ui/include/ui/metrics.h` is the whole idea:
|
||||
|
||||
```c
|
||||
float ui_get_actual_scale(void);
|
||||
int ui_compute(float value); /* (int)(scale * value) */
|
||||
void ui_compute_rect(pd_rect_t *actual, const ui_rect_t *logical);
|
||||
```
|
||||
|
||||
**The principle: lay out in logical (CSS) pixels and apply scale only at the
|
||||
paint and input boundary.** Never scale the layout itself. Freya does the same
|
||||
through Skia's scale factor. NAppGUI delegates to native widgets, so its
|
||||
approach does not transfer.
|
||||
|
||||
This maps onto our architecture with very little code, precisely because
|
||||
`document_container` is *already* the single boundary between logical layout
|
||||
and device pixels:
|
||||
|
||||
| Step | Change |
|
||||
|---|---|
|
||||
| Read the scale | `SDL_GetWindowDisplayScale()` into one global; refresh on `SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED` |
|
||||
| Paint | multiply rects and coords by scale inside the `draw_*` callbacks — one helper, ~10 call sites |
|
||||
| Fonts | `create_font` rasterises at `size * scale` but reports **unscaled** metrics back to litehtml |
|
||||
| Input | divide SDL mouse coordinates by scale before `on_mouse_event` |
|
||||
| Viewport | report `get_viewport` in logical px (`pixels / scale`) |
|
||||
|
||||
Total: one inline helper, one global, ~10 call sites and two event cases —
|
||||
small only because everything already funnels through one interface.
|
||||
|
||||
**Redraw gating is separate and simpler.** Nuklear repaints every frame by
|
||||
default; replace the polling loop with `SDL_WaitEvent` and repaint only when
|
||||
an event arrives or an animation is pending. A loop change, not an
|
||||
architectural one, and it is what takes idle CPU to zero.
|
||||
|
||||
---
|
||||
|
||||
## 16. Open question: is Nuklear still earning its place?
|
||||
|
||||
Recorded because the answer changed as the architecture settled, and it should
|
||||
be decided deliberately rather than by inertia.
|
||||
|
||||
Nuklear was hired as the whole UI. Two later decisions took most of that away:
|
||||
**litehtml** now owns layout, and **SDL3** now owns drawing. `SDL_Renderer`
|
||||
already provides `SDL_RenderFillRect`, `SDL_RenderLine`, `SDL_RenderTexture`
|
||||
and `SDL_RenderGeometry`, so for application content there are now two
|
||||
abstractions between a CSS box and a pixel:
|
||||
|
||||
```
|
||||
litehtml -> nk_fill_rect -> nk vertex buffer -> SDL_RenderGeometry
|
||||
^ could paint straight here
|
||||
```
|
||||
|
||||
What Nuklear still uniquely supplies:
|
||||
|
||||
| Capability | Still unique to Nuklear? |
|
||||
|---|---|
|
||||
| `nk_textedit_*` state machine (§15.3 option A) | ❌ it is stb_textedit, which is public-domain and usable standalone |
|
||||
| Font atlas / stb_truetype baking | ❌ SDL_ttf or plutovg's text API also cover it |
|
||||
| **A widget set for the devtools panel (§14.1)** | ✅ **yes** — `nk_tree_push`, property rows, splitters |
|
||||
| Draw-command buffering and batching | ➖ useful, but `SDL_Renderer` batches already |
|
||||
|
||||
**So its remaining unique value is the devtools panel.**
|
||||
|
||||
**Recommendation: keep it through M2, then decide.** It is a single
|
||||
MIT/public-domain header costing essentially nothing, and removing it before
|
||||
litehtml is integrated would be optimising an architecture that has not been
|
||||
validated. But if `document_container` ends up painting directly to
|
||||
`SDL_Renderer` — which is the simpler design — then Nuklear becomes "the
|
||||
toolkit the devtools are built in". That is a legitimate reason to keep it,
|
||||
just not the job it was originally brought in for.
|
||||
|
||||
**Decide after M2**, when the paint path is real and the cost of each option
|
||||
is measurable rather than predicted.
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2026 Alpaq92
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -1,611 +0,0 @@
|
||||
# Curie — Plan
|
||||
|
||||
Companion to [FINDINGS.md](FINDINGS.md), which records *what was chosen and
|
||||
why*. This file records *what to build next*.
|
||||
|
||||
---
|
||||
|
||||
## 1. Where we are
|
||||
|
||||
| Piece | State |
|
||||
|---|---|
|
||||
| **Build: one `CMakeLists.txt`** | ✅ clean build, 333 targets; `build.ps1` is now just a wrapper |
|
||||
| **SDL3 backend** (`nuklear_sdl3_renderer`) | ✅ running; picks `direct3d11` here, Metal/GL elsewhere |
|
||||
| **Callback main loop** (`SDL_AppInit/Iterate/Event/Quit`) | ✅ browser-safe from the start (§8.1) |
|
||||
| **litehtml + gumbo** built from submodule | ✅ C++17, no patching needed |
|
||||
| **pico.css rendering** (`container_nk.cpp`, 30 virtuals) | ✅ **first slice renders** |
|
||||
| **Zerove font** (CC0) | ✅ vendored, baked via stb_truetype at device size |
|
||||
| **HiDPI scaling** (`src/metrics.c`, LCUI model) | ✅ verified 1x / 2x; `CURIE_SCALE` override |
|
||||
| System theme + live switching | ✅ portable — `SDL_GetSystemTheme` |
|
||||
| Ionicons → Open-Color icon (window + `.ico` resource) | ✅ verified by pixel sampling |
|
||||
| plutovg + plutosvg | ✅ built as CMake targets |
|
||||
| **Cross-platform (macOS/Linux/BSD/WASM)** | ⬜ **unblocked but unproven** — nothing left but to try it |
|
||||
| Text input, devtools, accessibility | ⬜ see FINDINGS §15.3, §14.1, §15.1 |
|
||||
|
||||
**Binary size:** `curie.exe` 3.99 MB — 2.66 MB of that was the SDL3-trimmed
|
||||
baseline; litehtml accounts for the rest.
|
||||
|
||||
### Two bugs worth remembering
|
||||
|
||||
**`curie_root()` used an ambiguous marker.** It walked up from the executable
|
||||
looking for a `third_party` sibling — but `add_subdirectory(third_party/SDL)`
|
||||
makes CMake mirror that path into the build tree, so `build/third_party/`
|
||||
exists and the walk stopped one level early, resolving the root to
|
||||
`…/Curie/build`. Every asset lookup then failed. Now it looks for a dedicated
|
||||
`.curie-root` sentinel, with a `CURIE_ROOT` environment override for installed
|
||||
layouts and for WASM, where walking up means nothing.
|
||||
|
||||
**Silent fallbacks hide their own cause.** The font loader fell back to
|
||||
Nuklear's bitmap ProggyClean without saying so, which is indistinguishable
|
||||
from "the font never loaded". It now reports either `Zerove @ 16px` or the
|
||||
exact path that failed, in the UI.
|
||||
|
||||
> The window currently shows a **placeholder** ("smoke / toolchain ok /
|
||||
> click"). It exists only to prove Nuklear + GDI compiles, links and runs. No
|
||||
> pico.css is rendered yet — that is M2.
|
||||
|
||||
### Icon pipeline (done)
|
||||
|
||||
`tools/mkicon.c` renders `browsers-outline.svg` at 16/24/32/48/64/128/256 px,
|
||||
recolours it from `open-color.json` (**violet-9** outline `#5f3dc4`,
|
||||
**indigo-3** inside `#91a7ff`), writes `gen/curie.ico` + `gen/curie.rc`;
|
||||
`rc.exe` compiles it and the linker embeds it, so Explorer shows the icon.
|
||||
The running window sets the same glyph at 16/32 px via `WM_SETICON`.
|
||||
|
||||
Both paths share one code path (`curie_svg_surface`), and both read the SVG
|
||||
and the palette from `third_party/` — nothing is hand-transcribed. Changing
|
||||
the glyph or shades means editing the five variables at the top of
|
||||
`build.ps1`. Inspect the recolour without launching the UI:
|
||||
|
||||
```bash
|
||||
./build/curie.exe --dump-icon ./build/icon_check.png
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 2. Portability to Linux and macOS
|
||||
|
||||
Currently Windows-only. The blocker is narrower than it looks: the *asset*
|
||||
pipeline is already portable, and only the platform shell is not.
|
||||
|
||||
| Piece | Today | Portable? |
|
||||
|---|---|---|
|
||||
| plutovg / plutosvg | pure C | ✅ already |
|
||||
| litehtml | portable C++ | ✅ already |
|
||||
| pico.css, Open-Color, Ionicons | data files | ✅ already |
|
||||
| **Window / input / paint** | Nuklear **GDI** backend | ❌ Windows-only |
|
||||
| **Build** | `build.ps1` + MSVC | ❌ Windows-only |
|
||||
| **Exe icon** | `HICON`, `.rc`, `.ico` | ❌ Windows-only |
|
||||
| **Path helpers** | `GetModuleFileNameA` | ❌ Windows-only |
|
||||
| **Font loading** | `AddFontResourceExW` | ❌ Windows-only |
|
||||
|
||||
### 2.1 macOS is the deciding constraint
|
||||
|
||||
To be precise, because it is easy to overstate: **Nuklear runs on macOS.**
|
||||
`nuklear.h` is 31k lines containing *zero* platform includes — no `windows.h`,
|
||||
no X11, no Cocoa, no GL. It only emits draw commands and has no notion of an
|
||||
operating system.
|
||||
|
||||
What is missing is a **native Cocoa/Metal backend** equivalent to `gdi`
|
||||
(Windows) or `x11` (Linux). macOS is nonetheless covered by backends Nuklear
|
||||
already ships demos for:
|
||||
|
||||
| Backend | Windows | Linux | macOS |
|
||||
|---|---|---|---|
|
||||
| `glfw_opengl2/3/4`, `glfw_vulkan` | ✅ | ✅ | ✅ |
|
||||
| `sdl_opengl2/3`, `sdl_renderer`, `sdl3_renderer` | ✅ | ✅ | ✅ |
|
||||
| `sfml_opengl2/3`, `allegro5` | ✅ | ✅ | ✅ |
|
||||
| `rawfb` (you supply the window) | ✅ | ✅ | ✅ |
|
||||
| `gdi`, `gdip`, `d3d9/11/12` | ✅ | ❌ | ❌ |
|
||||
| `x11`, `x11_opengl2/3`, `xcb_cairo` | ❌ | ✅ | ❌ |
|
||||
|
||||
So the constraint is narrower than "macOS is unsupported": Windows and Linux
|
||||
*could* each run a zero-dependency native backend (GDI, X11), but macOS needs
|
||||
a cross-platform one. Maintaining three backends to save one dependency is a
|
||||
bad trade — hence a single cross-platform backend everywhere.
|
||||
|
||||
| Option | Licence | Covers | FreeBSD | Notes |
|
||||
|---|---|---|---|---|
|
||||
| **SDL3 + `sdl3_renderer`** | Zlib | Win, Linux, macOS | ✅ `devel/sdl3` | Nuklear ships the backend; best macOS story. **Recommended** |
|
||||
| GLFW + `glfw_opengl3` | Zlib | Win, Linux, macOS | ✅ `graphics/glfw` | Needs a GL context; GL is deprecated on macOS |
|
||||
| sokol_app + `util/sokol_nuklear.h` | Zlib | Win, Linux, macOS, wasm | ⚠️ untested | Single-header, no external build; only option with BSD risk |
|
||||
| `rawfb` + own shell | — | — | ✅ | No GPU dependency, but you write the platform shells |
|
||||
|
||||
All three are **Zlib**, which is MIT-compatible and slightly *more*
|
||||
permissive — it requires no attribution in binary distributions. Full licence
|
||||
and FreeBSD evidence in FINDINGS §8bis.
|
||||
|
||||
**Zlib is MIT-compatible** — permissive, no copyleft, and it does not even
|
||||
require attribution in binary distributions. Same reasoning as CC0 in
|
||||
FINDINGS §8.1: it satisfies the single-MIT policy.
|
||||
|
||||
### 2.2 Sequencing matters: switch the backend *before* litehtml
|
||||
|
||||
Changing backend also changes font handling — GDI fonts give way to Nuklear's
|
||||
`stb_truetype` font atlas, which is portable **and** is what is needed to load
|
||||
the CC0 TTF anyway (no `AddFontResourceExW`).
|
||||
|
||||
litehtml's `create_font` / `get_text_width` / `split_text` must bind to
|
||||
whatever measures text. Doing the backend switch first means writing that
|
||||
binding **once** instead of twice. This reorders the milestones below.
|
||||
|
||||
### 2.3 Build system: adopt CMake
|
||||
|
||||
The earlier "no CMake" stance was correct for a Windows-only build compiling a
|
||||
handful of submodule `.c` files. It does not survive three platforms, three
|
||||
compilers and a C++ dependency that already ships CMake. `build.ps1` becomes a
|
||||
thin convenience wrapper around `cmake --build`.
|
||||
|
||||
### 2.4 Per-platform icon packaging
|
||||
|
||||
The SVG → RGBA pipeline is portable (plutosvg); only packaging differs.
|
||||
`tools/mkicon.c` grows two output modes:
|
||||
|
||||
| Platform | Artifact | Notes |
|
||||
|---|---|---|
|
||||
| Windows | `.ico` + `.rc` → linked resource | ✅ done |
|
||||
| macOS | `.icns` inside `Foo.app/Contents/Resources` | plus `Info.plist` |
|
||||
| Linux | PNGs in `hicolor/<size>/apps` + `.desktop` | no in-binary icon concept |
|
||||
|
||||
`write_dib` stays Windows-specific; the render loop above it is shared.
|
||||
|
||||
### 2.5 System theme following
|
||||
|
||||
The title bar is drawn by the OS or window manager, never by Nuklear, so
|
||||
matching it to the system scheme is irreducibly platform-specific.
|
||||
`src/theme.h` keeps the portable surface to two calls —
|
||||
`curie_prefers_dark()` and `curie_window_set_dark()` — taking the native
|
||||
window as an opaque `void *`.
|
||||
|
||||
| Platform | Detect | Apply | State |
|
||||
|---|---|---|---|
|
||||
| Windows | `AppsUseLightTheme` registry value | `DwmSetWindowAttribute` attr 20 (19 pre-20H1) | ✅ done |
|
||||
| macOS | `AppleInterfaceStyle` user default | `[NSWindow setAppearance:]` (usually automatic) | ⬜ needs an Obj-C TU |
|
||||
| Linux/FreeBSD (X11) | XDG portal `org.freedesktop.appearance` over D-Bus | `_GTK_THEME_VARIANT` = `"dark"` window property | ⬜ |
|
||||
| Wayland | portal | **not possible** without client-side decorations | ⬜ |
|
||||
|
||||
Live switching is wired on Windows via `WM_SETTINGCHANGE`
|
||||
(`"ImmersiveColorSet"`) and `WM_THEMECHANGED`, which set a dirty flag the
|
||||
main loop consumes — so flipping the system theme re-themes the running app
|
||||
with no restart. Verified: `DwmGetWindowAttribute` reports `value=1` on a
|
||||
dark system, and the re-theme path survives a live notification.
|
||||
|
||||
**Adopting SDL3 deletes this table.** SDL3 ships `SDL_GetSystemTheme()` and
|
||||
`SDL_EVENT_SYSTEM_THEME_CHANGED`, and already calls
|
||||
`DwmSetWindowAttribute` itself on Windows — so both unimplemented rows above
|
||||
(the macOS Objective-C TU and the Linux/FreeBSD portal + `_GTK_THEME_VARIANT`
|
||||
work) simply disappear. `src/theme.c` collapses into two SDL calls at M1.
|
||||
See FINDINGS §8bis.
|
||||
|
||||
**Wayland is the one genuine gap** — a client cannot theme a decoration it
|
||||
does not draw. Applications there either accept the compositor's decoration
|
||||
or do client-side decorations themselves.
|
||||
|
||||
Nuklear's own palette is themed alongside the frame, but only lightly: once
|
||||
litehtml renders pico.css, content theming becomes the stylesheet's job via
|
||||
`prefers-color-scheme`, and `curie_prefers_dark()` becomes the input that
|
||||
picks which media query applies.
|
||||
|
||||
### 2.6 Path helpers
|
||||
|
||||
`curie_root()` needs a portable "where am I" implementation:
|
||||
`GetModuleFileNameA` (Windows), `/proc/self/exe` (Linux),
|
||||
`_NSGetExecutablePath` (macOS). Roughly 20 lines behind one `#ifdef`.
|
||||
|
||||
---
|
||||
|
||||
## 3. Asset loading: runtime vs build-time (the `-Assets` flag)
|
||||
|
||||
Today every asset is read from `third_party/` at startup. That is ideal while
|
||||
iterating and wrong for shipping a single binary. Both modes should exist.
|
||||
|
||||
### 3.1 This does not violate the no-hardcoded-values rule
|
||||
|
||||
Worth stating, because it looks like it might. The rule is that no upstream
|
||||
value is **hand-transcribed** — upstream stays the single source of truth.
|
||||
Baking preserves that: the generator reads the *same submodule files* the
|
||||
runtime path reads, and emits `gen/` output that is generated, never edited
|
||||
and never committed. Bumping a submodule and rebuilding propagates the change
|
||||
with no hand-editing. What stays forbidden is a human copying `#5f3dc4` into
|
||||
a `.c` file. `tools/mkicon.c` already works exactly this way.
|
||||
|
||||
### 3.2 Flag design
|
||||
|
||||
```powershell
|
||||
.\build.ps1 # default: -Assets Runtime
|
||||
.\build.ps1 -Assets Baked # embed everything into the binary
|
||||
```
|
||||
|
||||
Sets `/DCURIE_BAKED_ASSETS` and puts `gen/` on the include path.
|
||||
|
||||
### 3.3 One API, two providers
|
||||
|
||||
Call sites must not branch. `src/curie.h` keeps its signatures; only the
|
||||
provider changes:
|
||||
|
||||
| Function | Runtime | Baked |
|
||||
|---|---|---|
|
||||
| `curie_read_file` | `fopen` under repo root | pointer into a `const` blob |
|
||||
| `curie_oc_color` | scans `open-color.json` | indexes a generated table |
|
||||
| `curie_svg_icon` | plutosvg rasterises on demand | `memcpy` from a pre-rendered array |
|
||||
|
||||
Consequence: in baked mode plutosvg links only into the *generator*, so the
|
||||
shipped binary loses a dependency and all startup rasterisation.
|
||||
|
||||
### 3.4 The generator
|
||||
|
||||
`tools/bake.c`, compiled from the same sources as the app — no new toolchain.
|
||||
Emits into `gen/` (git-ignored):
|
||||
|
||||
| Output | Contents | Source |
|
||||
|---|---|---|
|
||||
| `gen/oc_palette.h` | family/shade → RGB | `open-color/open-color.json` |
|
||||
| `gen/icons.h` | RGBA arrays per icon per size | `ionicons/src/svg/*.svg` |
|
||||
| `gen/pico_css.h` | stylesheet as a byte blob | `pico/css/pico.css` |
|
||||
| `gen/font.h` | TTF bytes | vendored Zerove |
|
||||
|
||||
A manifest (`tools/icons.txt`) keeps it from rasterising all 1357 Ionicons.
|
||||
|
||||
### 3.5 Trade-offs
|
||||
|
||||
| | Runtime | Baked |
|
||||
|---|---|---|
|
||||
| Distribution | needs `third_party/` beside the binary | self-contained |
|
||||
| Startup cost | file I/O + SVG raster per icon | zero |
|
||||
| Iteration | edit CSS, relaunch | rebuild |
|
||||
| Binary size | small | grows with assets |
|
||||
| Hot reload | possible | impossible by construction |
|
||||
|
||||
Keep **Runtime** as the development default; **Baked** is the release mode.
|
||||
|
||||
---
|
||||
|
||||
## 4. Milestones
|
||||
|
||||
### M1 — portable shell ← next
|
||||
1. Adopt CMake; keep `build.ps1` as a wrapper.
|
||||
2. Replace the GDI backend with **SDL3 + `sdl3_renderer`** (or sokol, §2.1).
|
||||
3. Swap GDI fonts for Nuklear's `stb_truetype` atlas.
|
||||
4. Make `curie_root()` portable (§2.5).
|
||||
5. Confirm the window opens on Windows, Linux and macOS.
|
||||
|
||||
**Exit criterion:** the placeholder window runs on all three platforms.
|
||||
|
||||
### M2 — litehtml vertical slice
|
||||
The decisive experiment; everything after is incremental.
|
||||
|
||||
1. Add `third_party/litehtml` to the CMake build.
|
||||
2. `src/container_nk.cpp` — the single C++ TU implementing
|
||||
`document_container`, exposing a C API. Bind first: `create_font`,
|
||||
`get_text_width`, `split_text`, `draw_text`, `draw_solid_fill`,
|
||||
`draw_borders`, `set_clip`/`del_clip`.
|
||||
3. Load `third_party/pico/css/pico.css` + a small HTML fragment, render one
|
||||
styled `<button>` into Nuklear's canvas via `nk_window_get_canvas()`.
|
||||
4. Feed mouse position into `on_mouse_event` so `:hover`/`:active` light up.
|
||||
|
||||
**Exit criterion:** a pico.css-styled button that visibly reacts to hover.
|
||||
|
||||
**Risk to watch:** font metrics. `get_text_width` / `split_text` must agree
|
||||
with what actually gets drawn, or text mis-wraps. Verify by measuring a known
|
||||
string against its drawn width before building anything on top.
|
||||
|
||||
### M3 — Zerove font
|
||||
Vendor the CC0 `.ttf` (itch.io is not a git host — the one documented
|
||||
exception to the submodule rule, FINDINGS §8.3) and load it through the font
|
||||
atlas. Pair with Unitblock for monospace.
|
||||
|
||||
### M4 — `-Assets Baked`
|
||||
Implement §3, after M2, so the generator bakes formats that have settled.
|
||||
|
||||
### M5 — icons in content
|
||||
Route litehtml's `draw_image` to plutosvg so `<img src="…ionicon.svg">`
|
||||
resolves against the Ionicons submodule. The recolour helper generalises.
|
||||
|
||||
### M6 — devtools panel
|
||||
Inspect the live tree, modelled on Freya's devtools (FINDINGS §14.1). Build
|
||||
it with **plain Nuklear widgets** — `nk_tree_push` for the DOM, property rows
|
||||
for computed styles — which is legitimate here because the "no Nuklear
|
||||
widgets" rule (§2.1) constrains application *content*, not tool panels.
|
||||
Sources are all data litehtml already holds: DOM, computed styles, box model,
|
||||
winning cascade rule. Compile-time gated so release builds carry none of it.
|
||||
|
||||
### M7 — behaviour layer
|
||||
Keyboard navigation, focus and widget semantics, ported from Zag.js state
|
||||
machines (FINDINGS §7). litehtml supplies mouse hover/active only.
|
||||
|
||||
---
|
||||
|
||||
## 5. Open decisions
|
||||
|
||||
1. **Accept C++ for litehtml?** (FINDINGS §10) Blocks M2. The pure-C
|
||||
alternative cannot render pico.css without hand-writing var(), calc(),
|
||||
pseudo-elements, block/inline layout and flexbox.
|
||||
2. ~~Backend~~ — **decided: SDL3.** Vendored at `third_party/SDL` (3.5.0,
|
||||
Zlib), paired with Nuklear's `nuklear_sdl3_renderer.h`. Covers Windows,
|
||||
macOS, Linux and FreeBSD, and collapses the theme/dialog/clipboard/IME/DPI
|
||||
layer into SDL calls (FINDINGS §8bis).
|
||||
3. **Accessibility** — nothing in this stack provides it and SDL3 did not
|
||||
change that (FINDINGS §13.1). Decide before M2 whether it is a
|
||||
requirement, because it argues against the architecture rather than
|
||||
against any one component.
|
||||
3. **Vendor the Zerove `.ttf`?** Blocks M3; needs a download.
|
||||
|
||||
## 6. Deliberately not doing
|
||||
|
||||
- ~~No `display:grid`~~ — **moved out of this list; it must be handled.**
|
||||
See §7 below.
|
||||
- **No general SVG CSS engine.** `src/appicon.c` does a targeted recolour of
|
||||
the Ionicons outline idiom (`fill:none`, `stroke:#000`, unfilled `<path>`),
|
||||
not arbitrary SVG restyling.
|
||||
- **No Nuklear widgets.** Nuklear is the canvas and input source; CSS layout
|
||||
and immediate-mode row/column layout cannot coexist (FINDINGS §2.1).
|
||||
|
||||
---
|
||||
|
||||
## 7. ⚠️ `display: grid` — must be handled
|
||||
|
||||
litehtml has **no grid renderer** (confirmed: no `render_grid`, no grid
|
||||
properties in `css_properties.h`), so `display: grid` silently falls back to
|
||||
block. Left alone, every `.grid` container stacks vertically — the mobile
|
||||
layout, on every screen size. It fails quietly, which is what makes it worth
|
||||
flagging.
|
||||
|
||||
**The exposure is small and precisely known.** Pico's entire grid system is
|
||||
one utility class:
|
||||
|
||||
```css
|
||||
.grid {
|
||||
grid-column-gap: var(--pico-grid-column-gap);
|
||||
grid-row-gap: var(--pico-grid-row-gap);
|
||||
display: grid;
|
||||
grid-template-columns: 1fr; /* < 768px */
|
||||
}
|
||||
@media (min-width: 768px) {
|
||||
.grid { grid-template-columns: repeat(auto-fit, minmax(0%, 1fr)); }
|
||||
}
|
||||
.grid > * { min-width: 0; }
|
||||
```
|
||||
|
||||
That is all of it: **3 × `grid-row-gap`, 3 × `grid-column-gap`, 2 ×
|
||||
`grid-template-columns`**, and a single `display: grid`.
|
||||
|
||||
**Fix: a CSS shim, not engine work.** litehtml *does* implement flexbox —
|
||||
`m_flex_grow`, `m_flex_shrink`, `m_flex_basis`, `m_flex_direction`,
|
||||
`m_flex_wrap`, `m_flex_justify_content`, `m_flex_align_items`,
|
||||
`m_flex_align_self` are all present. And `repeat(auto-fit, minmax(0, 1fr))` is
|
||||
semantically "equal columns that wrap", which is exactly `flex: 1 1 0` on the
|
||||
children:
|
||||
|
||||
```css
|
||||
/* loaded after pico.css */
|
||||
.grid { display: flex; flex-wrap: wrap; }
|
||||
.grid > * { flex: 1 1 0; min-width: 0; }
|
||||
```
|
||||
|
||||
Roughly five lines, no engine changes, and it keeps upstream pico.css
|
||||
untouched — the override is a separate stylesheet, so the submodule stays the
|
||||
source of truth.
|
||||
|
||||
**Open detail:** `gap` / `row-gap` / `column-gap` support in litehtml's flex
|
||||
implementation is **unconfirmed** — the property names did not appear in the
|
||||
grep. If gaps are unsupported, use margins on `.grid > *` with a negative
|
||||
margin on the container. Verify during M2, when the first real stylesheet
|
||||
renders.
|
||||
|
||||
---
|
||||
|
||||
## 8. WASM — and what it forces on the design
|
||||
|
||||
A fifth target: the browser, via Emscripten. SDL3 supports it well
|
||||
(`src/video/emscripten/` with events, framebuffer and mouse backends;
|
||||
`SDL_PLATFORM_EMSCRIPTEN`; CMake carries `PreseedEmscriptenCache.cmake`), so
|
||||
the platform itself is not the problem. Two consequences are, and both are
|
||||
cheaper to accept **now** than to retrofit.
|
||||
|
||||
### 8.1 The main loop must be callback-driven — decide before M1
|
||||
|
||||
A browser tab cannot be blocked. A `while (running) { ... }` loop freezes the
|
||||
page: it never yields to the event loop, so nothing renders and the tab hangs.
|
||||
|
||||
SDL3 solves this natively with **main callbacks**: `SDL_MAIN_USE_CALLBACKS`
|
||||
plus `SDL_AppInit` / `SDL_AppIterate` / `SDL_AppEvent` / `SDL_AppQuit`,
|
||||
returning `SDL_APP_CONTINUE`. SDL drives the loop, so on the web it hands
|
||||
control back to the browser each frame, and on native it is an ordinary loop —
|
||||
**identical application code on all five targets**.
|
||||
|
||||
**Therefore M1 should adopt the callback model directly**, rather than porting
|
||||
today's `while (running)` loop and rewriting it later. This is the single
|
||||
highest-value consequence of adding WASM, and it costs nothing to take now.
|
||||
|
||||
It also composes with the redraw gating in §2.5: `SDL_AppIterate` returning
|
||||
early when nothing changed is exactly the right shape, on both web and native.
|
||||
|
||||
### 8.2 Assets: there is no filesystem in a browser
|
||||
|
||||
The governing rule — read every asset from `third_party/` at runtime — has no
|
||||
meaning in a browser tab. `fopen("third_party/pico/css/pico.css")` cannot
|
||||
work. Two options, both legitimate:
|
||||
|
||||
| Option | How | Trade-off |
|
||||
|---|---|---|
|
||||
| **Emscripten preload** | `--preload-file third_party/pico/css/pico.css@/pico.css` packages assets into a `.data` file mounted as a virtual FS | `fopen` keeps working unchanged; **no code changes at all**. Ships a second file next to the `.wasm` |
|
||||
| **`-Assets Baked`** (§3) | assets compiled into the binary | One artifact; smaller total; but requires the baked provider from §3 to exist |
|
||||
|
||||
**Recommendation:** preload for the first WASM build (zero code change), and
|
||||
treat baked mode as the size optimisation it is. Note this **promotes §3 from
|
||||
optional to eventually-required** if a single-artifact web build is wanted.
|
||||
|
||||
### 8.3 An honest note
|
||||
|
||||
We are building an HTML/CSS renderer that will run *inside* a browser, which
|
||||
already has one. That is coherent — the point is one UI codebase rendering
|
||||
identically on five targets, and the web build is how you demo or embed it —
|
||||
but it is worth stating plainly that the browser is the one target where the
|
||||
DOM is already free, and where a thin DOM backend would be less work than
|
||||
litehtml-on-canvas. Not a reason to change course; a reason not to pretend the
|
||||
tradeoff is invisible.
|
||||
|
||||
### 8.4 Toolchain
|
||||
|
||||
**Emscripten is not installed** (checked at project start: `emcc` absent).
|
||||
An `emsdk` install is roughly 1 GB. Nothing else is missing: SDL3 builds under
|
||||
`emcmake cmake`, litehtml is portable C++, plutovg/plutosvg are portable C,
|
||||
and Nuklear has no platform code at all.
|
||||
|
||||
### 8.5 Platform matrix
|
||||
|
||||
| Target | Backend | Status |
|
||||
|---|---|---|
|
||||
| Windows | SDL3 `windows` | ✅ SDL3 built static here (15.6 MB lib, 278 objects) |
|
||||
| macOS | SDL3 `cocoa` (Metal) | ⬜ |
|
||||
| Linux | SDL3 `x11` / `wayland` / `kmsdrm` | ⬜ |
|
||||
| FreeBSD | SDL3 `x11` / `wayland` | ⬜ (FINDINGS §8bis) |
|
||||
| **WASM** | SDL3 `emscripten` | ⬜ needs emsdk; callback loop required |
|
||||
|
||||
---
|
||||
|
||||
## 9. Rendering performance: why we cost more than Explorer, and the ladder out
|
||||
|
||||
All figures below are measured on this machine, not estimated. "Hover" means
|
||||
the pointer driven continuously at ~66 moves/second across the card's buttons
|
||||
and links — a deliberate worst case, several times harsher than real use.
|
||||
|
||||
| Configuration | Hover | Idle |
|
||||
|---|---|---|
|
||||
| AA on (default) | **32.1%** | 0.4% |
|
||||
| AA off (`CURIE_AA=0`) | **8.0%** | 0.3% |
|
||||
| AA off + software renderer | 9.7% | 0.6% |
|
||||
|
||||
Counters from the same runs: `layouts=1, rebuilds=1` (constant), and roughly
|
||||
**6 paints per second** during a sweep. Six repaints costing ~32% means a
|
||||
single full repaint costs on the order of **20 ms of CPU**.
|
||||
|
||||
### 9.1 Why Explorer does more work for less CPU
|
||||
|
||||
It does not do more work. It does **far less work per change**, because the
|
||||
whole native stack is retained-mode with damage tracking:
|
||||
|
||||
| | Explorer / Win32 | Curie today |
|
||||
|---|---|---|
|
||||
| Idle window | composited by DWM from a cached surface; app does nothing | nothing (we gate redraws) — parity |
|
||||
| Hover a button | `InvalidateRect` on that button; `WM_PAINT` arrives clipped to ~100x40 px | **entire page repainted** |
|
||||
| What gets regenerated | the damaged rectangle only | full document walk, every draw command, full tessellation, full vertex upload |
|
||||
| Text | DirectWrite with a system-wide glyph cache | our atlas (fine) but re-tessellated per frame |
|
||||
| Geometry | retained in the control's cached bitmap | rebuilt from scratch every paint |
|
||||
|
||||
So the gap is **granularity, not efficiency**. Explorer repaints ~4,000 px²
|
||||
when you hover a button; we repaint ~294,000 px². That is the entire story,
|
||||
and it is why micro-optimising our paint path would miss the point.
|
||||
|
||||
The AA multiplier compounds it: `nk_convert` emits fringe geometry for every
|
||||
shape, so anti-aliasing costs 4x — but it is also what fixed the jagged edges,
|
||||
so it is a real trade rather than waste.
|
||||
|
||||
### 9.2 The optimisation ladder
|
||||
|
||||
**Level 0 — redraw gating. Done.** Skip the frame entirely when nothing
|
||||
changed. Idle went from ~47% to ~0.3%. This is why idle is already at parity
|
||||
with a native app.
|
||||
|
||||
**Level 1 — use the damage rectangles we already receive.** Cheap, and
|
||||
currently thrown away:
|
||||
|
||||
```cpp
|
||||
// container_nk.cpp today
|
||||
static void noop_redraw(const litehtml::position &) {}
|
||||
d->document->on_mouse_over(x, y, x, y, noop_redraw);
|
||||
```
|
||||
|
||||
That callback **is** the damage list — litehtml tells us exactly which
|
||||
rectangles changed, and we discard every one. Separately,
|
||||
`document::draw(hdc, x, y, const position *clip)` already takes a clip, so
|
||||
passing a damage rect makes litehtml skip elements outside it: fewer draw
|
||||
commands emitted, less geometry tessellated. On its own this is not enough,
|
||||
because the rest of the window would be undefined — which leads to:
|
||||
|
||||
**Level 2 — retained render target. The actual fix.**
|
||||
|
||||
1. Create an `SDL_Texture` with `SDL_TEXTUREACCESS_TARGET`, window-sized.
|
||||
2. Render the page into it **once**.
|
||||
3. Every frame: blit that texture. One textured quad, essentially free.
|
||||
4. On damage: `SDL_SetRenderTarget(tex)`, scissor to the damaged rect, redraw
|
||||
only that region (passing it as litehtml's clip), restore the target.
|
||||
5. Resize or theme change: re-render the whole texture.
|
||||
|
||||
This is precisely Explorer's model — a cached surface plus partial
|
||||
invalidation. Expected effect: hover cost falls from ~20 ms to roughly the
|
||||
damaged fraction of the page, so **1–2 ms**, with anti-aliasing left on.
|
||||
That is the "best of both worlds": idle ~0%, hover near-free, no quality
|
||||
sacrifice, and no loss of responsiveness.
|
||||
|
||||
Estimated effort: moderate — a render target, damage collection, and clip
|
||||
plumbing through `curie_doc_draw`. Roughly 150–250 lines, all in
|
||||
`main.c` and `container_nk.cpp`.
|
||||
|
||||
**Level 3 — stop re-parsing CSS on every page rebuild.** Each theme or
|
||||
diagnostics toggle re-parses ~91 KB of pico plus Open-Color plus app.css,
|
||||
because `document::createFromString` parses stylesheets every time. Rebuilds
|
||||
are rare and user-initiated, so this is not urgent — but it is the reason the
|
||||
theme switch feels heavier than the diagnostics toggle. The real fix is DOM
|
||||
mutation instead of rebuilding, which litehtml supports poorly (§14.1 in
|
||||
FINDINGS covers the same limitation).
|
||||
|
||||
**Level 4 — selective anti-aliasing.** The backend hardcodes
|
||||
`config.shape_AA = config.line_AA = AA`. Text and images gain nothing from
|
||||
fringe geometry; rounded rectangles and strokes do. Splitting them needs
|
||||
either a patched backend or our own `nk_convert` config, which means giving up
|
||||
`nuklear_sdl3_renderer.h` as-is.
|
||||
|
||||
**Level 5 — vertex caching.** Nuklear re-tessellates identical geometry every
|
||||
frame. Level 2 makes this mostly moot: unchanged regions are never
|
||||
re-tessellated at all because they are never redrawn.
|
||||
|
||||
### 9.3 Recommendation
|
||||
|
||||
Do **Level 2**. Levels 3–5 are refinements of a path that Level 2 largely
|
||||
eliminates, and Level 1 is a prerequisite that falls out of it naturally.
|
||||
|
||||
Until then, `CURIE_AA=0` is the honest lever: 4x cheaper hovering, at the cost
|
||||
of the smooth edges AA was added to provide.
|
||||
|
||||
### 9.4 Click latency is a different problem from hover cost
|
||||
|
||||
Measured directly: a page rebuild takes **45-65 ms**. That is the delay on any
|
||||
click that changes state - the theme switch, the diagnostics toggle - and it
|
||||
is entirely CSS re-parsing.
|
||||
|
||||
`document::createFromString` accepts stylesheets only as **strings**, so every
|
||||
rebuild re-parses Open-Color, pico and app.css from scratch. There is no API
|
||||
to hand it an already-parsed stylesheet.
|
||||
|
||||
| Attempt | Rebuild time |
|
||||
|---|---|
|
||||
| `pico.css` (93 KB) | 51-65 ms |
|
||||
| `pico.min.css` (83 KB) | 45-56 ms |
|
||||
|
||||
Minifying bought ~15% and is kept, but it does not solve the problem: parse
|
||||
cost scales with stylesheet size, and pico is simply large.
|
||||
|
||||
**Note the asymmetry the user observed:** hovering is smooth while clicking
|
||||
lags. That is exactly right and diagnostic - hovering only repaints
|
||||
(~20 ms, and no rebuild), whereas clicking re-parses everything (~50 ms) *and*
|
||||
repaints. The two need different fixes.
|
||||
|
||||
**Options for the click path, in order of preference:**
|
||||
|
||||
1. **Re-apply the cascade without re-parsing.** `media_changed()` internally
|
||||
does `refresh_styles()` + `compute_styles()` on the existing tree - exactly
|
||||
the operation needed - but it is gated behind a media-list check and there
|
||||
is no public entry point for "the DOM changed, restyle it". Exposing one
|
||||
(a small patch to litehtml, or a PR upstream) would make theme switching
|
||||
essentially free.
|
||||
2. **Cache documents by state.** Keep a small map from state key
|
||||
(theme + diagnostics visibility) to a built document and swap pointers on
|
||||
click. First visit to a state costs 50 ms, every later toggle is instant.
|
||||
Costs memory: a full DOM and style tree per cached variant.
|
||||
3. **Shrink the stylesheet.** Only pico's used rules are needed; a build-time
|
||||
subset would cut parse time proportionally. Cuts against reading upstream
|
||||
files verbatim at runtime.
|
||||
|
||||
Option 1 is the correct fix and the only one that scales; option 2 is the
|
||||
pragmatic one that needs no upstream change.
|
||||
@@ -0,0 +1,105 @@
|
||||
# Curie
|
||||
|
||||
A desktop application in C where none of the styling is compiled in.
|
||||
|
||||
- **Nuklear** draws every widget and lays out every row.
|
||||
- **libcss**, taken from LCUI, parses a stylesheet at runtime; its computed
|
||||
values are pushed into `nk_style` around each widget call.
|
||||
- **SDL3** supplies the window, the input and the renderer.
|
||||
|
||||
The stylesheet is [tiny.css](https://github.com/ihsan6133/tiny.css), which is
|
||||
classless and written for HTML. Curie reads the rules that have a counterpart
|
||||
in Nuklear — `button`, `input`, `select`, `details`, `summary`, `dialog` — and
|
||||
the palette in `:root`, and maps them onto the widget styles. Edit a colour in
|
||||
`third_party/tinycss/src/`, restart, and the app follows: nothing under `src/`
|
||||
holds a colour of its own.
|
||||
|
||||
The same sources build a native binary and a WebAssembly page.
|
||||
|
||||
## What is in it
|
||||
|
||||
Seven tabs. The first is an ordinary login form; the rest exist to show every
|
||||
control Nuklear has, and what each one looks like once the stylesheet has been
|
||||
applied to it.
|
||||
|
||||
| Tab | What it holds |
|
||||
| --- | --- |
|
||||
| Login | A form, with a themed card, field focus and a contact panel |
|
||||
| Buttons | Labels, symbols, images, repeaters, checkboxes, radios, selectables |
|
||||
| Inputs | Text fields, sliders, progress, knobs, colour picker, property steppers |
|
||||
| Display | Labels, images, charts, tables, trees, list views |
|
||||
| Layout | Static, dynamic and template rows, spaces, groups, splitters |
|
||||
| Popups | Menus, context menus, combos, tooltips, modal dialogs |
|
||||
| Diagnostics | What the renderer chose, where a frame goes, where the memory went |
|
||||
|
||||
At rest the app draws nothing at all and uses no measurable CPU: SDL is told
|
||||
to wait for events, and a frame is built only when something has actually
|
||||
changed.
|
||||
|
||||
## Building
|
||||
|
||||
The dependencies are submodules, so first:
|
||||
|
||||
```bash
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
|
||||
### Windows
|
||||
|
||||
```powershell
|
||||
.\build.ps1
|
||||
```
|
||||
|
||||
Needs Visual Studio Build Tools with "Desktop development with C++". The
|
||||
script locates MSVC, CMake and Ninja inside that install, so nothing has to be
|
||||
on `PATH`.
|
||||
|
||||
### macOS, Linux, the BSDs
|
||||
|
||||
```bash
|
||||
cmake -S . -B build && cmake --build build --parallel
|
||||
```
|
||||
|
||||
### The web
|
||||
|
||||
```powershell
|
||||
.\build-wasm.ps1
|
||||
```
|
||||
|
||||
or, with an activated emsdk on any platform:
|
||||
|
||||
```bash
|
||||
emcmake cmake -S . -B build-wasm && cmake --build build-wasm --parallel
|
||||
```
|
||||
|
||||
A `file://` page cannot fetch the `.wasm`, so serve the output directory:
|
||||
`python -m http.server -d build-wasm 8000`.
|
||||
|
||||
## Where things are
|
||||
|
||||
| Path | What it is |
|
||||
| --- | --- |
|
||||
| `src/main.c` | The shell: window, title bar, tab strip, and the CSS-to-`nk_style` mapping |
|
||||
| `src/showcase.c` | The six showcase pages |
|
||||
| `src/style.c` | libcss: parse the sheets, resolve a selector, hand back computed values |
|
||||
| `src/cssflat.c` | Narrows CSS to what libcss implements, and resolves `var()` first |
|
||||
| `src/appicon.c` | An Ionicons SVG, recoloured and rasterised at runtime |
|
||||
| `src/metrics.c` | The display scale, in one place |
|
||||
| `src/theme.c` | Which colour scheme the desktop is using |
|
||||
| `src/util.c` | Paths, whole-file reads, the resident set |
|
||||
| `tools/mkicon.c` | Bakes the window icon during the build |
|
||||
| `assets/fonts/` | The UI typeface, vendored with its licence — the one exception to the submodule rule |
|
||||
|
||||
## Documentation
|
||||
|
||||
- [docs/DEVELOPMENT.md](docs/DEVELOPMENT.md) — how the pieces fit, and what to
|
||||
know before changing them
|
||||
- [docs/PERFORMANCE.md](docs/PERFORMANCE.md) — size, memory, CPU, and what it
|
||||
needs to run
|
||||
- [docs/NOTICE.md](docs/NOTICE.md) — every dependency and its licence
|
||||
- [CONTRIBUTING.md](CONTRIBUTING.md)
|
||||
|
||||
## Licence
|
||||
|
||||
MIT — see [LICENSE](LICENSE). Third-party licences are listed in
|
||||
[docs/NOTICE.md](docs/NOTICE.md).
|
||||
Binary file not shown.
@@ -0,0 +1,150 @@
|
||||
Aileron - licence notice
|
||||
========================
|
||||
|
||||
Aileron is by Sora Sagano of DOT COLON (dotcolon.net) and is released into the
|
||||
public domain under CC0 1.0 Universal.
|
||||
|
||||
The download does not ship a licence file, so this notice records where the
|
||||
terms come from. Two independent sources, both from the designer:
|
||||
|
||||
1. The font's own `name` table, read from Aileron-Regular.otf:
|
||||
|
||||
copyright No Rights Reserved.
|
||||
manufacturer Sora Sagano
|
||||
designer Sora Sagano
|
||||
vendor URL http://www.dotcolon.net
|
||||
|
||||
2. The foundry's page for the family, https://dotcolon.net/font/aileron,
|
||||
which states "Aileron is No Rights Reserved." beside a link to
|
||||
https://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
It is also listed as CC-0 at https://fontlibrary.org/en/font/aileron
|
||||
|
||||
This file was assembled by the Curie project from those sources. It is not a
|
||||
document supplied by the designer. The CC0 1.0 Universal legal code that the
|
||||
declaration above refers to is reproduced in full below, from
|
||||
https://creativecommons.org/publicdomain/zero/1.0/legalcode
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
Creative Commons Legal Code
|
||||
|
||||
CC0 1.0 Universal
|
||||
|
||||
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
||||
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
||||
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
||||
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
||||
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
||||
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
||||
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
||||
HEREUNDER.
|
||||
|
||||
Statement of Purpose
|
||||
|
||||
The laws of most jurisdictions throughout the world automatically confer
|
||||
exclusive Copyright and Related Rights (defined below) upon the creator
|
||||
and subsequent owner(s) (each and all, an "owner") of an original work of
|
||||
authorship and/or a database (each, a "Work").
|
||||
|
||||
Certain owners wish to permanently relinquish those rights to a Work for
|
||||
the purpose of contributing to a commons of creative, cultural and
|
||||
scientific works ("Commons") that the public can reliably and without fear
|
||||
of later claims of infringement build upon, modify, incorporate in other
|
||||
works, reuse and redistribute as freely as possible in any form whatsoever
|
||||
and for any purposes, including without limitation commercial purposes.
|
||||
These owners may contribute to the Commons to promote the ideal of a free
|
||||
culture and the further production of creative, cultural and scientific
|
||||
works, or to gain reputation or greater distribution for their Work in
|
||||
part through the use and efforts of others.
|
||||
|
||||
For these and/or other purposes and motivations, and without any
|
||||
expectation of additional consideration or compensation, the person
|
||||
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
|
||||
is an owner of Copyright and Related Rights in the Work, voluntarily
|
||||
elects to apply CC0 to the Work and publicly distribute the Work under its
|
||||
terms, with knowledge of his or her Copyright and Related Rights in the
|
||||
Work and the meaning and intended legal effect of CC0 on those rights.
|
||||
|
||||
1. Copyright and Related Rights. A Work made available under CC0 may be
|
||||
protected by copyright and related or neighboring rights ("Copyright and
|
||||
Related Rights"). Copyright and Related Rights include, but are not
|
||||
limited to, the following:
|
||||
|
||||
i. the right to reproduce, adapt, distribute, perform, display,
|
||||
communicate, and translate a Work;
|
||||
ii. moral rights retained by the original author(s) and/or performer(s);
|
||||
iii. publicity and privacy rights pertaining to a person's image or
|
||||
likeness depicted in a Work;
|
||||
iv. rights protecting against unfair competition in regards to a Work,
|
||||
subject to the limitations in paragraph 4(a), below;
|
||||
v. rights protecting the extraction, dissemination, use and reuse of data
|
||||
in a Work;
|
||||
vi. database rights (such as those arising under Directive 96/9/EC of the
|
||||
European Parliament and of the Council of 11 March 1996 on the legal
|
||||
protection of databases, and under any national implementation
|
||||
thereof, including any amended or successor version of such
|
||||
directive); and
|
||||
vii. other similar, equivalent or corresponding rights throughout the
|
||||
world based on applicable law or treaty, and any national
|
||||
implementations thereof.
|
||||
|
||||
2. Waiver. To the greatest extent permitted by, but not in contravention
|
||||
of, applicable law, Affirmer hereby overtly, fully, permanently,
|
||||
irrevocably and unconditionally waives, abandons, and surrenders all of
|
||||
Affirmer's Copyright and Related Rights and associated claims and causes
|
||||
of action, whether now known or unknown (including existing as well as
|
||||
future claims and causes of action), in the Work (i) in all territories
|
||||
worldwide, (ii) for the maximum duration provided by applicable law or
|
||||
treaty (including future time extensions), (iii) in any current or future
|
||||
medium and for any number of copies, and (iv) for any purpose whatsoever,
|
||||
including without limitation commercial, advertising or promotional
|
||||
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
|
||||
member of the public at large and to the detriment of Affirmer's heirs and
|
||||
successors, fully intending that such Waiver shall not be subject to
|
||||
revocation, rescission, cancellation, termination, or any other legal or
|
||||
equitable action to disrupt the quiet enjoyment of the Work by the public
|
||||
as contemplated by Affirmer's express Statement of Purpose.
|
||||
|
||||
3. Public License Fallback. Should any part of the Waiver for any reason
|
||||
be judged legally invalid or ineffective under applicable law, then the
|
||||
Waiver shall be preserved to the maximum extent permitted taking into
|
||||
account Affirmer's express Statement of Purpose. In addition, to the
|
||||
extent the Waiver is so judged Affirmer hereby grants to each affected
|
||||
person a royalty-free, non transferable, non sublicensable, non exclusive,
|
||||
irrevocable and unconditional license to exercise Affirmer's Copyright and
|
||||
Related Rights in the Work (i) in all territories worldwide, (ii) for the
|
||||
maximum duration provided by applicable law or treaty (including future
|
||||
time extensions), (iii) in any current or future medium and for any number
|
||||
of copies, and (iv) for any purpose whatsoever, including without
|
||||
limitation commercial, advertising or promotional purposes (the
|
||||
"License"). The License shall be deemed effective as of the date CC0 was
|
||||
applied by Affirmer to the Work. Should any part of the License for any
|
||||
reason be judged legally invalid or ineffective under applicable law, such
|
||||
partial invalidity or ineffectiveness shall not invalidate the remainder
|
||||
of the License, and in such case Affirmer hereby affirms that he or she
|
||||
will not (i) exercise any of his or her remaining Copyright and Related
|
||||
Rights in the Work or (ii) assert any associated claims and causes of
|
||||
action with respect to the Work, in either case contrary to Affirmer's
|
||||
express Statement of Purpose.
|
||||
|
||||
4. Limitations and Disclaimers.
|
||||
|
||||
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
||||
surrendered, licensed or otherwise affected by this document.
|
||||
b. Affirmer offers the Work as-is and makes no representations or
|
||||
warranties of any kind concerning the Work, express, implied,
|
||||
statutory or otherwise, including without limitation warranties of
|
||||
title, merchantability, fitness for a particular purpose, non
|
||||
infringement, or the absence of latent or other defects, accuracy, or
|
||||
the present or absence of errors, whether or not discoverable, all to
|
||||
the greatest extent permissible under applicable law.
|
||||
c. Affirmer disclaims responsibility for clearing rights of other persons
|
||||
that may apply to the Work or any use thereof, including without
|
||||
limitation any person's Copyright and Related Rights in the Work.
|
||||
Further, Affirmer disclaims responsibility for obtaining any necessary
|
||||
consents, permissions or other rights required for any use of the
|
||||
Work.
|
||||
d. Affirmer understands and acknowledges that Creative Commons is not a
|
||||
party to this document and has no duty or obligation with respect to
|
||||
this CC0 or use of the Work.
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,115 @@
|
||||
This repository is a fork of Libre Franklin: https://github.com/impallari/Libre-Franklin
|
||||
|
||||
## License for USWDS’s Modified Version
|
||||
|
||||
This repository contains both the original font software for Libre Franklin (the “Original Version”) and font software modifications made by the General Services Administration (GSA). This repository combines the Original Version and these GSA modifications into a piece of font software called Public Sans, which is a “Modified Version” of Libre Franklin.
|
||||
|
||||
As a work of the United States Government, the font software modifications made by GSA are not subject to copyright within the United States. Additionally, GSA waives copyright and related rights in its font software modifications worldwide through the [CC0 1.0 Universal public domain dedication](https://creativecommons.org/publicdomain/zero/1.0/).
|
||||
|
||||
The Original Version (as defined in the SIL Open Font License, Version 1.1) remains subject to copyright under the SIL Open Font License, Version 1.1.
|
||||
|
||||
This Modified Version (Public Sans) contains both software under the SIL Open Font License, Version 1.1 and software modifications by GSA released as CC0. As a work of the United States Government, the software modifications made by GSA are not subject to copyright within the United States. Additionally, GSA waives copyright and related rights in its software modifications worldwide through the [CC0 1.0 Universal Public Domain Dedication](https://creativecommons.org/publicdomain/zero/1.0/). It is a “joint work” made of the original software and modifications combined into a single work.
|
||||
|
||||
**In practice, users of this Modified Version (Public Sans) should use Public Sans according to the terms of the SIL Open Font License, Version 1.1, below.** This is because this font is a combination of work subject to copyright and work not subject to copyright, so the more restrictive requirements apply to using the combined work.
|
||||
|
||||
## License of project USWDS’s Modified Version is based on
|
||||
|
||||
- Libre Franklin is licensed under the SIL Open Font License, Version 1.1 (<http://scripts.sil.org/OFL>)
|
||||
- To view the copyright and specific terms and conditions of Libre Franklin, please refer to [OFL.txt](https://github.com/impallari/Libre-Franklin/blob/master/OFL.txt)
|
||||
|
||||
## SIL Open Font License, Version 1.1
|
||||
|
||||
Copyright 2015 The Public Sans Project Authors (https://github.com/uswds/public-sans)
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
|
||||
This license is copied below, and is also available with a FAQ at http://scripts.sil.org/OFL
|
||||
|
||||
```
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font creation
|
||||
efforts of academic and linguistic communities, and to provide a free and
|
||||
open framework in which fonts may be shared and improved in partnership
|
||||
with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply
|
||||
to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as
|
||||
distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to a
|
||||
new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||
redistribute, and sell modified and unmodified copies of the Font
|
||||
Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components,
|
||||
in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the corresponding
|
||||
Copyright Holder. This restriction only applies to the primary font name as
|
||||
presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created
|
||||
using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
```
|
||||
Binary file not shown.
@@ -0,0 +1,209 @@
|
||||
# Development
|
||||
|
||||
How the pieces fit, and what to know before changing them.
|
||||
|
||||
## The pipeline
|
||||
|
||||
```
|
||||
third_party/tinycss/src/*.css
|
||||
|
|
||||
v
|
||||
src/cssflat.c narrows the text to what libcss implements,
|
||||
| and resolves every var() before it gets there
|
||||
v
|
||||
src/style.c libcss: parse, match a selector, compute
|
||||
|
|
||||
v
|
||||
apply_widget_style() in src/main.c - the one place that writes nk_style
|
||||
|
|
||||
v
|
||||
Nuklear draws
|
||||
```
|
||||
|
||||
Three things are worth knowing about that chain.
|
||||
|
||||
**`cssflat` exists because libcss is not a browser.** It parses type, `#id`,
|
||||
`.class` and `:status` selectors joined by descendant combinators, and 85
|
||||
properties. It has no custom properties — `css_computed_style_t` declares a
|
||||
`custom_props` field, but nothing in `lib/css` reads it — and no `@media` at
|
||||
all. Since tiny.css keeps its whole palette in `:root` custom properties, the
|
||||
substitution has to happen before the engine sees the text. That pass also
|
||||
drops `@media` blocks and any selector carrying `[attr]` or a `::pseudo`,
|
||||
which the parser cannot represent, and hands the resolved palette back so the
|
||||
surfaces this app paints itself can read the same values the rules do.
|
||||
|
||||
**`apply_widget_style()` is the only writer of `nk_style`.** Every widget
|
||||
style — button, input, combo, tab, progress, checkbox, slider, tooltip,
|
||||
scrollbar — is set there, from a resolved rule or a palette token. Setting one
|
||||
somewhere else works right up until a theme change reloads the sheets and
|
||||
undoes it.
|
||||
|
||||
**Style lookups are cached, and the rule store is rebuilt per load.** A
|
||||
resolved selector is kept in a small fixed cache; `curie_style_init()` destroys
|
||||
and re-creates libcss's rule store on every call, because parsing adds rules to
|
||||
a global store and nothing takes the previous sheet's rules back out. Without
|
||||
that, switching schemes stacked another copy of tiny.css each time.
|
||||
|
||||
## The frame loop
|
||||
|
||||
There is no loop. SDL is told `SDL_HINT_MAIN_CALLBACK_RATE = "waitevent"`, so
|
||||
`SDL_AppIterate` runs when an event arrives and not otherwise, and it returns
|
||||
immediately unless `app->dirty` is set.
|
||||
|
||||
What sets `dirty`:
|
||||
|
||||
- a widget the shell knows about being clicked, typed into or dragged;
|
||||
- the pointer crossing one of the **hot rectangles** registered during the
|
||||
previous frame (`curie_hot()` and friends) — that is how hover states repaint
|
||||
without polling;
|
||||
- the window moving, resizing or changing scheme.
|
||||
|
||||
While a mouse button is held the callback rate switches to the display's
|
||||
refresh, and a two-frame `restore_rate` settle runs after the release, so the
|
||||
frame that completes a click is not also the frame that stops scheduling
|
||||
frames.
|
||||
|
||||
This is why the app measures 0.00% CPU at rest, and why **adding a timer or an
|
||||
unconditional repaint to make something update is the wrong fix**. Mark the
|
||||
thing that changed instead.
|
||||
|
||||
Frame gaps are measured between the last two drawn frames, not counted over a
|
||||
second: a second only advances when a frame is drawn, so a counted figure
|
||||
reads stale for exactly as long as the app is quiet.
|
||||
|
||||
## Fonts and the atlas
|
||||
|
||||
Five sizes are baked — 12, 13, 14, 16 and 19px — at the display scale, into a
|
||||
single Nuklear atlas texture. `curie_font(app, px, bold)` returns the nearest
|
||||
baked size; `bold` is accepted and ignored — not for want of a face, since
|
||||
`Aileron-Bold.otf` sits beside the regular, but because baking it would put a
|
||||
second set of five faces in the atlas and roughly double the largest allocation
|
||||
the app makes.
|
||||
|
||||
The face is Aileron, CC0, vendored under `assets/fonts/`. It replaced Karla,
|
||||
which came from inside the Nuklear submodule with no licence file anywhere near
|
||||
it — see [NOTICE.md](NOTICE.md#fonts) for where Aileron's terms were traced to.
|
||||
It is an OTF, which costs nothing: stb_truetype reads CFF outlines too. Changing
|
||||
face is one `#define FONT_FILE` in `src/main.c`, and two other vendored faces
|
||||
are there to switch to.
|
||||
|
||||
The atlas is 1024x128 RGBA32, half a megabyte, and is the largest single
|
||||
allocation the application makes. Two things got it there: oversampling is 2x1
|
||||
rather than 3x2 (oversampling costs exactly its area), and the 23px step was
|
||||
dropped because nothing ever asked for it.
|
||||
|
||||
**The remaining lever, not yet taken.** Baking `NK_FONT_ATLAS_ALPHA8` instead
|
||||
of RGBA32 would take the atlas to roughly 0.13 MB with no visible difference —
|
||||
Nuklear draws glyphs by modulating a colour, so the three colour channels
|
||||
carry nothing. It is not done because `nk_sdl_font_stash_end()` in Nuklear's
|
||||
SDL3 backend hard-codes the RGBA32 bake, and this project does not edit
|
||||
submodules. Taking it would mean vendoring that backend — roughly 700 lines,
|
||||
MIT — into `src/` and maintaining it against upstream. Worth doing if the
|
||||
memory matters more than the drift: against a process whose private bytes vary
|
||||
by about 1.8 MB run to run because of the graphics driver, 0.4 MB is below the
|
||||
noise floor.
|
||||
|
||||
## Icons
|
||||
|
||||
Every icon is an Ionicons SVG opened from the submodule at runtime, its stroke
|
||||
recoloured to the theme's `--text-muted` (or an explicit colour), rasterised
|
||||
by plutosvg at twice the drawn size and cached as an SDL texture. No path data
|
||||
and no colour is copied into this tree. The cache is cleared on every theme
|
||||
change, since the colour is baked into the raster.
|
||||
|
||||
The one exception is the window icon, which `tools/mkicon.c` bakes during the
|
||||
build — a window needs its icon before there is a renderer to make textures
|
||||
with.
|
||||
|
||||
## Environment variables
|
||||
|
||||
All read once at startup. The first three exist so a screenshot lands on the
|
||||
same view every time instead of being clicked into place.
|
||||
|
||||
| Variable | Effect |
|
||||
| --- | --- |
|
||||
| `CURIE_TAB` | Which tab opens (0 = Login … 6 = Diagnostics) |
|
||||
| `CURIE_SCROLL` | How far that page starts scrolled |
|
||||
| `CURIE_THEME` | 0 system, 1 light, 2 dark |
|
||||
| `CURIE_SCALE` | Overrides the display scale, in the spirit of `GDK_SCALE` |
|
||||
| `CURIE_ROOT` | Where the assets are, if not found by walking up to `.curie-root` |
|
||||
| `CURIE_RENDERER` | `auto`, `gpu` or `software` |
|
||||
| `CURIE_VSYNC` | `0` turns vsync off |
|
||||
| `CURIE_AA` | `0` turns Nuklear's anti-aliasing off |
|
||||
| `CURIE_FRAME_RATE` | A frame cap, or `0` for uncapped, instead of `waitevent` |
|
||||
| `CURIE_REDRAW` | `always` draws every callback — for profiling, not for use |
|
||||
| `CURIE_STATS` | Logs frame timings once a second |
|
||||
|
||||
The Diagnostics tab reports all of it, plus where each frame's milliseconds
|
||||
went and where the memory went. Prefer it to a guess: several plausible
|
||||
optimisations here turned out to be measurably worse, and one 4x CPU
|
||||
regression was invisible in the build, render and present timings because the
|
||||
cost was inside the renderer.
|
||||
|
||||
## The web build
|
||||
|
||||
Same sources, same `CMakeLists.txt`. The Emscripten-specific parts:
|
||||
|
||||
- Assets are packaged with `--preload-file`, and only the files the sources
|
||||
actually name. The list is built by grepping `src/*.c` at configure time,
|
||||
which is what took the bundle from 3.55 MB to 1.30 MB.
|
||||
- `-Oz` and `--closure 1`. `-Oz` is what runs Binaryen's `wasm-opt`; there is
|
||||
no separate step to add.
|
||||
- `tools/shell.html` is the page. Its loading overlay sets
|
||||
`pointer-events: none` — without that, a full-viewport overlay swallows
|
||||
every canvas click and the app looks dead.
|
||||
- `mkicon` is not built; there is no window to give an icon to.
|
||||
|
||||
## Nuklear behaviours that have already cost an afternoon
|
||||
|
||||
Each of these was found the hard way. They are in the library, not in this
|
||||
code, and none of them is a bug.
|
||||
|
||||
- **Buttons fire on press.** `nk_input_is_mouse_pressed` is `down && clicked`,
|
||||
which needs a frame while the button is held. A browser delivers press and
|
||||
release in one task, so that frame never happens and the button never fires.
|
||||
The build defines `NK_BUTTON_TRIGGER_ON_RELEASE`.
|
||||
- **A button's content rect is bounds − padding − border − *rounding*, on both
|
||||
axes.** A generous radius from the stylesheet can drive a small button's
|
||||
content rect negative, at which point its symbol or image silently vanishes.
|
||||
`compact_push()` in `showcase.c` exists for exactly this.
|
||||
- **`nk_stroke_rect` is asymmetric.** A 2px border measures 1px on the left
|
||||
and top and 2px on the right and bottom. Combos therefore set
|
||||
`combo.border = 0`, and the page strokes the frame itself, inset by half the
|
||||
width.
|
||||
- **`nk_draw_button_text_symbol` always centres the label.** The alignment
|
||||
argument only chooses which side the glyph goes on.
|
||||
- **`nk_do_selectable_image` reads inverted.** `NK_TEXT_ALIGN_LEFT` pins the
|
||||
image to the *right* edge.
|
||||
- **A tree header's border rect is always square.** `NK_TREE_TAB` fills the
|
||||
header twice — the border rect at a literal `0` rounding, then the
|
||||
background inset by `tab.border` at `tab.rounding`. Whatever radius the
|
||||
stylesheet asks for, the outer rect's colour shows through at the corners,
|
||||
so the header reads as a square box. The fix is to paint that rect in the
|
||||
surface behind the header. `nk_combo_begin_color` has the same literal `0`.
|
||||
- **There is one `window.rounding` for every panel**, popups included. Set it
|
||||
around the popup, not globally, or the window corners round twice.
|
||||
- **`nk_menubar_begin` must precede all other layout** in its panel, and pins
|
||||
its row out of any scrolling — hence its own group.
|
||||
- **`nk_group_begin` returns 0 when scrolled out of view.** Returning early
|
||||
from a page on that blanks everything below it.
|
||||
- **`NK_POPUP_DYNAMIC` does not fill its body at begin**, and strokes its
|
||||
border at pre-shrink bounds, so `nk_tooltip` shows a ghost frame. The
|
||||
tooltip here is drawn straight onto the canvas instead.
|
||||
- **`nk_layout_space` does not nest.**
|
||||
- **`nk_image` stretches to its widget slot**, whatever raster size you asked
|
||||
for.
|
||||
- **`nk_rule_horizontal` fills its whole widget rect** — the row height *is*
|
||||
the line thickness.
|
||||
- **Some widgets have no aligned variant.** `nk_checkbox_flags_label` is one;
|
||||
`showcase.c` wraps `nk_checkbox_label_align` in the same four lines the
|
||||
library would have.
|
||||
- **The SDL backend's malloc-only allocator is not a leak.**
|
||||
`nk_buffer_realloc` copies and frees the old pointer itself.
|
||||
|
||||
## Loose ends
|
||||
|
||||
- `src/cssflat.h` still describes the pass in terms of Open-Color and
|
||||
`app.css`, both of which are gone. The code is current; the comment is not.
|
||||
- `assets/demo.html` refers to `third_party/pico`, a submodule that no longer
|
||||
exists, and nothing loads it.
|
||||
@@ -0,0 +1,67 @@
|
||||
# Third-party notices
|
||||
|
||||
Curie itself is MIT (see [LICENSE](../LICENSE)). Everything it is built on is
|
||||
a git submodule under `third_party/`, used as it ships. Each licence below was
|
||||
read from that project's own licence file in the pinned revision, not from its
|
||||
README or its website.
|
||||
|
||||
Refresh the pinned revisions with `git submodule status`.
|
||||
|
||||
| Component | Used for | Licence | Pinned at |
|
||||
| --- | --- | --- | --- |
|
||||
| [SDL](https://github.com/libsdl-org/SDL) | Window, input, renderer, system theme, file dialog | zlib | `release-3.4.16` |
|
||||
| [Nuklear](https://github.com/Immediate-Mode-UI/Nuklear) | Immediate-mode widgets, layout, font baking, SDL3 backend | MIT **or** public domain (Unlicense), your choice | `master` |
|
||||
| [LCUI](https://github.com/lc-soft/LCUI) | `libcss` (parser, selector matching, cascade) and `yutil` (containers, strings) | MIT | `develop` |
|
||||
| [tiny.css](https://github.com/ihsan6133/tiny.css) | The stylesheet the whole look comes from | MIT | `main` |
|
||||
| [Ionicons](https://github.com/ionic-team/ionicons) | Every icon in the app, read as SVG at runtime | MIT | `v8.1.0` |
|
||||
| [plutosvg](https://github.com/sammycage/plutosvg) | Rasterising those SVGs | MIT | `v0.0.8` |
|
||||
| [plutovg](https://github.com/sammycage/plutovg) | The 2D canvas plutosvg draws on (nested submodule) | MIT | tracked by plutosvg |
|
||||
|
||||
Only two of LCUI's libraries are built — `libcss` and `yutil` — not the
|
||||
toolkit. SDL is built static, with the audio, joystick, haptic, HID, sensor,
|
||||
camera, power, GPU, tray and offscreen subsystems disabled, along with the
|
||||
render backends this application can never select.
|
||||
|
||||
## Fonts
|
||||
|
||||
Fonts are the one exception to this project's submodule rule: the faces below are
|
||||
vendored as files under `assets/fonts/`. That is deliberate. The UI face used to be
|
||||
Karla, taken from `third_party/nuklear/extra_font/` — and the Nuklear submodule
|
||||
ships that `.ttf` with no licence anywhere near it, so its terms could only be read
|
||||
off a different project. A dependency whose licence has to be inferred is not one
|
||||
to build a distributable on.
|
||||
|
||||
| Font | Role | Licence | Where the terms are |
|
||||
| --- | --- | --- | --- |
|
||||
| **Aileron** | **The UI face.** Regular is baked; Bold is vendored but not baked. | CC0 1.0 | `assets/fonts/Aileron-Notice.txt` |
|
||||
| Public Sans | Not loaded. The runner-up: a neutral grotesque, close in feel. | SIL Open Font License 1.1 | `assets/fonts/PublicSans-License.md` |
|
||||
| Zerove | Not loaded. Unicase — `a` and `A` are the same outline at 1434 units — so a wordmark face, not a UI one. | CC0 1.0 | `assets/fonts/Zerove-License.txt` |
|
||||
|
||||
Aileron is by Sora Sagano of DOT COLON. Its download ships no licence file either,
|
||||
so rather than repeat Karla's problem the terms were traced to their source and
|
||||
written down: the font's own `name` table carries `copyright: No Rights Reserved.`
|
||||
alongside the designer and foundry, and dotcolon.net/font/aileron states the same
|
||||
beside a CC0 link. Metadata inside the file the designer built is better provenance
|
||||
than a text file next to it, and `Aileron-Notice.txt` records both, says plainly
|
||||
that the project assembled it, and reproduces the CC0 legal code it refers to.
|
||||
|
||||
Aileron is an OTF. Nuklear bakes through stb_truetype, which reads CFF outlines as
|
||||
well as TrueType ones, so the format costs nothing. Switching face is one line —
|
||||
`FONT_FILE` in `src/main.c`.
|
||||
|
||||
Six other faces were built and looked at before this one: Jupiteroid, Liber Struct,
|
||||
Vegur, Tenderness, Seshat and Medio (all CC0), plus Karla and IBM Plex Sans (OFL).
|
||||
None is in the tree.
|
||||
|
||||
## What is redistributed
|
||||
|
||||
A native build links SDL, libcss, yutil, plutosvg and plutovg statically, and
|
||||
compiles Nuklear into the binary. That binary therefore carries the zlib and
|
||||
MIT terms above, all of which are satisfied by shipping this file with it.
|
||||
|
||||
The application does **not** embed the stylesheet, the icons or the font: it
|
||||
opens them at runtime from the submodule checkout, resolved relative to the
|
||||
`.curie-root` marker. A distributable build has to ship those files alongside
|
||||
the binary. The WebAssembly build is the exception — Emscripten packages the
|
||||
handful of files actually referenced into `curie.data`, which is why that
|
||||
bundle needs no checkout beside it.
|
||||
@@ -0,0 +1,176 @@
|
||||
# Performance
|
||||
|
||||
Every number below was measured, not estimated. Where a figure is an
|
||||
expectation rather than a measurement it says so.
|
||||
|
||||
**Measured on:** Windows 11 Pro (26200), x64, MSVC Release, Direct3D 11, one
|
||||
display at 1.00x scale, 960x680 window. That is the only platform these
|
||||
figures come from — see [System requirements](#system-requirements) for what
|
||||
is and is not known about the others.
|
||||
|
||||
Reproduce any of it from the **Diagnostics** tab, which reports the renderer,
|
||||
the frame breakdown, the memory and the startup cost of each step.
|
||||
|
||||
## Size
|
||||
|
||||
| Artefact | Bytes |
|
||||
| --- | --- |
|
||||
| `curie.exe` | 2,686,464 |
|
||||
| `curie.wasm` | 1,194,540 |
|
||||
| `curie.js` | 76,222 |
|
||||
| `curie.data` | 36,215 |
|
||||
| `curie.html` | 1,019 |
|
||||
| **Web bundle, total** | **1,307,996** |
|
||||
|
||||
The binary links SDL, libcss, yutil, plutosvg and plutovg statically and
|
||||
compiles Nuklear in, so nothing but the C runtime is loaded from outside it.
|
||||
Trimming SDL to the subsystems this app uses — no audio, joystick, haptic,
|
||||
HID, sensor, camera, power, GPU, tray or offscreen — and dropping the render
|
||||
backends it can never select took it from 3.39 MB to its present size.
|
||||
|
||||
The web bundle was 3.55 MB before two changes: `-Oz` with `--closure 1`, and
|
||||
packaging only the asset files the sources actually name rather than the
|
||||
directories they live in. `curie.data` fell from 1,868,661 bytes to 36,215 on
|
||||
its own.
|
||||
|
||||
## Memory
|
||||
|
||||
Steady state after startup, on the Login tab:
|
||||
|
||||
| Counter | Value |
|
||||
| --- | --- |
|
||||
| Private bytes | 8.4 MB |
|
||||
| Working set | 23–30 MB |
|
||||
|
||||
**Private bytes vary by about 1.8 MB between runs** — 8.8, 9.7 and 10.6 MB
|
||||
across three consecutive launches of the same binary — because the Direct3D 11
|
||||
driver's own heap does. Any optimisation worth less than roughly a megabyte
|
||||
cannot be distinguished from that noise, which is the honest ceiling on
|
||||
further tuning. Working set is much larger than private bytes because it
|
||||
counts shared driver and system pages that are not this process's to give
|
||||
back.
|
||||
|
||||
What the application itself allocates:
|
||||
|
||||
| Allocation | Size |
|
||||
| --- | --- |
|
||||
| Font atlas (1024x128 RGBA32) | 0.5 MB |
|
||||
| Icon cache | 19 KB over 4 rasters; ~80 KB after the Display tab |
|
||||
| Nuklear command buffer | 4 KB, growing to ~16 KB on the densest page |
|
||||
| Application state | ~30 KB |
|
||||
|
||||
That is under 0.6 MB of a roughly 9 MB process. The atlas is the only item
|
||||
with meaningful room left in it — see the ALPHA8 note in
|
||||
[DEVELOPMENT.md](DEVELOPMENT.md#fonts-and-the-atlas).
|
||||
|
||||
### What startup costs
|
||||
|
||||
Resident set sampled at each step, and the difference each one made:
|
||||
|
||||
| Step | Delta | Running total |
|
||||
| --- | --- | --- |
|
||||
| Before `main` — CRT, loader, the image itself | — | 7.4 MB |
|
||||
| `SDL_Init(SDL_INIT_VIDEO)` | +3.7 MB | 11.1 MB |
|
||||
| Window and renderer | +10.4 MB | 21.5 MB |
|
||||
| Window icon — the first touch of plutosvg | +0.2 MB | 21.7 MB |
|
||||
| Nuklear context | +0.0 MB | 21.8 MB |
|
||||
| Font atlas | +1.5 MB | 23.2 MB |
|
||||
| Stylesheets | +0.4 MB | 23.6 MB |
|
||||
|
||||
The window-and-renderer step is the graphics driver, and most of it is shared
|
||||
pages rather than this process's own: disabling the render backends the app
|
||||
never selects moved private bytes by 0.9 MB while barely moving working set at
|
||||
all.
|
||||
|
||||
### Growth over time
|
||||
|
||||
Memory is flat in use, and is checked that way rather than assumed. Eighty
|
||||
scheme switches followed by six sweeps through all seven tabs:
|
||||
|
||||
```
|
||||
start 11.20 MB private
|
||||
after 20 theme loads 10.44
|
||||
after 40 9.55
|
||||
after 60 9.52
|
||||
after 80 9.52
|
||||
after 6 tab sweeps 9.52
|
||||
```
|
||||
|
||||
This is worth re-running after any change to the style or icon paths. Before
|
||||
the rule store was rebuilt per load, the same test climbed from 7.91 to
|
||||
15.50 MB and had not levelled off.
|
||||
|
||||
## CPU
|
||||
|
||||
| Situation | Cost |
|
||||
| --- | --- |
|
||||
| At rest, any tab | **0.00%** of one core over 8 s |
|
||||
| Pointer sweeping across the Login page | ~2.8% of one core, median |
|
||||
|
||||
At rest the figure is not "low", it is nothing: SDL is told to wait for
|
||||
events, and `SDL_AppIterate` returns immediately unless something has actually
|
||||
changed. A frame is built when a widget changes state or the pointer crosses a
|
||||
region registered as hot in the previous frame.
|
||||
|
||||
Where a frame's time goes, on a typical drawn frame:
|
||||
|
||||
| Phase | Time |
|
||||
| --- | --- |
|
||||
| Build (running the UI code) | 1.3–1.9 ms |
|
||||
| Render (Nuklear commands to geometry) | 0.4–0.9 ms |
|
||||
| Present | 1.0–13 ms |
|
||||
|
||||
Present is the vsync wait and dominates, which is the intended shape. While a
|
||||
mouse button is held, the callback rate is set to the display's refresh rather
|
||||
than uncapped: presenting faster than the display accepts fills the swapchain
|
||||
and then `SDL_RenderPresent` blocks on it — measured at 29 ms a frame against
|
||||
0.11 ms of building, which held a drag at 35 fps.
|
||||
|
||||
Parsing both stylesheets takes 1.5–4.0 ms, and happens at startup and on each
|
||||
scheme change.
|
||||
|
||||
## GPU
|
||||
|
||||
Modest by construction. The application holds one atlas texture plus one
|
||||
texture per rasterised icon, uploads nothing per frame, and submits a few
|
||||
hundred triangles — Nuklear's geometry for the visible widgets. Anti-aliasing
|
||||
is Nuklear's own, done on the CPU during the render phase, and
|
||||
`CURIE_AA=0` turns it off.
|
||||
|
||||
There is no shader, no framebuffer of its own and no compute: everything goes
|
||||
through `SDL_Renderer`, so the graphics API is whichever one SDL picked.
|
||||
|
||||
## System requirements
|
||||
|
||||
**Windows** is the only platform in this table with measured numbers. The rest
|
||||
follow from the build configuration and SDL's own requirements, and are marked
|
||||
as expectations until somebody runs them.
|
||||
|
||||
| Platform | Renderer | Status |
|
||||
| --- | --- | --- |
|
||||
| Windows 10/11, x64 | Direct3D 11, or OpenGL if D3D is unavailable | **Measured.** Everything above. |
|
||||
| macOS | Metal | *Expected.* Builds with CMake; no measurements. |
|
||||
| Linux, x64/ARM | OpenGL or OpenGL ES, X11 or Wayland | *Expected.* Same. |
|
||||
| FreeBSD and the other BSDs | OpenGL, X11 or Wayland | *Expected.* SDL supports them; not built here. |
|
||||
| Browser | WebGL 2 (required — the build sets both the minimum and maximum) | **Measured** for size only; not profiled. |
|
||||
|
||||
**Filling that table in is planned work.** The macOS, Linux and BSD rows stay
|
||||
marked as expectations until somebody builds on each and runs the same
|
||||
measurements the Windows row came from — the Diagnostics tab reports
|
||||
everything needed, so it is a matter of access to the machines, not of
|
||||
tooling. The browser row needs a profiling pass rather than just a size
|
||||
check.
|
||||
|
||||
In every case the requirement is modest: this is a 2.7 MB binary that draws a
|
||||
few hundred triangles and idles at zero. On the desktop it needs about 10 MB
|
||||
of RAM and whatever the platform's own graphics driver takes on top. A machine
|
||||
that can run a browser can run it.
|
||||
|
||||
Two things a deployment does need:
|
||||
|
||||
- **The asset files.** A native build reads tiny.css and the Ionicons SVGs
|
||||
from disk at runtime, resolved relative to the `.curie-root` marker, so
|
||||
those files have to ship beside the binary or `CURIE_ROOT` has to point at
|
||||
them. The web build is the exception: Emscripten packages them into
|
||||
`curie.data`.
|
||||
- **A served web build.** A `file://` page cannot fetch the `.wasm`.
|
||||
+51
-26
@@ -77,27 +77,25 @@ static const int g_font_px[FONT_STEPS] = { 12, 13, 14, 16, 19 };
|
||||
#define TITLE_GAP 6 /* between the app mark and the name */
|
||||
#define MARK_SIZE 18 /* the app mark, drawn size */
|
||||
|
||||
/* The resident set at each step of the startup, so the diagnostics can say
|
||||
* what each piece costs rather than leaving it to be guessed at. Sampled into
|
||||
* a file static because the first two land before App exists. */
|
||||
enum {
|
||||
RSS_ENTRY, RSS_SDL, RSS_WINDOW, RSS_NUKLEAR, RSS_FONT, RSS_STYLE,
|
||||
RSS_STEPS
|
||||
};
|
||||
/* The resident set at each startup milestone (the list is in ui.h, next to
|
||||
* the page that prints it). A file static because the first two samples land
|
||||
* before App exists. */
|
||||
static size_t g_rss[RSS_STEPS];
|
||||
|
||||
/* Ionicons draw a 32-unit stroke on a 512 viewBox - 6.25% of the glyph - so
|
||||
* below 16px the line falls under one pixel and anti-aliases to grey. That,
|
||||
* not the artwork, is why a glyph looked "greyed out": at 12px the minimise
|
||||
* faded, and dropping the maximise to 14px faded that one instead. Every
|
||||
* glyph therefore stays at or above 16, and the remaining differences are
|
||||
* optical - a cross and a dash read smaller than a square of equal size. */
|
||||
* faded, and dropping the maximise to 14px faded that one too - until the
|
||||
* stroke widths in the SVG were scaled up on the way through, which is what
|
||||
* puts the line back over a pixel and lets the maximise sit a size below the
|
||||
* other two. The remaining differences are optical: a cross and a dash read
|
||||
* smaller than a square of equal size. */
|
||||
/* Even sizes, so that (CTL_SIZE - glyph) / 2 is a whole number of pixels.
|
||||
* At 17 the padding was 5.5 and the minimise dash - a single horizontal line
|
||||
* through the middle of the box - straddled a pixel boundary and came out as
|
||||
* one bright row between two dim ones however heavy the stroke was. */
|
||||
#define GLYPH_MINIMISE 18
|
||||
#define GLYPH_MAXIMISE 16
|
||||
#define GLYPH_MAXIMISE 14
|
||||
#define GLYPH_CLOSE 18
|
||||
|
||||
/* Size alone only got them off the grey floor; at this scale the artwork's
|
||||
@@ -515,15 +513,32 @@ image_centred(struct nk_context *ctx, struct nk_image im, int px)
|
||||
/* --- fonts --------------------------------------------------------------- */
|
||||
/* Nuklear's built-in default is ProggyClean, a 13px *bitmap* font: blocky at
|
||||
* any real size and unable to scale. Baking a TTF through stb_truetype is what
|
||||
* makes text look like text - and this is the path the CC0 Zerove font will
|
||||
* use once per-widget font selection is wanted for display type; only
|
||||
* FONT_FILE changes. Zerove is unicase (measured: 'a' and 'A' are the same
|
||||
* outline at 1434 units), so it is a wordmark face, not a UI face. */
|
||||
#define FONT_FILE "third_party/nuklear/extra_font/Karla-Regular.ttf"
|
||||
* makes text look like text.
|
||||
*
|
||||
* The face is Aileron, CC0, vendored under assets/fonts/. It replaced Karla,
|
||||
* which ships inside the Nuklear submodule with no licence anywhere near it:
|
||||
* a dependency whose terms can only be read off somewhere else is not one to
|
||||
* build a distributable on. Aileron's download has no licence file either, so
|
||||
* Aileron-Notice.txt records where its terms come from - the declaration is in
|
||||
* the font's own name table, which is better provenance than a file would be.
|
||||
* Vendoring rather than submoduling is the one exception to this project's
|
||||
* submodule rule.
|
||||
*
|
||||
* It is an OTF: stb_truetype, which Nuklear bakes through, reads CFF outlines
|
||||
* as well as TrueType ones.
|
||||
*
|
||||
* assets/fonts/ also holds two faces that are not loaded - Public Sans (OFL),
|
||||
* which was the runner-up, and Zerove (CC0), which is unicase (measured: 'a'
|
||||
* and 'A' are the same outline at 1434 units) and so a wordmark face rather
|
||||
* than a UI one. Only FONT_FILE would change. See docs/NOTICE.md. */
|
||||
#define FONT_FILE "assets/fonts/Aileron-Regular.otf"
|
||||
|
||||
/* Nearest baked size. `bold` is accepted and ignored: Karla ships regular
|
||||
* only, and synthesising a bold by double-striking looks worse than not having
|
||||
* one - so font-weight still has no face to select. */
|
||||
/* Nearest baked size. `bold` is accepted and ignored, but no longer for want
|
||||
* of a face: Aileron-Bold.otf sits beside the regular. Baking it would put
|
||||
* a second set of FONT_STEPS faces in the atlas and roughly double the largest
|
||||
* allocation this app makes, which is not a trade to take silently - so
|
||||
* font-weight still has no face to select, and the file is there for the day
|
||||
* that changes. */
|
||||
static const struct nk_user_font *
|
||||
pick_font(App *app, int px, int bold)
|
||||
{
|
||||
@@ -587,7 +602,7 @@ rebuild_font(App *app)
|
||||
font = nk_font_atlas_add_default(atlas, (float)curie_px(FONT_SIZE), NULL);
|
||||
} else {
|
||||
SDL_snprintf(app->font_status, sizeof(app->font_status),
|
||||
"Karla, %d sizes %d-%dpx", FONT_STEPS,
|
||||
"Aileron, %d sizes %d-%dpx", FONT_STEPS,
|
||||
curie_px(g_font_px[0]), curie_px(g_font_px[FONT_STEPS - 1]));
|
||||
}
|
||||
|
||||
@@ -1841,14 +1856,21 @@ apply_widget_style(App *app)
|
||||
curie_style_get("summary", &sum);
|
||||
st->tab.background = nk_style_item_color(
|
||||
det.matched ? curie_visible(col_of(det.bg), body, base) : base);
|
||||
st->tab.border_color = det.matched ? col_of(det.border_col) : edge;
|
||||
/* Nuklear fills a tab header twice: the border rect at a literal 0
|
||||
* rounding, then the background inset by tab.border at tab.rounding. The
|
||||
* first is square whatever the style asks for, so with any other colour
|
||||
* its corners show through and the header reads as a square box however
|
||||
* round the fill is. Painting it in the surface behind the header, and
|
||||
* taking the border to nothing, leaves the rounded fill on its own -
|
||||
* details' own 1px border is not worth a set of square corners. */
|
||||
st->tab.border_color = body;
|
||||
/* The main text colour for both kinds of tree row. `summary` resolves to
|
||||
* something dimmer, and it only reaches the plain nodes - the element
|
||||
* rows draw their label through nk_style_selectable - so honouring it
|
||||
* made one row in the tree a different colour from its siblings. */
|
||||
st->tab.text = text;
|
||||
st->tab.border = 0.0f;
|
||||
if (det.matched) {
|
||||
st->tab.border = det.border;
|
||||
st->tab.rounding = det.rounding;
|
||||
st->tab.padding = nk_vec2(det.pad_x, det.pad_y);
|
||||
}
|
||||
@@ -1937,7 +1959,7 @@ apply_widget_style(App *app)
|
||||
static void
|
||||
tab_strip(App *app, struct nk_context *ctx, int win_w)
|
||||
{
|
||||
const struct nk_user_font *font = pick_font(app, 14, 0);
|
||||
const struct nk_user_font *font = pick_font(app, 16, 0);
|
||||
unsigned char c[4];
|
||||
struct nk_color accent = curie_style_token("--links", c)
|
||||
? col_of(c) : app->text;
|
||||
@@ -2394,7 +2416,6 @@ curie_diagnostics(App *app, curie_diag *out)
|
||||
out->tab = app->tab;
|
||||
out->scale = curie_scale();
|
||||
out->style_ms = app->style_ms_x100 / 100.0f;
|
||||
out->fps = app->fps;
|
||||
out->frame_gap_ms = app->frame_gap_ms;
|
||||
|
||||
/* Nuklear grows this to fit the busiest frame it has been asked to draw
|
||||
@@ -2603,10 +2624,14 @@ SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
if (app->borderless) SDL_SetWindowHitTest(app->win, window_hit_test, app);
|
||||
/* Either way it can be changed from the card at runtime. */
|
||||
|
||||
g_rss[RSS_WINDOW] = curie_process_rss();
|
||||
|
||||
/* Its own milestone: this is the first thing to touch plutosvg, and
|
||||
* folding that into the renderer's figure was exactly the sort of
|
||||
* misattribution the table exists to prevent. */
|
||||
set_window_icon(app->win);
|
||||
curie_set_scale(curie_dpi_query_scale(app->win)); /* needs the window */
|
||||
|
||||
g_rss[RSS_WINDOW] = curie_process_rss();
|
||||
g_rss[RSS_ICON] = curie_process_rss();
|
||||
|
||||
app->ctx = nk_sdl_init(app->win, app->ren, nk_sdl_allocator());
|
||||
if (!app->ctx) return SDL_APP_FAILURE;
|
||||
|
||||
+93
-39
@@ -29,6 +29,11 @@
|
||||
#define ROW_TALL 34.0f /* one control with a label inside it */
|
||||
#define ROW_SMALL 22.0f
|
||||
|
||||
const char *const curie_rss_names[RSS_STEPS] = {
|
||||
"before any of it", "SDL_Init(VIDEO)", "window and renderer",
|
||||
"window icon", "Nuklear context", "font atlas", "stylesheets"
|
||||
};
|
||||
|
||||
const char *const curie_tab_names[TAB_COUNT] = {
|
||||
"Login", "Buttons", "Inputs", "Display", "Layout", "Popups", "Diagnostics"
|
||||
};
|
||||
@@ -59,7 +64,7 @@ heading(App *app, struct nk_context *ctx, const char *text)
|
||||
static void
|
||||
caption(App *app, struct nk_context *ctx, const char *text)
|
||||
{
|
||||
const struct nk_user_font *f = curie_font(app, 13, 0);
|
||||
const struct nk_user_font *f = curie_font(app, 16, 0);
|
||||
struct nk_color c = curie_token("--text-muted", ctx->style.text.color);
|
||||
float avail = content_w(ctx) - 4.0f;
|
||||
float tw = f->width(f->userdata, f->height, text, (int)strlen(text));
|
||||
@@ -114,8 +119,9 @@ compact_pop(struct nk_context *ctx)
|
||||
nk_style_pop_vec2(ctx);
|
||||
}
|
||||
|
||||
/* A caption-sized line that names the call being demonstrated, so the page
|
||||
* reads as documentation rather than as decoration. */
|
||||
/* A small line naming the call being demonstrated, so the page reads as
|
||||
* documentation rather than as decoration. Deliberately below the caption:
|
||||
* it is a reference, not part of the prose. */
|
||||
static void
|
||||
api(App *app, struct nk_context *ctx, const char *text)
|
||||
{
|
||||
@@ -352,6 +358,66 @@ hot(App *app, struct nk_context *ctx, int cursor)
|
||||
curie_hot(app, nk_widget_bounds(ctx), cursor, 1);
|
||||
}
|
||||
|
||||
/* Checkboxes and radios sit the way the Edit menu sits them: label at the
|
||||
* left of its cell, box at the right. nk_checkbox_label_align puts the box
|
||||
* flush against the edge of the widget it is given, with no padding of its
|
||||
* own, so the clear space between one cell and the next label has to come
|
||||
* from the row - hence a static gap column after every cell, which the three
|
||||
* cell helpers below fill so no call site has to remember it. */
|
||||
#define CHECK_CELL 190.0f
|
||||
#define CHECK_GAP 12.0f
|
||||
#define CHECK_ALIGN NK_WIDGET_RIGHT, NK_TEXT_LEFT
|
||||
|
||||
static void
|
||||
check_row(struct nk_context *ctx, int cells)
|
||||
{
|
||||
int i;
|
||||
|
||||
nk_layout_row_template_begin(ctx, ROW);
|
||||
for (i = 0; i < cells; i++) {
|
||||
nk_layout_row_template_push_static(ctx, CHECK_CELL);
|
||||
nk_layout_row_template_push_static(ctx, CHECK_GAP);
|
||||
}
|
||||
/* Soaks up the rest of the width so the cells stay the size they were
|
||||
* asked for rather than sharing the window between them. */
|
||||
nk_layout_row_template_push_dynamic(ctx);
|
||||
nk_layout_row_template_end(ctx);
|
||||
}
|
||||
|
||||
static void
|
||||
check_cell(App *app, struct nk_context *ctx, const char *label, nk_bool *on)
|
||||
{
|
||||
hot(app, ctx, 1);
|
||||
nk_checkbox_label_align(ctx, label, on, CHECK_ALIGN);
|
||||
nk_spacer(ctx);
|
||||
}
|
||||
|
||||
/* Nuklear has nk_checkbox_flags_label but no aligned form of it, so this is
|
||||
* that wrapper's own few lines with the aligned call in the middle. */
|
||||
static void
|
||||
flags_cell(App *app, struct nk_context *ctx, const char *label,
|
||||
unsigned *flags, unsigned value)
|
||||
{
|
||||
nk_bool on = (*flags & value) != 0;
|
||||
|
||||
hot(app, ctx, 1);
|
||||
if (nk_checkbox_label_align(ctx, label, &on, CHECK_ALIGN)) {
|
||||
if (on) *flags |= value;
|
||||
else *flags &= ~value;
|
||||
}
|
||||
nk_spacer(ctx);
|
||||
}
|
||||
|
||||
static void
|
||||
radio_cell(App *app, struct nk_context *ctx, const char *label, int *sel,
|
||||
int value)
|
||||
{
|
||||
hot(app, ctx, 1);
|
||||
if (nk_option_label_align(ctx, label, *sel == value, CHECK_ALIGN))
|
||||
*sel = value;
|
||||
nk_spacer(ctx);
|
||||
}
|
||||
|
||||
/* A button that exists only to be looked at. Same as nk_button_label, plus
|
||||
* the hover registration every interactive widget owes the shell now that the
|
||||
* page-wide backstop no longer forces a frame. */
|
||||
@@ -527,27 +593,22 @@ page_buttons(App *app, struct nk_context *ctx, showcase_state *s)
|
||||
"options is held in a single value. Radios are a group only "
|
||||
"because the code makes them one: nk_option_label takes the "
|
||||
"answer to \"am I the active one\" and returns whether it was "
|
||||
"clicked.");
|
||||
api(app, ctx, "nk_checkbox_label / nk_checkbox_flags_label / "
|
||||
"nk_option_label");
|
||||
"clicked. Both sit their box at the right of the cell, the way "
|
||||
"the Edit menu does; the flags form has no aligned variant, so "
|
||||
"this page wraps the aligned call in its own four lines.");
|
||||
api(app, ctx, "nk_checkbox_label_align / nk_option_label_align");
|
||||
|
||||
/* A static grid, not dynamic columns: two dynamic columns put the
|
||||
* second checkbox at the halfway mark of a 960px window, which reads as
|
||||
* two unrelated controls rather than a pair. */
|
||||
nk_layout_row_static(ctx, ROW, 190, 3);
|
||||
hot(app, ctx, 1);
|
||||
nk_checkbox_label(ctx, "Wrap long lines", &s->check_wrap);
|
||||
hot(app, ctx, 1);
|
||||
nk_checkbox_label(ctx, "Check spelling", &s->check_spell);
|
||||
nk_spacer(ctx);
|
||||
/* A fixed grid, not dynamic columns: two dynamic columns put the second
|
||||
* checkbox at the halfway mark of a 960px window, which reads as two
|
||||
* unrelated controls rather than a pair. */
|
||||
check_row(ctx, 2);
|
||||
check_cell(app, ctx, "Wrap long lines", &s->check_wrap);
|
||||
check_cell(app, ctx, "Check spelling", &s->check_spell);
|
||||
|
||||
nk_layout_row_static(ctx, ROW, 190, 3);
|
||||
hot(app, ctx, 1);
|
||||
nk_checkbox_flags_label(ctx, "read", &s->flags, 1u);
|
||||
hot(app, ctx, 1);
|
||||
nk_checkbox_flags_label(ctx, "write", &s->flags, 2u);
|
||||
hot(app, ctx, 1);
|
||||
nk_checkbox_flags_label(ctx, "execute", &s->flags, 4u);
|
||||
check_row(ctx, 3);
|
||||
flags_cell(app, ctx, "read", &s->flags, 1u);
|
||||
flags_cell(app, ctx, "write", &s->flags, 2u);
|
||||
flags_cell(app, ctx, "execute", &s->flags, 4u);
|
||||
|
||||
nk_layout_row_dynamic(ctx, ROW_SMALL, 1);
|
||||
SDL_snprintf(line, sizeof(line), "flags = 0x%02x", s->flags);
|
||||
@@ -556,11 +617,10 @@ page_buttons(App *app, struct nk_context *ctx, showcase_state *s)
|
||||
curie_token("--text-muted", ctx->style.text.color));
|
||||
nk_style_pop_font(ctx);
|
||||
|
||||
nk_layout_row_static(ctx, ROW, 190, 3);
|
||||
check_row(ctx, 3);
|
||||
for (i = 0; i < 3; i++) {
|
||||
static const char *const names[3] = { "Never", "On Wi-Fi", "Always" };
|
||||
hot(app, ctx, 1);
|
||||
if (nk_option_label(ctx, names[i], s->radio == i)) s->radio = i;
|
||||
radio_cell(app, ctx, names[i], &s->radio, i);
|
||||
}
|
||||
|
||||
section(app, ctx, "Selectables",
|
||||
@@ -867,7 +927,7 @@ section_grid(App *app, struct nk_context *ctx)
|
||||
{ "tiny.css", "MIT", "the stylesheet itself" },
|
||||
{ "plutosvg", "MIT", "rasterises the icons" },
|
||||
{ "Ionicons", "MIT", "the icons" },
|
||||
{ "Karla", "OFL", "the typeface" }
|
||||
{ "Aileron", "CC0", "the typeface" }
|
||||
};
|
||||
static const float weights[3] = { 0.24f, 0.16f, 0.60f };
|
||||
|
||||
@@ -1534,9 +1594,6 @@ page_diagnostics(App *app, struct nk_context *ctx, showcase_state *st)
|
||||
|
||||
diag_row(app, ctx, "at rest", d.frame_rate);
|
||||
diag_row(app, ctx, "while dragging", d.drag_rate);
|
||||
/* From the gap to the previous frame, not from a count over a second:
|
||||
* that second only advances when a frame is drawn, so it reads stale for
|
||||
* as long as the app is quiet - which here is most of the time. */
|
||||
/* Milliseconds are the natural unit for a frame, but a quiet app can sit
|
||||
* for minutes: past a second the number stops reading as a duration. */
|
||||
if (d.frame_gap_ms >= 1000.0f)
|
||||
@@ -1602,19 +1659,16 @@ page_diagnostics(App *app, struct nk_context *ctx, showcase_state *st)
|
||||
"driver and the loader wanted before main ran.");
|
||||
|
||||
{
|
||||
static const char *const step[5] = {
|
||||
"SDL_Init(VIDEO)", "window and renderer", "Nuklear context",
|
||||
"font atlas", "stylesheets"
|
||||
};
|
||||
int i;
|
||||
|
||||
SDL_snprintf(v, sizeof(v), "%.1f MB", d.rss_at[0] / 1048576.0);
|
||||
diag_row(app, ctx, "before any of it", v);
|
||||
for (i = 0; i < 5; i++) {
|
||||
double delta = (d.rss_at[i + 1] - (double)d.rss_at[i]) / 1048576.0;
|
||||
SDL_snprintf(v, sizeof(v), "%.1f MB",
|
||||
d.rss_at[RSS_ENTRY] / 1048576.0);
|
||||
diag_row(app, ctx, curie_rss_names[RSS_ENTRY], v);
|
||||
for (i = RSS_ENTRY + 1; i < RSS_STEPS; i++) {
|
||||
double delta = (d.rss_at[i] - (double)d.rss_at[i - 1]) / 1048576.0;
|
||||
SDL_snprintf(v, sizeof(v), "%+.1f MB (%.1f MB total)", delta,
|
||||
d.rss_at[i + 1] / 1048576.0);
|
||||
diag_row(app, ctx, step[i], v);
|
||||
d.rss_at[i] / 1048576.0);
|
||||
diag_row(app, ctx, curie_rss_names[i], v);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,22 @@ enum {
|
||||
};
|
||||
extern const char *const curie_tab_names[TAB_COUNT];
|
||||
|
||||
/* Startup milestones, sampled into curie_diag::rss_at so the diagnostics page
|
||||
* can report what each step of the startup cost. They live here rather than
|
||||
* in the shell because the page indexes the same list: adding a milestone is
|
||||
* one edit, and the array below sizes itself from it. */
|
||||
enum {
|
||||
RSS_ENTRY, /* before SDL_Init - the CRT, the loader, the image */
|
||||
RSS_SDL,
|
||||
RSS_WINDOW,
|
||||
RSS_ICON,
|
||||
RSS_NUKLEAR,
|
||||
RSS_FONT,
|
||||
RSS_STYLE,
|
||||
RSS_STEPS
|
||||
};
|
||||
extern const char *const curie_rss_names[RSS_STEPS];
|
||||
|
||||
#define SC_TEXT_CAP 64
|
||||
#define SC_BOX_CAP 512
|
||||
#define SC_SERIES_N 32
|
||||
@@ -138,7 +154,7 @@ typedef struct curie_diag {
|
||||
const char *drag_rate; /* and while a button is held */
|
||||
const char *font;
|
||||
int vsync, aa, dark, sheets, tab;
|
||||
float scale, style_ms, fps, build_ms, render_ms, present_ms;
|
||||
float scale, style_ms, build_ms, render_ms, present_ms;
|
||||
float frame_gap_ms; /* since the previous drawn frame */
|
||||
/* Where the memory is. nk_bytes is Nuklear's own command buffer, which
|
||||
* grows to fit the busiest frame drawn so far and is never given back;
|
||||
@@ -146,10 +162,7 @@ typedef struct curie_diag {
|
||||
unsigned long nk_bytes, nk_used, icon_bytes, rss_bytes;
|
||||
int icons;
|
||||
int atlas_w, atlas_h; /* the baked font atlas, RGBA32 */
|
||||
/* Resident set at each startup milestone: on entry, after SDL_Init,
|
||||
* after the window and renderer, after nk_sdl_init, after the font bake,
|
||||
* after the stylesheets. */
|
||||
unsigned long rss_at[6];
|
||||
unsigned long rss_at[RSS_STEPS]; /* one per milestone above */
|
||||
} curie_diag;
|
||||
|
||||
void curie_diagnostics(App *app, curie_diag *out);
|
||||
|
||||
Reference in New Issue
Block a user