| 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 |
#pragma once |
| 32 |
|
| 33 |
#include "scene/gui/box_container.h" |
| 34 |
#include "scene/gui/panel_container.h" |
| 35 |
#include "scene/gui/tree.h" |
| 36 |
|
| 37 |
class LineEdit; |
| 38 |
class MenuButton; |
| 39 |
|
| 40 |
class SpanningHeader : public PanelContainer { |
| 41 |
GDCLASS(SpanningHeader, PanelContainer); |
| 42 |
|
| 43 |
public: |
| 44 |
SpanningHeader(const String &p_text); |
| 45 |
}; |
| 46 |
|
| 47 |
class DarkPanelContainer : public PanelContainer { |
| 48 |
GDCLASS(DarkPanelContainer, PanelContainer); |
| 49 |
|
| 50 |
public: |
| 51 |
DarkPanelContainer(); |
| 52 |
}; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
class TreeSortAndFilterBar : public HBoxContainer { |
| 57 |
GDCLASS(TreeSortAndFilterBar, HBoxContainer); |
| 58 |
|
| 59 |
public: |
| 60 |
|
| 61 |
enum SortType { |
| 62 |
NUMERIC_SORT = 0, |
| 63 |
ALPHA_SORT, |
| 64 |
SORT_TYPE_MAX |
| 65 |
}; |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
struct SortOptionIndexes { |
| 70 |
int ascending; |
| 71 |
int descending; |
| 72 |
}; |
| 73 |
|
| 74 |
protected: |
| 75 |
|
| 76 |
|
| 77 |
struct SortItem { |
| 78 |
SortItem() {} |
| 79 |
SortItem(int p_id, const String &p_label, SortType p_type, bool p_ascending, int p_column) : |
| 80 |
id(p_id), label(p_label), type(p_type), ascending(p_ascending), column(p_column) {} |
| 81 |
int id = 0; |
| 82 |
String label; |
| 83 |
SortType type = SortType::NUMERIC_SORT; |
| 84 |
bool ascending = false; |
| 85 |
int column = 0; |
| 86 |
}; |
| 87 |
|
| 88 |
struct TreeItemColumn { |
| 89 |
TreeItemColumn() {} |
| 90 |
TreeItemColumn(TreeItem *p_item, int p_column) : |
| 91 |
item(p_item), column(p_column) {} |
| 92 |
TreeItem *item = nullptr; |
| 93 |
int column; |
| 94 |
}; |
| 95 |
|
| 96 |
struct TreeItemAlphaComparator { |
| 97 |
bool operator()(const TreeItemColumn &p_a, const TreeItemColumn &p_b) const { |
| 98 |
return NoCaseComparator()(p_a.item->get_text(p_a.column), p_b.item->get_text(p_b.column)); |
| 99 |
} |
| 100 |
}; |
| 101 |
|
| 102 |
struct TreeItemNumericComparator { |
| 103 |
bool operator()(const TreeItemColumn &p_a, const TreeItemColumn &p_b) const { |
| 104 |
return p_a.item->get_text(p_a.column).to_int() < p_b.item->get_text(p_b.column).to_int(); |
| 105 |
} |
| 106 |
}; |
| 107 |
|
| 108 |
LineEdit *filter_edit = nullptr; |
| 109 |
MenuButton *sort_button = nullptr; |
| 110 |
Tree *managed_tree = nullptr; |
| 111 |
HashMap<int, SortItem> sort_items; |
| 112 |
int current_sort = 0; |
| 113 |
|
| 114 |
void _apply_filter(TreeItem *p_current_node = nullptr); |
| 115 |
void _apply_sort(); |
| 116 |
void _sort_changed(int p_id); |
| 117 |
void _filter_changed(const String &p_filter); |
| 118 |
|
| 119 |
public: |
| 120 |
TreeSortAndFilterBar(Tree *p_managed_tree, const String &p_filter_placeholder_text); |
| 121 |
void _notification(int p_what); |
| 122 |
SortOptionIndexes add_sort_option(const String &p_new_option, SortType p_sort_type, int p_sort_column, bool p_is_default = false); |
| 123 |
void clear_filter(); |
| 124 |
void clear(); |
| 125 |
void select_sort(int p_item_id); |
| 126 |
void apply(); |
| 127 |
}; |