mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 18:35:09 +00:00
LibGUI: Add GColumnsView
This is a shiny new widget that can display a tree using Miller columns ^:) In many cases, the columns view can be used as an alternative to tree view, but it has its own set of limitations: * It can only display one model column (so it cannot replace a table) * It takes up a lot of horizontal space, so it's only suitable if the item text is fairly short * It can only display one subtree at a time But as long as a usecase doesn't suffer from these limitations, a columns view can be *much* more intuitive than a tree view.
This commit is contained in:
parent
10324f95b0
commit
edb61d8bfd
3 changed files with 369 additions and 0 deletions
40
Libraries/LibGUI/GColumnsView.h
Normal file
40
Libraries/LibGUI/GColumnsView.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Vector.h>
|
||||
#include <LibGUI/GAbstractView.h>
|
||||
|
||||
class GColumnsView : public GAbstractView {
|
||||
C_OBJECT(GColumnsView)
|
||||
public:
|
||||
int model_column() const { return m_model_column; }
|
||||
void set_model_column(int column) { m_model_column = column; }
|
||||
|
||||
private:
|
||||
GColumnsView(GWidget* parent = nullptr);
|
||||
virtual ~GColumnsView();
|
||||
|
||||
GModelIndex index_at_event_position(const Point&) const;
|
||||
void push_column(GModelIndex& parent_index);
|
||||
void update_column_sizes();
|
||||
|
||||
int item_height() const { return 16; }
|
||||
int icon_size() const { return 16; }
|
||||
int icon_spacing() const { return 2; }
|
||||
int text_padding() const { return 2; }
|
||||
|
||||
virtual void did_update_model() override;
|
||||
virtual void paint_event(GPaintEvent&) override;
|
||||
virtual void mousedown_event(GMouseEvent& event) override;
|
||||
virtual void doubleclick_event(GMouseEvent& event) override;
|
||||
virtual void context_menu_event(GContextMenuEvent& event) override;
|
||||
virtual void keydown_event(GKeyEvent& event) override;
|
||||
|
||||
struct Column {
|
||||
GModelIndex parent_index;
|
||||
int width;
|
||||
// TODO: per-column vertical scroll?
|
||||
};
|
||||
|
||||
Vector<Column> m_columns;
|
||||
int m_model_column;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue