feat: add UIManager interface for external modification

This commit is contained in:
2025-12-28 20:54:36 +08:00
parent 778c17811e
commit 152d210f00
2 changed files with 48 additions and 4 deletions

View File

@@ -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<int, std::unique_ptr<Button>> m_buttons;
std::unordered_map<int, std::unique_ptr<Label>> m_labels;

View File

@@ -44,7 +44,10 @@ public:
m_rect.x = static_cast<float>(x);
m_rect.y = static_cast<float>(y);
}
void setPosition(int x, int y) {
m_rect.x = static_cast<float>(x);
m_rect.y = static_cast<float>(y);
}
/**
* @brief 获取组件边界矩形
* @return SDL_FRect 浮点矩形