Toolbar.h 1.7 KB

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