/* * Copyright (c) 2018-2020, Andreas Kling * Copyright (c) 2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include namespace GUI { class Toolbar : public Widget { C_OBJECT(Toolbar) public: virtual ~Toolbar() override = default; ErrorOr> try_add_action(GUI::Action&); ErrorOr try_add_separator(); GUI::Button& add_action(GUI::Action&); void add_separator(); bool is_collapsible() const { return m_collapsible; } void set_collapsible(bool b) { m_collapsible = b; } bool is_grouped() const { return m_grouped; } void set_grouped(bool b) { m_grouped = b; } virtual Optional calculated_preferred_size() const override; virtual Optional calculated_min_size() const override; protected: explicit Toolbar(Gfx::Orientation = Gfx::Orientation::Horizontal, int button_size = 24); virtual void paint_event(PaintEvent&) override; virtual void resize_event(GUI::ResizeEvent&) override; ErrorOr update_overflow_menu(); ErrorOr create_overflow_objects(); private: struct Item { enum class Type { Invalid, Separator, Action }; Type type { Type::Invalid }; RefPtr action; RefPtr widget; }; NonnullOwnPtrVector m_items; RefPtr m_overflow_menu; RefPtr m_overflow_action; RefPtr