Sfoglia il codice sorgente

LibGUI: Fix bad title alignment in GroupBox

Make a separate rect for the text and use IntRect::centered_within()
to sidestep any subpixel jitter. This way it looks good with both bitmap
and vector fonts.
Andreas Kling 2 anni fa
parent
commit
4d0d0a99b4
1 ha cambiato i file con 8 aggiunte e 2 eliminazioni
  1. 8 2
      Userland/Libraries/LibGUI/GroupBox.cpp

+ 8 - 2
Userland/Libraries/LibGUI/GroupBox.cpp

@@ -43,8 +43,14 @@ void GroupBox::paint_event(PaintEvent& event)
     Gfx::StylePainter::paint_frame(painter, frame_rect, palette(), Gfx::FrameStyle::SunkenBox);
 
     if (!m_title.is_empty()) {
-        Gfx::IntRect text_rect { 6, 1, font().width_rounded_up(m_title) + 6, font().pixel_size_rounded_up() };
-        painter.fill_rect(text_rect, palette().button());
+        // Fill with button background behind the text (covering the frame).
+        Gfx::IntRect text_background_rect { 6, 1, font().width_rounded_up(m_title) + 6, font().pixel_size_rounded_up() };
+        painter.fill_rect(text_background_rect, palette().button());
+
+        // Center text within button background rect to ensure symmetric padding on both sides.
+        // Note that we don't use TextAlignment::Center here to avoid subpixel jitter.
+        Gfx::IntRect text_rect { 0, 0, text_background_rect.width() - 6, text_background_rect.height() };
+        text_rect.center_within(text_background_rect);
         painter.draw_text(text_rect, m_title, Gfx::TextAlignment::CenterLeft, palette().button_text());
     }
 }