From de18b28bfe04078b83e7d28ad6247097fda85249 Mon Sep 17 00:00:00 2001 From: Thomas Nemer Date: Tue, 11 Nov 2025 11:35:14 +0100 Subject: [PATCH] Add advanced examples and API reference documentation This commit implements issue #16 by adding: **Intermediate Examples (examples/intermediate/):** - 01_nested_panels: Complex nested layout composition with FlexLayout, GridLayout, and StackLayout - 02_responsive_ui: Window resize behavior with ResizeBehavior, AxisResizeBehavior, and ResponsiveConstraints - 03_event_handling: Advanced event patterns with custom event handling and focus management - 04_dynamic_layout: Runtime UI changes with dynamic component addition/removal and layout switching **Advanced Examples (examples/advanced/):** - 01_custom_component: ColorPicker custom component demonstrating CRTP pattern, custom render/event handling, and builder pattern - 02_custom_layout: CircularLayout implementation showing custom layout manager creation with CRTP - 03_custom_renderer: IRenderer interface demonstration showing frame lifecycle and rendering concepts - 04_performance: Performance optimization techniques with 100-component GridLayout and FPS counter **API Reference Documentation (docs/api/):** - README.md: Navigation hub for all API documentation - QUICK_REFERENCE.md: Condensed one-page reference for quick lookup - core/Component.md: Detailed Component class API documentation All examples compile successfully and include: - Complete CMakeLists.txt for each example - Comprehensive README.md explaining concepts and usage - Well-commented, educational source code - Progressive complexity from intermediate to advanced topics Resolves #16 --- docs/api/QUICK_REFERENCE.md | 511 ++++++++++++++++++ docs/api/README.md | 212 ++++++++ docs/api/core/Component.md | 256 +++++++++ examples/CMakeLists.txt | 20 + .../01_custom_component/CMakeLists.txt | 33 ++ .../advanced/01_custom_component/README.md | 57 ++ .../advanced/01_custom_component/main.cpp | 285 ++++++++++ .../advanced/02_custom_layout/CMakeLists.txt | 24 + examples/advanced/02_custom_layout/README.md | 27 + examples/advanced/02_custom_layout/main.cpp | 141 +++++ .../03_custom_renderer/CMakeLists.txt | 24 + .../advanced/03_custom_renderer/README.md | 32 ++ examples/advanced/03_custom_renderer/main.cpp | 109 ++++ .../advanced/04_performance/CMakeLists.txt | 24 + examples/advanced/04_performance/README.md | 42 ++ examples/advanced/04_performance/main.cpp | 122 +++++ .../01_nested_panels/CMakeLists.txt | 33 ++ .../intermediate/01_nested_panels/README.md | 124 +++++ .../intermediate/01_nested_panels/main.cpp | 213 ++++++++ .../02_responsive_ui/CMakeLists.txt | 33 ++ .../intermediate/02_responsive_ui/README.md | 205 +++++++ .../intermediate/02_responsive_ui/main.cpp | 231 ++++++++ .../03_event_handling/CMakeLists.txt | 33 ++ .../intermediate/03_event_handling/README.md | 299 ++++++++++ .../intermediate/03_event_handling/main.cpp | 299 ++++++++++ .../04_dynamic_layout/CMakeLists.txt | 33 ++ .../intermediate/04_dynamic_layout/README.md | 272 ++++++++++ .../intermediate/04_dynamic_layout/main.cpp | 322 +++++++++++ 28 files changed, 4016 insertions(+) create mode 100644 docs/api/QUICK_REFERENCE.md create mode 100644 docs/api/README.md create mode 100644 docs/api/core/Component.md create mode 100644 examples/advanced/01_custom_component/CMakeLists.txt create mode 100644 examples/advanced/01_custom_component/README.md create mode 100644 examples/advanced/01_custom_component/main.cpp create mode 100644 examples/advanced/02_custom_layout/CMakeLists.txt create mode 100644 examples/advanced/02_custom_layout/README.md create mode 100644 examples/advanced/02_custom_layout/main.cpp create mode 100644 examples/advanced/03_custom_renderer/CMakeLists.txt create mode 100644 examples/advanced/03_custom_renderer/README.md create mode 100644 examples/advanced/03_custom_renderer/main.cpp create mode 100644 examples/advanced/04_performance/CMakeLists.txt create mode 100644 examples/advanced/04_performance/README.md create mode 100644 examples/advanced/04_performance/main.cpp create mode 100644 examples/intermediate/01_nested_panels/CMakeLists.txt create mode 100644 examples/intermediate/01_nested_panels/README.md create mode 100644 examples/intermediate/01_nested_panels/main.cpp create mode 100644 examples/intermediate/02_responsive_ui/CMakeLists.txt create mode 100644 examples/intermediate/02_responsive_ui/README.md create mode 100644 examples/intermediate/02_responsive_ui/main.cpp create mode 100644 examples/intermediate/03_event_handling/CMakeLists.txt create mode 100644 examples/intermediate/03_event_handling/README.md create mode 100644 examples/intermediate/03_event_handling/main.cpp create mode 100644 examples/intermediate/04_dynamic_layout/CMakeLists.txt create mode 100644 examples/intermediate/04_dynamic_layout/README.md create mode 100644 examples/intermediate/04_dynamic_layout/main.cpp diff --git a/docs/api/QUICK_REFERENCE.md b/docs/api/QUICK_REFERENCE.md new file mode 100644 index 0000000..e616556 --- /dev/null +++ b/docs/api/QUICK_REFERENCE.md @@ -0,0 +1,511 @@ +# Prong API Quick Reference + +Condensed reference for all Prong APIs. See individual files for detailed documentation. + +## Core Classes + +### Component +Base class for all UI elements. +```cpp +class Component { + virtual void update(double deltaTime) = 0; + virtual void render() = 0; + void setPosition(int x, int y); + void setSize(int width, int height); + void addChild(std::unique_ptr child); + bool handleEvent(const Event& event); + void setResizeBehavior(ResizeBehavior behavior); +}; +``` + +### Scene +Root container and event coordinator. +```cpp +class Scene : public Component { + Scene(IWindow* window, IRenderer* renderer); + void attach(); // Start receiving events + void detach(); // Stop receiving events + void handleResize(int newWidth, int newHeight); +}; +``` + +### ComponentBuilder +Fluent API for component construction. +```cpp +auto component = create(/* constructor args */) + .withSize(width, height) + .withPosition(x, y) + .withVisible(bool) + .build(); +``` + +### Event +Unified event structure. +```cpp +struct Event { + enum class Type { MOUSE_PRESS, MOUSE_RELEASE, MOUSE_MOVE, MOUSE_SCROLL, KEY_PRESS, KEY_RELEASE, CHAR_INPUT }; + Type type; + int localX, localY; // Mouse position in local coordinates + int button; // Mouse button + int key, mods; // Keyboard + unsigned int codepoint; // Character input + double scrollX, scrollY; // Scroll delta +}; +``` + +## UI Components + +### Button +```cpp +auto button = create