Learn: a second client tests a different thing than a second window
A second app with independent state is a consumer test of the library. If it must patch the first app or take over the native loop, the earlier demo did not prove a reusable framework. Keep both apps buildable at the same revision.
Run it: link two unrelated clients to the same target
The two-consumer sample declares a tiny scale library. Only the library implements its operation; the first and second files are consumers.
cmake_minimum_required(VERSION 4.0)
project(two_consumers LANGUAGES CXX)
add_library(scale scale.cpp)
target_include_directories(scale PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
target_compile_features(scale PUBLIC cxx_std_20)
add_executable(first first.cpp)
add_executable(second second.cpp)
target_link_libraries(first PRIVATE scale)
target_link_libraries(second PRIVATE scale)
cmake -S course/examples/two-consumers -B build/examples/two-consumers -G "Unix Makefiles"
cmake --build build/examples/two-consumers
./build/examples/two-consumers/first
./build/examples/two-consumers/second
Expect 14 and 24. Try it: change only the second input in a scratch copy; the library and first client should require no source edit.
Build it: ship a toggle alongside the counter
Your challenge: Add a toggle executable with an independent on/off model, one named control, and a label. Use the same library and action, focus, layout, and paint interfaces. Do not alter the library for an app-specific reason.
Let it start Off, switch to On after one click or keyboard activation, and switch back after the next. Distinguish no shared application state from shared framework code. Add a brief README with supported setup, build/run commands for both apps, API usage and ownership, the verification commands, and current scope limits. If this second consumer reveals a genuine abstraction gap, document the required public API change, update both consumers, and rerun both; the final proof runs against a single stable revision.
Check it
Build both targets from a clean tree. Verify the toggle trace Off → On → Off, independent of the counter. Confirm the two app files include only public UI headers and don’t handle native window IDs, loop events, font handles, or pixel buffers. Repeat focus, redraw, resize, and close smoke checks. Make sure both app targets link the very same library, not a copied implementation for the second.
python3 course/check_core.py reuse-api --previous
Use the verification guide to report independent native observations, CTest results, and anything blocked. Keep setup and run instructions separate from development notes.
Hints and troubleshooting
Hint: the second program only links after copying a source file
Print your target dependency graph. The implementation belongs to the library target; both executables consume it with target_link_libraries. Look for duplicate entry points and native headers leaking out of the public interface.
Finish line: You can explain the trace from native event to action, model update, layout, clipped paint, and presentation, and can run it in two independent apps. This edition does not implement Wayland, GPU rendering, full CSS layout, IME, complex shaping, accessibility parity, or multiple windows. Those are extensions, not missing steps in this book. When you’re ready, see Future scope for a project, an implementation order, and primary resources for bringing web-like capabilities to the native framework.