Add label component

This commit is contained in:
2025-12-13 16:02:14 +08:00
parent 1e2555a35b
commit 1d1f71af19
2 changed files with 85 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
#include "Label.h"
Label::Label(const std::string& text, TextStyle style) :
m_labelData({text, style})
{
}
Label::Label() {
}
void Label::setText(const std::string& text, TextStyle style) {
m_labelData.text = text;
m_labelData.textstytle = style;
}
void Label::setText(const std::string& text) {
m_labelData.text = text;
}
void Label::setBackgroundColor(SDL_Color normal) {
m_labelData.backgroundColor = normal;
}
void Label::setBorder(int thickness, SDL_Color color) {
m_labelData.borderThickness = thickness;
m_labelData.borderColor = color;
}
void Label::update(float deltaTime) {
}

50
src/ui/components/Label.h Normal file
View File

@@ -0,0 +1,50 @@
#pragma once
#include "ui/base/UIComponent.h"
#include "ui/base/UIRenderData.h"
class Label : public UIComponent {
public:
Label(const std::string& text, TextStyle style);
~Label() override = default;
Label();
// 实现UIComponent接口
void update(float deltaTime) override;
/**
* @brief 设置按钮文本
* @param text 按钮文本
* @param style 文本样式
*/
void setText(const std::string& text, TextStyle style);
void setText(const std::string& text);
/**
* @brief 设置背景颜色
* @param normal 正常状态颜色
* @param hovered 悬停状态颜色(可选,默认透明)
* @param pressed 按下状态颜色(可选,默认透明)
*/
void setBackgroundColor(SDL_Color normal);
/**
* @brief 设置边框
* @param thickness 边框厚度(像素)
* @param color 边框颜色
*/
void setBorder(int thickness, SDL_Color color);
LabelData& getLabelDate() {
m_labelData.rect = m_rect;
return m_labelData;
}
private:
LabelData m_labelData;
};