Skip to content

Commit

Permalink
Render background for labels.
Browse files Browse the repository at this point in the history
  • Loading branch information
Themaister committed May 24, 2024
1 parent b98b48b commit f158983
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions ui/label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "label.hpp"
#include "widget.hpp"
#include "device.hpp"

namespace Granite
{
Expand Down Expand Up @@ -50,13 +51,29 @@ void Label::reconfigure_to_canvas(vec2, vec2)

float Label::render(FlatRenderer &renderer, float layer, vec2 offset, vec2 size)
{
if (bg_color.w > 0.0f)
{
if (bg_image)
{
auto *view = renderer.get_device().get_resource_manager().get_image_view_blocking(bg_image);
renderer.render_textured_quad(*view,
vec3(offset, layer), size,
vec2(0.0f), vec2(view->get_view_width(), view->get_view_height()),
DrawPipeline::AlphaBlend, bg_color, Vulkan::StockSampler::LinearClamp);
}
else
{
renderer.render_quad(vec3(offset, layer), size, bg_color);
}
}

auto &ui = *GRANITE_UI_MANAGER();
auto &font = ui.get_font(font_size);
renderer.render_text(font, text.c_str(), vec3(offset + geometry.margin, layer), size - 2.0f * geometry.margin,
renderer.render_text(font, text.c_str(), vec3(offset + geometry.margin, layer - 0.5f), size - 2.0f * geometry.margin,
color, alignment);

assert(children.empty());
return layer;
return layer - 0.5f;
}

void Label::reconfigure()
Expand Down

0 comments on commit f158983

Please sign in to comment.