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>
117 lines
4.5 KiB
C++
117 lines
4.5 KiB
C++
#pragma once
|
|
|
|
#include "IDataNode.h"
|
|
#include "JsonDataValue.h"
|
|
#include <nlohmann/json.hpp>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <memory>
|
|
#include <map>
|
|
#include <functional>
|
|
|
|
namespace grove {
|
|
|
|
using json = nlohmann::json;
|
|
|
|
/**
|
|
* @brief Concrete implementation of IDataNode backed by JSON
|
|
*
|
|
* Represents a node in the hierarchical data tree. Can have:
|
|
* - Children nodes (map of name -> node)
|
|
* - Own data (JSON value)
|
|
* - Path in the tree for identification
|
|
*/
|
|
class JsonDataNode : public IDataNode {
|
|
public:
|
|
/**
|
|
* @brief Create a node with name and optional data
|
|
* @param name Node name
|
|
* @param data Optional JSON data for this node
|
|
* @param parent Optional parent node (for path tracking)
|
|
* @param readOnly Whether this node is read-only (for config/)
|
|
*/
|
|
JsonDataNode(const std::string& name,
|
|
const json& data = json::object(),
|
|
JsonDataNode* parent = nullptr,
|
|
bool readOnly = false);
|
|
|
|
virtual ~JsonDataNode() = default;
|
|
|
|
// Tree navigation
|
|
std::unique_ptr<IDataNode> getChild(const std::string& name) override;
|
|
IDataNode* getChildReadOnly(const std::string& name) override;
|
|
std::vector<std::string> getChildNames() override;
|
|
bool hasChildren() override;
|
|
bool hasChild(const std::string& name) const override;
|
|
|
|
// Exact search in children
|
|
std::vector<IDataNode*> getChildrenByName(const std::string& name) override;
|
|
bool hasChildrenByName(const std::string& name) const override;
|
|
IDataNode* getFirstChildByName(const std::string& name) override;
|
|
|
|
// Pattern matching search
|
|
std::vector<IDataNode*> getChildrenByNameMatch(const std::string& pattern) override;
|
|
bool hasChildrenByNameMatch(const std::string& pattern) const override;
|
|
IDataNode* getFirstChildByNameMatch(const std::string& pattern) override;
|
|
|
|
// Query by properties
|
|
std::vector<IDataNode*> queryByProperty(const std::string& propName,
|
|
const std::function<bool(const IDataValue&)>& predicate) override;
|
|
|
|
// Node's own data
|
|
std::unique_ptr<IDataValue> getData() const override;
|
|
bool hasData() const override;
|
|
void setData(std::unique_ptr<IDataValue> data) override;
|
|
|
|
// Typed data access
|
|
std::string getString(const std::string& name, const std::string& defaultValue = "") const override;
|
|
int getInt(const std::string& name, int defaultValue = 0) const override;
|
|
double getDouble(const std::string& name, double defaultValue = 0.0) const override;
|
|
bool getBool(const std::string& name, bool defaultValue = false) const override;
|
|
bool hasProperty(const std::string& name) const override;
|
|
|
|
// Typed data modification
|
|
void setString(const std::string& name, const std::string& value) override;
|
|
void setInt(const std::string& name, int value) override;
|
|
void setDouble(const std::string& name, double value) override;
|
|
void setBool(const std::string& name, bool value) override;
|
|
|
|
// Hash system
|
|
std::string getDataHash() override;
|
|
std::string getTreeHash() override;
|
|
std::string getSubtreeHash(const std::string& childPath) override;
|
|
|
|
// Metadata
|
|
std::string getPath() const override;
|
|
std::string getName() const override;
|
|
std::string getNodeType() const override;
|
|
|
|
// Tree modification
|
|
void setChild(const std::string& name, std::unique_ptr<IDataNode> node) override;
|
|
bool removeChild(const std::string& name) override;
|
|
void clearChildren() override;
|
|
|
|
// Direct JSON access (for internal use by JsonDataTree)
|
|
const json& getJsonData() const { return m_data; }
|
|
json& getJsonData() { return m_data; }
|
|
const std::map<std::string, std::unique_ptr<JsonDataNode>>& getChildren() const { return m_children; }
|
|
|
|
private:
|
|
std::string m_name;
|
|
json m_data;
|
|
JsonDataNode* m_parent;
|
|
bool m_readOnly;
|
|
std::map<std::string, std::unique_ptr<JsonDataNode>> m_children;
|
|
|
|
// Helper methods
|
|
bool matchesPattern(const std::string& text, const std::string& pattern) const;
|
|
void collectMatchingNodes(const std::string& pattern, std::vector<IDataNode*>& results);
|
|
void collectNodesByProperty(const std::string& propName,
|
|
const std::function<bool(const IDataValue&)>& predicate,
|
|
std::vector<IDataNode*>& results);
|
|
std::string computeHash(const std::string& input) const;
|
|
void checkReadOnly() const;
|
|
};
|
|
|
|
} // namespace grove
|