بنقرة واحدة
dev-ui-lesson
Add a UI lesson — TTF parsing, font rasterization, immediate-mode UI controls, layout
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Add a UI lesson — TTF parsing, font rasterization, immediate-mode UI controls, layout
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Add PBR texture loading with separate roughness/metallic support to an SDL GPU project using forge_scene.h
Add Cook-Torrance PBR shading with GGX, Schlick-GGX, and Schlick Fresnel to an SDL GPU project alongside forge_scene.h
Add instanced grass rendering with segmented blades, wind animation, LOD density rings, and terrain LOD with geomorphing to an SDL GPU project
Add procedural noise texture generation to the asset pipeline — C tool, Python plugin, web UI with live preview
Add an asset pipeline lesson — hybrid Python + C track for asset processing, procedural geometry, and web frontend
Add an audio lesson — sound playback, mixing, spatial audio, DSP effects, with SDL GPU scenes and forge UI
| name | dev-ui-lesson |
| description | Add a UI lesson — TTF parsing, font rasterization, immediate-mode UI controls, layout |
| argument-hint | [number] [topic-name] [description] |
Create a new UI lesson teaching how to build an immediate-mode UI system from scratch — font parsing, text rasterization, layout, and interactive controls.
UI lessons produce CPU-side data (textures, vertices, indices, UVs) that a separate GPU lesson will later render. The UI library itself contains no GPU code — it is a pure data-generation layer.
When to use this skill:
Smart behavior:
The user (or you) can provide:
If any are missing, infer from context or ask.
common/ui/: Does relevant library code already exist?lessons/ui/NN-topic-name/
main.c)A focused C program that demonstrates the UI concept by producing data and
verifying it. UI lesson programs must write BMP images as their primary
visual output. These images are committed to assets/ and embedded in the
README so readers see results immediately. Programs typically:
Requirements:
#include "math/forge_math.h" for vec2/rect math,
#include "ui/forge_ui.h" for UI types (once the library exists)Template structure:
/*
* UI Lesson NN — Topic Name
*
* Demonstrates: [what this shows]
*
* SPDX-License-Identifier: Zlib
*/
#include <SDL3/SDL.h>
#include "math/forge_math.h"
int main(int argc, char *argv[])
{
(void)argc;
(void)argv;
if (!SDL_Init(0)) {
SDL_Log("SDL_Init failed: %s", SDL_GetError());
return 1;
}
/* Demonstrate the UI concept here */
SDL_Quit();
return 0;
}
Console output formatting:
-, =, *, |, ->, [OK], [!], "px", "glyph", "atlas"─, ═, •, ↓, →, ✓, ⚠ (may render as garbled text on
Windows)CMakeLists.txtadd_executable(NN-topic-name main.c)
target_include_directories(NN-topic-name PRIVATE ${FORGE_COMMON_DIR})
target_link_libraries(NN-topic-name PRIVATE SDL3::SDL3)
if(TARGET SDL3::SDL3-shared)
add_custom_command(TARGET NN-topic-name POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:SDL3::SDL3-shared>
$<TARGET_FILE_DIR:NN-topic-name>
)
endif()
Adapt as needed: Later lessons may link against a shared UI library
(common/ui/) once it exists.
README.mdStructure:
# UI Lesson NN — Topic Name
[Brief subtitle explaining what this teaches]
## What you'll learn
[Bullet list of UI concepts covered]
## Why this matters
[1-2 paragraphs connecting this topic to real game/tool UI development.
Explain when and why a developer will need this.]
## Result
[Brief description of what the example program produces]
[Embed PNG images generated by the program. The program writes BMP files
(no libpng dependency needed in C), so convert them to PNG before committing.
Copy the PNGs to the lesson's `assets/` directory and reference them with
``. Use tables to show multiple images side by
side:]
| Glyph 1 | Glyph 2 | Glyph 3 |
|---------|---------|---------|
|  |  |  |
**Important:** Build and run the program first to generate the BMP files,
then convert to PNG (`python3 -c "from PIL import Image; Image.open('file.bmp').save('file.png')"`)
and copy them to `assets/`. Never commit BMP files — they are uncompressed
and bloat the repository.
## Key concepts
[Bullet list of core takeaways:]
- **Concept 1** — Brief explanation
- **Concept 2** — Brief explanation
## The Details
[Main explanation of the topic, broken into subsections]
### [Subtopic 1]
[Explanation with code examples and diagrams where appropriate]
### [Subtopic 2]
[Explanation with code examples and diagrams where appropriate]
## Data output
[Describe the data structures this lesson produces — vertex layouts, texture
formats, index buffers. This section bridges UI lessons to the GPU lesson
that will render the data.]
- **Vertices**: [format — position, UV, color]
- **Indices**: [format — triangle list, winding order]
- **Textures**: [format — RGBA, single-channel alpha, atlas dimensions]
## Where it's used
In forge-gpu lessons:
- [Link to GPU lesson] renders this data with [technique]
- [Link to math lesson] provides [math concept] used here
- [Link to engine lesson] explains [engineering concept] used here
## Building
```bash
cmake -B build
cmake --build build --config Debug
# Windows
build\lessons\ui\NN-topic-name\Debug\NN-topic-name.exe
# Linux / macOS
./build/lessons/ui/NN-topic-name/NN-topic-name
```
## Exercises
1. [Exercise extending the concept]
2. [Exercise applying it differently]
3. [Exercise that produces different output data for the GPU to render]
## Further reading
- [Relevant UI/math/engine lesson that builds on this]
- [External resource — TTF spec, stb_truetype, Dear ImGui, etc.]
CMakeLists.txt (root): Add add_subdirectory(lessons/ui/NN-topic-name)
under a "UI Lessons" section (create the section if it doesn't exist yet)PLAN.md: Check off or add the UI lesson entryEvery new UI lesson must update all four of these files:
README.md (root): Add a row to the UI lessons table in the
"UI Lessons (lessons/ui/)" section — follow the same format as the
existing rowslessons/ui/README.md: Add a row to the lessons tablecommon/ui/README.md: If the lesson adds new types or functions to the
shared library, add them to the API reference sections. Always add the
lesson to the "Where It's Used" listREADME.md: Update the "What's next" section to
include the new lesson (and verify it matches the current plan order in
PLAN.md)cmake -B build
cmake --build build --config Debug
# Run from repo root so the program finds assets/fonts/
./build/lessons/ui/NN-topic-name/NN-topic-name
# Convert generated BMP files to PNG and copy to assets/
python3 -c "
from PIL import Image
import glob
for bmp in glob.glob('*.bmp'):
Image.open(bmp).save(bmp.replace('.bmp', '.png'), 'PNG', optimize=True)
"
cp *.png lessons/ui/NN-topic-name/assets/
Verify the demo runs and produces BMP files. Convert them to PNG (much
smaller — typically 97% reduction for UI screenshots) and copy to the
lesson's assets/ directory. Never commit BMP files to the repository.
If this lesson introduces reusable types or functions (font metrics, rect
packing, text shaping), add them to common/ui/ following the same
conventions as common/math/:
static inline functions in .h filesforge_ui_ prefix for public API, ForgeUi for typestests/ui/Before finalizing, launch a verification agent using the Task tool
(subagent_type: "general-purpose"). Give the agent the paths to the lesson's
README.md and main.c and ask it to audit every key topic for completeness.
For each key topic / "What you'll learn" bullet, the agent must check:
main.c actually exercise
this concept with code and output?What to flag:
The lesson is incomplete until every key topic passes all three checks.
Use the /dev-markdown-lint skill to check all markdown files:
npx markdownlint-cli2 "**/*.md"
If errors are found:
npx markdownlint-cli2 --fix "**/*.md"npx markdownlint-cli2 "**/*.md"Task agents have a 32K output token limit per Write call. Any file over ~800
lines MUST be written in chunks — split into 3-4 parts (~400-600 lines each),
write each to /tmp/, then concatenate.
Recovery rule — if a writing agent fails with a token limit error:
See .claude/large-file-strategy.md
for the full strategy.
If this lesson requires textures or 3D assets for any reason, they MUST go through the asset pipeline. No ad-hoc asset loading.
UI lessons cover building an immediate-mode UI system from the ground up:
UI lessons do not cover:
Every UI lesson should clearly document what data it produces:
This data contract is what connects UI lessons to the GPU lesson that renders them.
UI lessons should be practical and visual. Font parsing and text layout are domains with deep history and real complexity — treat the material with respect while keeping it accessible.
All generated UI code must use ctx->theme color slots for widget rendering.
Never hardcode color float literals (e.g. 0.878f, 0.878f, 0.941f, 1.0f) —
use the appropriate theme field instead (e.g. ctx->theme.text). The
forge_ui_theme_validate() contrast check is run as part of the test suite
and new themes or color changes must pass all contrast pairs.
Follow the same conventions as all forge-gpu code:
ForgeUi prefix for public types, forge_ui_ for public functionsPascalCase for typedefs, lowercase_snake_case for localsUPPER_SNAKE_CASE for #define constants#define or enum everythingFind opportunities to create compelling diagrams and visualizations via the
matplotlib scripts — they increase reader engagement and help learners
understand the topics being taught. Use the /dev-create-diagram skill to add
diagrams following the project's visual identity and quality standards.
For visual diagrams (glyph anatomy, atlas packing, text metrics, layout
boxes, widget trees), add a diagram function to
scripts/forge_diagrams/ui/lesson_NN.py (create the file if it doesn't exist):
setup_axes,
draw_vector, save helpers from _common.py)scripts/forge_diagrams/ui/__init__.pyDIAGRAMS dict in __main__.py with the lesson keypython scripts/forge_diagrams --lesson ui/NN to generate the PNGOutput goes to each lesson's assets/ directory at 200 DPI (PNG only).
For flow/pipeline diagrams (TTF parsing pipeline, UI layout pass, data flow from CPU to GPU), use inline mermaid blocks:
```mermaid
flowchart LR
A[TTF File] -->|parse| B[Glyph Outlines] -->|rasterize| C[Bitmap Atlas]
```
For formulas (Bezier curves, atlas packing ratios, font scaling), use
inline $...$ and display $$...$$ math notation:
$\text{scale} = \frac{\text{pixel height}}{\text{unitsPerEm}}$$$
B(t) = (1-t)^2 P_0 + 2(1-t)t P_1 + t^2 P_2
$$
Scenario: Learners want to understand how fonts work before rendering text.
lessons/ui/01-ttf-parsing/Scenario: A learner has parsed glyphs and wants to pack them into a texture.
lessons/ui/03-font-atlas/In these cases, update existing documentation or plan for later.
assets/, and embed with . Never
commit BMP files — they are uncompressed and bloat the repository.