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>
132 lines
3.1 KiB
C++
132 lines
3.1 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
#include <memory>
|
|
#include <cstdint>
|
|
#include "UILayout.h"
|
|
|
|
namespace grove {
|
|
|
|
class UIContext;
|
|
class UIRenderer;
|
|
|
|
/**
|
|
* @brief Base interface for all UI widgets
|
|
*
|
|
* Retained-mode UI widget with hierarchical structure.
|
|
* Each widget has position, size, visibility, and can have children.
|
|
*/
|
|
class UIWidget {
|
|
public:
|
|
virtual ~UIWidget() = default;
|
|
|
|
/**
|
|
* @brief Update widget state
|
|
* @param ctx UI context with input state
|
|
* @param deltaTime Time since last update
|
|
*/
|
|
virtual void update(UIContext& ctx, float deltaTime) = 0;
|
|
|
|
/**
|
|
* @brief Render widget via UIRenderer
|
|
* @param renderer Renderer that publishes to IIO
|
|
*/
|
|
virtual void render(UIRenderer& renderer) = 0;
|
|
|
|
/**
|
|
* @brief Get widget type name
|
|
* @return Type string (e.g., "panel", "label", "button")
|
|
*/
|
|
virtual std::string getType() const = 0;
|
|
|
|
// Identity
|
|
std::string id;
|
|
std::string tooltip; // Tooltip text (empty = no tooltip)
|
|
|
|
// Position and size (relative to parent)
|
|
float x = 0.0f;
|
|
float y = 0.0f;
|
|
float width = 0.0f;
|
|
float height = 0.0f;
|
|
bool visible = true;
|
|
|
|
// Layout properties (Phase 2)
|
|
LayoutProperties layoutProps;
|
|
|
|
// Hierarchy
|
|
UIWidget* parent = nullptr;
|
|
std::vector<std::unique_ptr<UIWidget>> children;
|
|
|
|
// Computed absolute position (after layout)
|
|
float absX = 0.0f;
|
|
float absY = 0.0f;
|
|
|
|
/**
|
|
* @brief Compute absolute position from parent chain
|
|
*/
|
|
void computeAbsolutePosition() {
|
|
if (parent) {
|
|
absX = parent->absX + x;
|
|
absY = parent->absY + y;
|
|
} else {
|
|
absX = x;
|
|
absY = y;
|
|
}
|
|
for (auto& child : children) {
|
|
child->computeAbsolutePosition();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief Add a child widget
|
|
* @param child Widget to add
|
|
*/
|
|
void addChild(std::unique_ptr<UIWidget> child) {
|
|
child->parent = this;
|
|
children.push_back(std::move(child));
|
|
}
|
|
|
|
/**
|
|
* @brief Find widget by ID recursively
|
|
* @param targetId ID to search for
|
|
* @return Widget pointer or nullptr
|
|
*/
|
|
UIWidget* findById(const std::string& targetId) {
|
|
if (id == targetId) {
|
|
return this;
|
|
}
|
|
for (auto& child : children) {
|
|
if (UIWidget* found = child->findById(targetId)) {
|
|
return found;
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
protected:
|
|
/**
|
|
* @brief Update all children
|
|
*/
|
|
void updateChildren(UIContext& ctx, float deltaTime) {
|
|
for (auto& child : children) {
|
|
if (child->visible) {
|
|
child->update(ctx, deltaTime);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief Render all children
|
|
*/
|
|
void renderChildren(UIRenderer& renderer) {
|
|
for (auto& child : children) {
|
|
if (child->visible) {
|
|
child->render(renderer);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
} // namespace grove
|