From 1d1f71af198e85e4a83ed717a23b42e312923341 Mon Sep 17 00:00:00 2001 From: zhenyan121 <3367366583@qq.com> Date: Sat, 13 Dec 2025 16:02:14 +0800 Subject: [PATCH] Add label component --- src/ui/components/Label.cpp | 35 ++++++++++++++++++++++++++ src/ui/components/Label.h | 50 +++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 src/ui/components/Label.cpp create mode 100644 src/ui/components/Label.h diff --git a/src/ui/components/Label.cpp b/src/ui/components/Label.cpp new file mode 100644 index 0000000..0336644 --- /dev/null +++ b/src/ui/components/Label.cpp @@ -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) { + +} diff --git a/src/ui/components/Label.h b/src/ui/components/Label.h new file mode 100644 index 0000000..ba668fc --- /dev/null +++ b/src/ui/components/Label.h @@ -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; + + +}; \ No newline at end of file