Toolbar.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/NonnullOwnPtrVector.h>
  8. #include <LibGUI/Button.h>
  9. #include <LibGUI/Widget.h>
  10. namespace GUI {
  11. class Toolbar : public Widget {
  12. C_OBJECT(Toolbar)
  13. public:
  14. virtual ~Toolbar() override;
  15. ErrorOr<NonnullRefPtr<GUI::Button>> try_add_action(GUI::Action&);
  16. GUI::Button& add_action(GUI::Action&);
  17. void add_separator();
  18. bool has_frame() const { return m_has_frame; }
  19. void set_has_frame(bool has_frame) { m_has_frame = has_frame; }
  20. protected:
  21. explicit Toolbar(Gfx::Orientation = Gfx::Orientation::Horizontal, int button_size = 16);
  22. virtual void paint_event(PaintEvent&) override;
  23. private:
  24. struct Item {
  25. enum class Type {
  26. Invalid,
  27. Separator,
  28. Action
  29. };
  30. Type type { Type::Invalid };
  31. RefPtr<Action> action;
  32. };
  33. NonnullOwnPtrVector<Item> m_items;
  34. const Gfx::Orientation m_orientation;
  35. int m_button_size { 16 };
  36. bool m_has_frame { true };
  37. };
  38. }