Toolbar.h 1.1 KB

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