Toolbar.h 1006 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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/Widget.h>
  9. namespace GUI {
  10. class Toolbar : public Widget {
  11. C_OBJECT(Toolbar)
  12. public:
  13. virtual ~Toolbar() override;
  14. GUI::Button& add_action(GUI::Action&);
  15. void add_separator();
  16. bool has_frame() const { return m_has_frame; }
  17. void set_has_frame(bool has_frame) { m_has_frame = has_frame; }
  18. protected:
  19. explicit Toolbar(Gfx::Orientation = Gfx::Orientation::Horizontal, int button_size = 16);
  20. virtual void paint_event(PaintEvent&) override;
  21. private:
  22. struct Item {
  23. enum class Type {
  24. Invalid,
  25. Separator,
  26. Action
  27. };
  28. Type type { Type::Invalid };
  29. RefPtr<Action> action;
  30. };
  31. NonnullOwnPtrVector<Item> m_items;
  32. const Gfx::Orientation m_orientation;
  33. int m_button_size { 16 };
  34. bool m_has_frame { true };
  35. };
  36. }