From d4ffac395b6f47b23584546de5322a9089d8886c Mon Sep 17 00:00:00 2001 From: scorpion-26 <58082714+scorpion-26@users.noreply.github.com> Date: Sat, 18 Mar 2023 15:52:11 +0100 Subject: [PATCH] SNI: Proper alignment for the icons --- src/SNI.cpp | 3 ++- src/Widget.cpp | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/SNI.cpp b/src/SNI.cpp index 04b8aea..725b36b 100644 --- a/src/SNI.cpp +++ b/src/SNI.cpp @@ -41,13 +41,14 @@ namespace SNI parentBox->RemoveChild(iconBox); auto container = Widget::Create(); + container->SetSpacing({4, false}); iconBox = container.get(); for (auto& item : items) { if (item.iconData) { auto texture = Widget::Create(); - 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)); } diff --git a/src/Widget.cpp b/src/Widget.cpp index 59b36c3..8d7b66c 100644 --- a/src/Widget.cpp +++ b/src/Widget.cpp @@ -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); }