SNI: Proper alignment for the icons

This commit is contained in:
scorpion-26 2023-03-18 15:52:11 +01:00
parent 8e953f985b
commit d4ffac395b
2 changed files with 10 additions and 3 deletions

View file

@ -41,13 +41,14 @@ namespace SNI
parentBox->RemoveChild(iconBox);
auto container = Widget::Create<Box>();
container->SetSpacing({4, false});
iconBox = container.get();
for (auto& item : items)
{
if (item.iconData)
{
auto texture = Widget::Create<Texture>();
texture->SetHorizontalTransform({32, true, Alignment::Fill});
texture->SetHorizontalTransform({0, true, Alignment::Fill});
texture->SetBuf(item.w, item.h, item.iconData);
iconBox->AddChild(std::move(texture));
}

View file

@ -515,8 +515,14 @@ void Texture::SetBuf(size_t width, size_t height, uint8_t* buf)
void Texture::Draw(cairo_t* cr)
{
// TODO: W + H
cairo_rectangle(cr, 0.f, 0.f, 32.f, 32.f);
GtkAllocation dim;
gtk_widget_get_allocation(m_Widget, &dim);
double ratio = (double)m_Width / (double)m_Height;
gtk_widget_set_size_request(m_Widget, dim.height * ratio, dim.height);
double scale = (double)dim.height / (double)m_Height;
cairo_scale(cr, scale, scale);
cairo_rectangle(cr, 0.f, 0.f, m_Width, m_Height);
gdk_cairo_set_source_pixbuf(cr, m_Pixbuf, 0, 0);
cairo_fill(cr);
}