BoxLayout.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2022, the SerenityOS developers.
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <LibGUI/Forward.h>
  9. #include <LibGUI/Layout.h>
  10. #include <LibGfx/Orientation.h>
  11. namespace GUI {
  12. class BoxLayout : public Layout {
  13. C_OBJECT(BoxLayout);
  14. public:
  15. virtual ~BoxLayout() override = default;
  16. Gfx::Orientation orientation() const { return m_orientation; }
  17. virtual void run(Widget&) override;
  18. virtual Gfx::IntSize preferred_size() const override;
  19. virtual UISize min_size() const override;
  20. protected:
  21. explicit BoxLayout(Gfx::Orientation);
  22. private:
  23. int preferred_primary_size() const;
  24. int preferred_secondary_size() const;
  25. Gfx::Orientation m_orientation;
  26. };
  27. class VerticalBoxLayout final : public BoxLayout {
  28. C_OBJECT(VerticalBoxLayout);
  29. private:
  30. explicit VerticalBoxLayout()
  31. : BoxLayout(Gfx::Orientation::Vertical)
  32. {
  33. }
  34. virtual ~VerticalBoxLayout() override = default;
  35. };
  36. class HorizontalBoxLayout final : public BoxLayout {
  37. C_OBJECT(HorizontalBoxLayout);
  38. private:
  39. explicit HorizontalBoxLayout()
  40. : BoxLayout(Gfx::Orientation::Horizontal)
  41. {
  42. }
  43. virtual ~HorizontalBoxLayout() override = default;
  44. };
  45. }