mirror of
https://github.com/zhenyan121/SporeBG-Conid.git
synced 2026-04-10 06:14:08 +08:00
Added a overload setText
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 正常状态颜色
|
||||
|
||||
Reference in New Issue
Block a user