SeparatorWidget.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2022, the SerenityOS developers.
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <LibGUI/Painter.h>
  8. #include <LibGUI/SeparatorWidget.h>
  9. #include <LibGfx/Palette.h>
  10. REGISTER_WIDGET(GUI, HorizontalSeparator)
  11. REGISTER_WIDGET(GUI, VerticalSeparator)
  12. namespace GUI {
  13. SeparatorWidget::SeparatorWidget(Gfx::Orientation orientation)
  14. : m_orientation(orientation)
  15. {
  16. set_preferred_size(SpecialDimension::Fit);
  17. }
  18. void SeparatorWidget::paint_event(PaintEvent& event)
  19. {
  20. Painter painter(*this);
  21. painter.add_clip_rect(event.rect());
  22. if (m_orientation == Gfx::Orientation::Vertical) {
  23. painter.translate(rect().center().x() - 1, 0);
  24. painter.draw_line({ 0, 0 }, { 0, rect().bottom() }, palette().threed_shadow1());
  25. painter.draw_line({ 1, 0 }, { 1, rect().bottom() }, palette().threed_highlight());
  26. } else {
  27. painter.translate(0, rect().center().y() - 1);
  28. painter.draw_line({ 0, 0 }, { rect().right(), 0 }, palette().threed_shadow1());
  29. painter.draw_line({ 0, 1 }, { rect().right(), 1 }, palette().threed_highlight());
  30. }
  31. }
  32. Optional<UISize> SeparatorWidget::calculated_preferred_size() const
  33. {
  34. if (m_orientation == Gfx::Orientation::Vertical)
  35. return UISize { 8, SpecialDimension::OpportunisticGrow };
  36. return UISize { SpecialDimension::OpportunisticGrow, 8 };
  37. }
  38. }