This commit implements Phase 7 of the UIModule, adding advanced features that make the UI system production-ready. ## Phase 7.1 - UIScrollPanel New scrollable container widget with: - Vertical and horizontal scrolling (configurable) - Mouse wheel support with smooth scrolling - Drag-to-scroll functionality (drag content or scrollbar) - Interactive scrollbar with proportional thumb - Automatic content size calculation - Visibility culling for performance - Full styling support (colors, borders, scrollbar) Files added: - modules/UIModule/Widgets/UIScrollPanel.h - modules/UIModule/Widgets/UIScrollPanel.cpp - modules/UIModule/Core/UIContext.h (added mouseWheelDelta) - modules/UIModule/UIModule.cpp (mouse wheel event routing) ## Phase 7.2 - Tooltips Smart tooltip system with: - Hover delay (500ms default) - Automatic positioning with edge avoidance - Semi-transparent background with border - Per-widget tooltip text via JSON - Tooltip property on all UIWidget types - Renders on top of all UI elements Files added: - modules/UIModule/Core/UITooltip.h - modules/UIModule/Core/UITooltip.cpp - modules/UIModule/Core/UIWidget.h (added tooltip property) - modules/UIModule/Core/UITree.cpp (tooltip parsing) ## Tests Added comprehensive visual tests: - test_28_ui_scroll.cpp - ScrollPanel with 35+ items - test_29_ui_advanced.cpp - Tooltips on various widgets - assets/ui/test_scroll.json - ScrollPanel layout - assets/ui/test_tooltips.json - Tooltips layout ## Documentation - docs/UI_MODULE_PHASE7_COMPLETE.md - Complete Phase 7 docs - docs/PROMPT_UI_MODULE_PHASE6.md - Phase 6 & 7 prompt - Updated CMakeLists.txt for new files and tests ## UIModule Status UIModule is now feature-complete with: ✅ 9 widget types (Panel, Label, Button, Image, Slider, Checkbox, ProgressBar, TextInput, ScrollPanel) ✅ Flexible layout system (vertical, horizontal, stack, absolute) ✅ Theme and style system ✅ Complete event system ✅ Tooltips with smart positioning ✅ Hot-reload support ✅ Comprehensive tests (Phases 1-7) 🚀 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
87 lines
2.1 KiB
C++
87 lines
2.1 KiB
C++
#pragma once
|
|
|
|
#include "UIWidget.h"
|
|
#include <grove/IDataNode.h>
|
|
#include <memory>
|
|
#include <functional>
|
|
#include <unordered_map>
|
|
|
|
namespace grove {
|
|
|
|
class UIPanel;
|
|
class UILabel;
|
|
|
|
/**
|
|
* @brief Factory function type for creating widgets
|
|
*/
|
|
using WidgetFactory = std::function<std::unique_ptr<UIWidget>(const IDataNode&)>;
|
|
|
|
/**
|
|
* @brief Manages the UI widget tree and JSON parsing
|
|
*
|
|
* Parses JSON layout files into a hierarchy of UIWidget objects.
|
|
* Supports widget factory registration for extensibility.
|
|
*/
|
|
class UITree {
|
|
public:
|
|
UITree();
|
|
~UITree() = default;
|
|
|
|
/**
|
|
* @brief Register a widget factory for a type
|
|
* @param type Widget type name (e.g., "panel", "label")
|
|
* @param factory Factory function
|
|
*/
|
|
void registerWidget(const std::string& type, WidgetFactory factory);
|
|
|
|
/**
|
|
* @brief Load UI tree from JSON data
|
|
* @param layoutData JSON layout data
|
|
* @return Root widget or nullptr on error
|
|
*/
|
|
std::unique_ptr<UIWidget> loadFromJson(const IDataNode& layoutData);
|
|
|
|
/**
|
|
* @brief Find widget by ID in the tree
|
|
* @param id Widget ID
|
|
* @return Widget pointer or nullptr
|
|
*/
|
|
UIWidget* findById(const std::string& id);
|
|
|
|
/**
|
|
* @brief Get the root widget
|
|
*/
|
|
UIWidget* getRoot() { return m_root.get(); }
|
|
|
|
/**
|
|
* @brief Set the root widget
|
|
*/
|
|
void setRoot(std::unique_ptr<UIWidget> root) { m_root = std::move(root); }
|
|
|
|
private:
|
|
std::unique_ptr<UIWidget> m_root;
|
|
std::unordered_map<std::string, WidgetFactory> m_factories;
|
|
|
|
/**
|
|
* @brief Parse a widget and its children recursively
|
|
*/
|
|
std::unique_ptr<UIWidget> parseWidget(const IDataNode& node);
|
|
|
|
/**
|
|
* @brief Parse common widget properties
|
|
*/
|
|
void parseCommonProperties(UIWidget* widget, const IDataNode& node);
|
|
|
|
/**
|
|
* @brief Parse layout properties from JSON
|
|
*/
|
|
void parseLayoutProperties(UIWidget* widget, const IDataNode& layoutNode);
|
|
|
|
/**
|
|
* @brief Register default widget types
|
|
*/
|
|
void registerDefaultWidgets();
|
|
};
|
|
|
|
} // namespace grove
|