feat: add background support for Label

This commit is contained in:
2026-02-05 10:25:37 +08:00
parent 7db7697625
commit c35fe48fc3
2 changed files with 12 additions and 8 deletions

View File

@@ -44,7 +44,7 @@ void UIRenderer::renderUI(const UIRenderData& uiRenderData) {
void UIRenderer::renderButton(const ButtonData& buttonData) {
//SDL_Log("render button\n");
renderButtonBackground(buttonData);
renderBackground<ButtonData>(buttonData);
renderButtonBorder(buttonData);
renderText<ButtonData>(buttonData);
@@ -52,12 +52,13 @@ void UIRenderer::renderButton(const ButtonData& buttonData) {
void UIRenderer::renderLabel(const LabelData& labelData) {
//SDL_Log("start render label\n");
renderBackground<LabelData>(labelData);
renderText<LabelData>(labelData);
}
void UIRenderer::renderButtonBackground(const ButtonData& buttonData) {
template <typename Type>
void UIRenderer::renderBackground(const Type& data) {
// 设置绘制颜色
if (!m_renderer) {
SDL_Log("renderer is null\n");
@@ -65,9 +66,11 @@ void UIRenderer::renderButtonBackground(const ButtonData& buttonData) {
// SDL_Log("renderButtonBackground called for rect (%d,%d,%d,%d)",
// buttonData.rect.x, buttonData.rect.y, buttonData.rect.w, buttonData.rect.h);
//SDL_Log("start render background\n");
auto m_backgroundColor = buttonData.backgroundColor;
auto m_rect = buttonData.rect;
auto m_backgroundColor = data.backgroundColor;
auto m_rect = data.rect;
if (data.backgroundColor.a == 0) {
return;
}
SDL_SetRenderDrawColor(m_renderer, m_backgroundColor.r, m_backgroundColor.g, m_backgroundColor.b, m_backgroundColor.a);
//auto [width, height] = m_textRenderer->getLogicalTextSize(buttonData.text, buttonData.textstytle);
auto viewport = m_textRenderer->getViewport();

View File

@@ -13,10 +13,11 @@ private:
/**
* @brief 渲染按钮背景
* @brief 渲染背景
* @param renderer SDL渲染器
*/
void renderButtonBackground(const ButtonData& buttonData);
template <typename Type>
void renderBackground(const Type& data);
/**
* @brief 渲染按钮边框