GGroupBox.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <LibDraw/Palette.h>
  2. #include <LibDraw/StylePainter.h>
  3. #include <LibGUI/GGroupBox.h>
  4. #include <LibGUI/GPainter.h>
  5. GGroupBox::GGroupBox(GWidget* parent)
  6. : GGroupBox({}, parent)
  7. {
  8. }
  9. GGroupBox::GGroupBox(const StringView& title, GWidget* parent)
  10. : GWidget(parent)
  11. , m_title(title)
  12. {
  13. }
  14. GGroupBox::~GGroupBox()
  15. {
  16. }
  17. void GGroupBox::paint_event(GPaintEvent& event)
  18. {
  19. GPainter painter(*this);
  20. painter.add_clip_rect(event.rect());
  21. Rect frame_rect {
  22. 0, font().glyph_height() / 2,
  23. width(), height() - font().glyph_height() / 2
  24. };
  25. StylePainter::paint_frame(painter, frame_rect, palette(), FrameShape::Box, FrameShadow::Sunken, 2);
  26. Rect text_rect { 4, 0, font().width(m_title) + 6, font().glyph_height() };
  27. painter.fill_rect(text_rect, palette().button());
  28. painter.draw_text(text_rect, m_title, TextAlignment::Center, palette().button_text());
  29. }
  30. void GGroupBox::set_title(const StringView& title)
  31. {
  32. if (m_title == title)
  33. return;
  34. m_title = title;
  35. update();
  36. }