Toolbar.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 <AK/NonnullOwnPtrVector.h>
  9. #include <LibGUI/Button.h>
  10. #include <LibGUI/Menu.h>
  11. #include <LibGUI/Widget.h>
  12. namespace GUI {
  13. class Toolbar : public Widget {
  14. C_OBJECT(Toolbar)
  15. public:
  16. virtual ~Toolbar() override = default;
  17. ErrorOr<NonnullRefPtr<GUI::Button>> try_add_action(GUI::Action&);
  18. ErrorOr<void> try_add_separator();
  19. GUI::Button& add_action(GUI::Action&);
  20. void add_separator();
  21. bool is_collapsible() const { return m_collapsible; }
  22. void set_collapsible(bool b) { m_collapsible = b; }
  23. bool is_grouped() const { return m_grouped; }
  24. void set_grouped(bool b) { m_grouped = b; }
  25. virtual Optional<UISize> calculated_preferred_size() const override;
  26. virtual Optional<UISize> calculated_min_size() const override;
  27. protected:
  28. explicit Toolbar(Gfx::Orientation = Gfx::Orientation::Horizontal, int button_size = 24);
  29. virtual void paint_event(PaintEvent&) override;
  30. virtual void resize_event(GUI::ResizeEvent&) override;
  31. ErrorOr<void> update_overflow_menu();
  32. ErrorOr<void> create_overflow_objects();
  33. private:
  34. struct Item {
  35. enum class Type {
  36. Invalid,
  37. Separator,
  38. Action
  39. };
  40. Type type { Type::Invalid };
  41. RefPtr<Action> action;
  42. RefPtr<Widget> widget;
  43. };
  44. NonnullOwnPtrVector<Item> m_items;
  45. RefPtr<Menu> m_overflow_menu;
  46. RefPtr<Action> m_overflow_action;
  47. RefPtr<Button> m_overflow_button;
  48. const Gfx::Orientation m_orientation;
  49. int m_button_size { 24 };
  50. bool m_collapsible { false };
  51. bool m_grouped { false };
  52. };
  53. }