Toolbar.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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/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 has_frame() const { return m_has_frame; }
  21. void set_has_frame(bool has_frame) { m_has_frame = has_frame; }
  22. protected:
  23. explicit Toolbar(Gfx::Orientation = Gfx::Orientation::Horizontal, int button_size = 16);
  24. virtual void paint_event(PaintEvent&) override;
  25. private:
  26. struct Item {
  27. enum class Type {
  28. Invalid,
  29. Separator,
  30. Action
  31. };
  32. Type type { Type::Invalid };
  33. RefPtr<Action> action;
  34. };
  35. NonnullOwnPtrVector<Item> m_items;
  36. const Gfx::Orientation m_orientation;
  37. int m_button_size { 16 };
  38. bool m_has_frame { true };
  39. };
  40. }