Added a overload setText

This commit is contained in:
2025-12-13 18:35:07 +08:00
parent e697d6f797
commit 4a71e4f742
2 changed files with 18 additions and 0 deletions

View File

@@ -22,6 +22,18 @@ void Button::setText(const std::string& text, TextStyle style) {
}
}
void Button::setText(const std::string& text) {
m_buttonData.text = text;
// 如果提供了 TextRenderer则立即测量文本并更新控件尺寸
if (m_textRenderer) {
auto [w, h] = m_textRenderer->getTextSize(text, m_buttonData.textstytle);
m_rect.w = static_cast<float>(w);
m_rect.h = static_cast<float>(h);
m_buttonData.rect = m_rect;
}
}
void Button::setBackgroundColor(SDL_Color normal) {
m_buttonData.backgroundColor = normal;
}

View File

@@ -25,6 +25,12 @@ public:
*/
void setText(const std::string& text, TextStyle style);
/**
* @brief 设置按钮文本(不改变样式)
* @param text 按钮文本
*/
void setText(const std::string& text);
/**
* @brief 设置背景颜色
* @param normal 正常状态颜色