diff --git a/src/ui/base/IUIManager.h b/src/ui/base/IUIManager.h index 44c7029..4f91aec 100644 --- a/src/ui/base/IUIManager.h +++ b/src/ui/base/IUIManager.h @@ -20,9 +20,50 @@ public: virtual const UIRenderData& getUIRenderData() = 0; // 收集渲染数据 virtual void CollectRenderData() = 0; - - - + // 提供接口给外部设置ui的各种设置 + void setButton(const std::string& name, int x, int y) { + size_t hash = makeHash(name); + auto it = m_buttons.find(hash); + if (it != m_buttons.end()) { + it->second->setPosition(x, y); + } + } + void setButton(const std::string&name, bool enabled) { + size_t hash = makeHash(name); + auto it = m_buttons.find(hash); + if (it != m_buttons.end()) { + it->second->setEnabled(enabled); + it->second->setVisible(enabled); + } + } + void setButton(const std::string& name, const std::string& text) { + size_t hash = makeHash(name); + auto it = m_buttons.find(hash); + if (it != m_buttons.end()) { + it->second->setText(text); + } + } + void setLabel(const std::string& name, int x, int y) { + size_t hash = makeHash(name); + auto it = m_labels.find(hash); + if (it != m_labels.end()) { + it->second->setPosition(x, y); + } + } + void setLabel(const std::string& name, bool visible) { + size_t hash = makeHash(name); + auto it = m_labels.find(hash); + if (it != m_labels.end()) { + it->second->setVisible(visible); + } + } + void setLabel(const std::string& name, const std::string& text) { + size_t hash = makeHash(name); + auto it = m_labels.find(hash); + if (it != m_labels.end()) { + it->second->setText(text); + } + } protected: std::unordered_map> m_buttons; std::unordered_map> m_labels; diff --git a/src/ui/base/UIComponent.h b/src/ui/base/UIComponent.h index 8fa2c54..f729207 100644 --- a/src/ui/base/UIComponent.h +++ b/src/ui/base/UIComponent.h @@ -44,7 +44,10 @@ public: m_rect.x = static_cast(x); m_rect.y = static_cast(y); } - + void setPosition(int x, int y) { + m_rect.x = static_cast(x); + m_rect.y = static_cast(y); + } /** * @brief 获取组件边界矩形 * @return SDL_FRect 浮点矩形