Inital context stuff and tests

Linking and  building is successfull and inital tests pass
This commit is contained in:
chrisbell committed 2026-11-02 14:16:16 -06:00
1 parent 2296f68123
commit 363e9894e8
10 files changed
+410 -59

No files matched your search

+57 -28
View File
@@ -72,9 +72,20 @@ color emoji are out of scope for the first versions.
## Rendering
Rectangles, borders, and glyphs all reduce to quads. A backend only needs to
manage textures, draw quad batches, and apply a scissor rect. Rendering
backends are replaceable, and the SDL3 and OpenGL backend is the default.
The core never calls a backend. Each frame `rg_render` returns a draw list
made of texture operations (create, update region, destroy) followed by
batches of colored and textured quads with scissor rects. A backend is any
code that consumes that list. The SDL3 and OpenGL backend is the default, and
the null backend records the list for headless tests. A WASM host can consume
the list from JavaScript. The shipped backends share a small convenience
interface, and the core does not depend on it.
## Viewport and scale
All API coordinates are logical pixels. The host calls
`rg_set_viewport(ctx, w, h, scale)` when the window resizes or the display
scale changes. A scale change invalidates the glyph atlas and glyphs are
rasterized again at the new size.
## Documents
@@ -144,27 +155,6 @@ across the FFI boundary.
never by raw pointers.
- The user can supply an allocator, and internal allocation uses arenas.
## Build and environment
The build system is CMake with Ninja. Development happens on NixOS using
direnv and flakes, and the devShell provides CMake, Ninja, pkg-config, clang,
clang-tools, SDL3, Emscripten, and lua-language-server. Emscripten's cache
directory is set to `.emscripten-cache` inside the project. WASM builds go
through `emcmake` into `build-wasm/`. Sources live in a flat `src/` with no
generated files, so Zig and Odin users can compile them with their own
toolchain.
## Milestone 1
A `main.lua` builds a `VBox` of `Label` and `Button` nodes. A stylesheet with
classes and a `:hover` state styles them. Layout runs through Clay and draws
through the SDL3 and OpenGL backend with stb_truetype text. A button click
fires both a Lua handler and a named event in the polled queue. One
transition eases a button background on hover. A data-bound label shows a
counter that the button increments.
Text inputs and scrolling follow in milestone 2, along with focus handling.
## Context and ownership
All state lives in an `rg_context`, which is created with `rg_create` and
@@ -194,8 +184,47 @@ Gamepad navigation will be added as a semantic layer (up, down, left, right,
accept, cancel) that drives focus movement, so a game can map any device to
it.
## Open questions
## Errors and logging
- Whether texture uploads travel inside the draw list.
- Viewport and display scale handling.
- Error reporting and logging.
Functions that can fail return an `int` status where zero is success and
negative values are errors. `rg_last_error(ctx)` returns the message for the
most recent failure on that context. The config carries a log callback, a log
level, and a userdata pointer. The default callback writes to stderr and the
default level is trace, so logging is verbose until I lower it. Lua errors
such as syntax errors and handler failures are logged and never replace the
live tree, so a broken save during hot reload leaves the last good tree on
screen.
## Testing
`ctest` runs the smoke tests. The core smoke test installs a counting
allocator and fails if any bytes are live after `rg_destroy`. Every
allocation, including Lua's, goes through the context allocator.
### Build and environment
The build system is CMake with Ninja. Development happens on NixOS using
direnv and flakes, and the devShell provides CMake, Ninja, pkg-config, clang,
clang-tools, SDL3, Emscripten, and lua-language-server. Emscripten's cache
directory is set to `.emscripten-cache` inside the project. WASM builds go
through `emcmake` into `build-wasm/`. Sources live in a flat `src/` with no
generated files, so Zig and Odin users can compile them with their own
toolchain.
### Milestone 1
A `main.lua` builds a `VBox` of `Label` and `Button` nodes. A stylesheet with
classes and a `:hover` state styles them. Layout runs through Clay and draws
through the SDL3 and OpenGL backend with stb_truetype text. A button click
fires both a Lua handler and a named event in the polled queue. One
transition eases a button background on hover. A data-bound label shows a
counter that the button increments.
Text inputs and scrolling follow in milestone 2, along with focus handling.
### Open questions
- Node handle format.
- Property system: how properties are named, typed, and stored.