summaryrefslogtreecommitdiff
path: root/Libraries/LibGUI/GTreeView.h
blob: 6fe0df6e696ce9bf1797548adca96961f21dc746 (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
#pragma once

#include <LibGUI/GAbstractView.h>

class GTreeView : public GAbstractView {
public:
    explicit GTreeView(GWidget*);
    virtual ~GTreeView() override;

    virtual void scroll_into_view(const GModelIndex&, Orientation);
    virtual const char* class_name() const override { return "GTreeView"; }

protected:
    virtual void paint_event(GPaintEvent&) override;
    virtual void mousedown_event(GMouseEvent&) override;
    virtual void keydown_event(GKeyEvent&) override;
    virtual void did_update_selection() override;
    virtual void did_update_model() override;

private:
    GModelIndex index_at_content_position(const Point&, bool& is_toggle) const;
    int item_height() const { return 16; }
    int max_item_width() const { return frame_inner_rect().width(); }
    int indent_width_in_pixels() const { return 16; }
    int icon_size() const { return 16; }
    int icon_spacing() const { return 2; }
    int toggle_size() const { return 9; }
    int text_padding() const { return 2; }
    void update_content_size();

    template<typename Callback>
    void traverse_in_paint_order(Callback) const;

    struct MetadataForIndex;

    MetadataForIndex& ensure_metadata_for_index(const GModelIndex&) const;

    mutable HashMap<void*, OwnPtr<MetadataForIndex>> m_view_metadata;

    RefPtr<GraphicsBitmap> m_expand_bitmap;
    RefPtr<GraphicsBitmap> m_collapse_bitmap;
};