summaryrefslogtreecommitdiff
path: root/LibGUI/GTableView.h
blob: c5aaab28fa02bda02a3e1561cc6e367f958b63ae (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
#pragma once

#include <LibGUI/GWidget.h>
#include <AK/Function.h>
#include <AK/HashMap.h>

class GScrollBar;
class GTableModel;

class GTableView : public GWidget {
public:
    explicit GTableView(GWidget* parent);
    virtual ~GTableView() override;

    virtual int header_height() const { return 16; }
    virtual int item_height() const { return 16; }

    void set_model(OwnPtr<GTableModel>&&);
    GTableModel* model() { return m_model.ptr(); }
    const GTableModel* model() const { return m_model.ptr(); }

    void did_update_model();

    int content_width() const;
    int horizontal_padding() const { return m_horizontal_padding; }

private:
    virtual void paint_event(GPaintEvent&) override;
    virtual void resize_event(GResizeEvent&) override;
    virtual void mousedown_event(GMouseEvent&) override;

    void update_scrollbar_ranges();
    int item_count() const;
    Rect row_rect(int item_index) const;

    GScrollBar* m_vertical_scrollbar { nullptr };
    GScrollBar* m_horizontal_scrollbar { nullptr };
    OwnPtr<GTableModel> m_model;
    int m_horizontal_padding { 5 };
};