summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI/Toolbar.h
blob: 8070867d2b622c3fa9ab7727b6b98926d116114c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/NonnullOwnPtrVector.h>
#include <LibGUI/Button.h>
#include <LibGUI/Widget.h>

namespace GUI {

class Toolbar : public Widget {
    C_OBJECT(Toolbar)
public:
    virtual ~Toolbar() override;

    ErrorOr<NonnullRefPtr<GUI::Button>> try_add_action(GUI::Action&);
    ErrorOr<void> try_add_separator();

    GUI::Button& add_action(GUI::Action&);
    void add_separator();

    bool has_frame() const { return m_has_frame; }
    void set_has_frame(bool has_frame) { m_has_frame = has_frame; }

protected:
    explicit Toolbar(Gfx::Orientation = Gfx::Orientation::Horizontal, int button_size = 16);

    virtual void paint_event(PaintEvent&) override;

private:
    struct Item {
        enum class Type {
            Invalid,
            Separator,
            Action
        };
        Type type { Type::Invalid };
        RefPtr<Action> action;
    };
    NonnullOwnPtrVector<Item> m_items;
    const Gfx::Orientation m_orientation;
    int m_button_size { 16 };
    bool m_has_frame { true };
};

}