| 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/control.h" |
| 34 |
#include "scene/gui/scroll_bar.h" |
| 35 |
#include "scene/property_list_helper.h" |
| 36 |
#include "scene/resources/text_paragraph.h" |
| 37 |
|
| 38 |
class ItemList : public Control { |
| 39 |
GDCLASS(ItemList, Control); |
| 40 |
|
| 41 |
public: |
| 42 |
enum IconMode { |
| 43 |
ICON_MODE_TOP, |
| 44 |
ICON_MODE_LEFT |
| 45 |
}; |
| 46 |
|
| 47 |
enum SelectMode { |
| 48 |
SELECT_SINGLE, |
| 49 |
SELECT_MULTI, |
| 50 |
SELECT_TOGGLE, |
| 51 |
}; |
| 52 |
|
| 53 |
enum ScrollHintMode { |
| 54 |
SCROLL_HINT_MODE_DISABLED, |
| 55 |
SCROLL_HINT_MODE_BOTH, |
| 56 |
SCROLL_HINT_MODE_TOP, |
| 57 |
SCROLL_HINT_MODE_BOTTOM, |
| 58 |
}; |
| 59 |
|
| 60 |
private: |
| 61 |
struct Item { |
| 62 |
mutable RID accessibility_item_element; |
| 63 |
mutable bool accessibility_item_dirty = true; |
| 64 |
|
| 65 |
Ref<Texture2D> icon; |
| 66 |
bool icon_transposed = false; |
| 67 |
Rect2i icon_region; |
| 68 |
Color icon_modulate = Color(1, 1, 1, 1); |
| 69 |
Ref<Texture2D> tag_icon; |
| 70 |
String text; |
| 71 |
String xl_text; |
| 72 |
Ref<TextParagraph> text_buf; |
| 73 |
String language; |
| 74 |
TextDirection text_direction = TEXT_DIRECTION_AUTO; |
| 75 |
AutoTranslateMode auto_translate_mode = AUTO_TRANSLATE_MODE_INHERIT; |
| 76 |
|
| 77 |
bool selectable = true; |
| 78 |
bool selected = false; |
| 79 |
bool disabled = false; |
| 80 |
bool tooltip_enabled = true; |
| 81 |
Variant metadata; |
| 82 |
String tooltip; |
| 83 |
Color custom_fg; |
| 84 |
Color custom_bg = Color(0.0, 0.0, 0.0, 0.0); |
| 85 |
|
| 86 |
int column = 0; |
| 87 |
Rect2 rect_cache; |
| 88 |
Rect2 min_rect_cache; |
| 89 |
|
| 90 |
Size2 get_icon_size() const; |
| 91 |
|
| 92 |
bool operator<(const Item &p_another) const { return text < p_another.text; } |
| 93 |
|
| 94 |
Item() { |
| 95 |
text_buf.instantiate(); |
| 96 |
} |
| 97 |
|
| 98 |
Item(bool p_dummy) {} |
| 99 |
}; |
| 100 |
RID accessibility_scroll_element; |
| 101 |
|
| 102 |
static inline PropertyListHelper base_property_helper; |
| 103 |
PropertyListHelper property_helper; |
| 104 |
|
| 105 |
int current = -1; |
| 106 |
int hovered = -1; |
| 107 |
int prev_hovered = -1; |
| 108 |
int shift_anchor = -1; |
| 109 |
|
| 110 |
bool shape_changed = true; |
| 111 |
|
| 112 |
bool ensure_selected_visible = false; |
| 113 |
bool same_column_width = false; |
| 114 |
bool allow_search = true; |
| 115 |
|
| 116 |
bool auto_width = false; |
| 117 |
float auto_width_value = 0.0; |
| 118 |
|
| 119 |
bool auto_height = false; |
| 120 |
float auto_height_value = 0.0; |
| 121 |
|
| 122 |
bool wraparound_items = true; |
| 123 |
|
| 124 |
Vector<Item> items; |
| 125 |
Vector<int> separators; |
| 126 |
|
| 127 |
SelectMode select_mode = SELECT_SINGLE; |
| 128 |
IconMode icon_mode = ICON_MODE_LEFT; |
| 129 |
VScrollBar *scroll_bar_v = nullptr; |
| 130 |
HScrollBar *scroll_bar_h = nullptr; |
| 131 |
TextServer::OverrunBehavior text_overrun_behavior = TextServer::OVERRUN_TRIM_ELLIPSIS; |
| 132 |
|
| 133 |
ScrollHintMode scroll_hint_mode = SCROLL_HINT_MODE_DISABLED; |
| 134 |
bool tile_scroll_hint = false; |
| 135 |
|
| 136 |
uint64_t search_time_msec = 0; |
| 137 |
String search_string; |
| 138 |
|
| 139 |
int current_columns = 1; |
| 140 |
int fixed_column_width = 0; |
| 141 |
int max_text_lines = 1; |
| 142 |
int max_columns = 1; |
| 143 |
|
| 144 |
Size2 fixed_icon_size; |
| 145 |
Size2 fixed_tag_icon_size; |
| 146 |
|
| 147 |
int defer_select_single = -1; |
| 148 |
bool allow_rmb_select = false; |
| 149 |
bool allow_reselect = false; |
| 150 |
|
| 151 |
real_t icon_scale = 1.0; |
| 152 |
|
| 153 |
bool do_autoscroll_to_bottom = false; |
| 154 |
|
| 155 |
void _scroll_changed(double); |
| 156 |
void _shape_text(int p_idx); |
| 157 |
void _mouse_exited(); |
| 158 |
void _shift_range_select(int p_from, int p_to); |
| 159 |
|
| 160 |
String _atr(int p_idx, const String &p_text) const; |
| 161 |
|
| 162 |
protected: |
| 163 |
struct ThemeCache { |
| 164 |
int h_separation = 0; |
| 165 |
int v_separation = 0; |
| 166 |
|
| 167 |
Ref<StyleBox> panel_style; |
| 168 |
Ref<StyleBox> focus_style; |
| 169 |
|
| 170 |
Ref<Font> font; |
| 171 |
int font_size = 0; |
| 172 |
Color font_color; |
| 173 |
Color font_hovered_color; |
| 174 |
Color font_hovered_selected_color; |
| 175 |
Color font_selected_color; |
| 176 |
int font_outline_size = 0; |
| 177 |
Color font_outline_color; |
| 178 |
|
| 179 |
int line_separation = 0; |
| 180 |
int icon_margin = 0; |
| 181 |
Ref<StyleBox> hovered_style; |
| 182 |
Ref<StyleBox> hovered_selected_style; |
| 183 |
Ref<StyleBox> hovered_selected_focus_style; |
| 184 |
Ref<StyleBox> selected_style; |
| 185 |
Ref<StyleBox> selected_focus_style; |
| 186 |
Ref<StyleBox> cursor_style; |
| 187 |
Ref<StyleBox> cursor_focus_style; |
| 188 |
Color guide_color; |
| 189 |
|
| 190 |
Ref<Texture2D> scroll_hint; |
| 191 |
Color scroll_hint_color; |
| 192 |
} theme_cache; |
| 193 |
|
| 194 |
void _notification(int p_what); |
| 195 |
bool _set(const StringName &p_name, const Variant &p_value); |
| 196 |
bool _get(const StringName &p_name, Variant &r_ret) const { return property_helper.property_get_value(p_name, r_ret); } |
| 197 |
void _get_property_list(List<PropertyInfo> *p_list) const { property_helper.get_property_list(p_list); } |
| 198 |
bool _property_can_revert(const StringName &p_name) const { return property_helper.property_can_revert(p_name); } |
| 199 |
bool _property_get_revert(const StringName &p_name, Variant &r_property) const { return property_helper.property_get_revert(p_name, r_property); } |
| 200 |
static void _bind_methods(); |
| 201 |
|
| 202 |
void _accessibility_action_scroll_set(const Variant &p_data); |
| 203 |
void _accessibility_action_scroll_up(const Variant &p_data); |
| 204 |
void _accessibility_action_scroll_down(const Variant &p_data); |
| 205 |
void _accessibility_action_scroll_left(const Variant &p_data); |
| 206 |
void _accessibility_action_scroll_right(const Variant &p_data); |
| 207 |
void _accessibility_action_scroll_into_view(const Variant &p_data, int p_index); |
| 208 |
void _accessibility_action_focus(const Variant &p_data, int p_index); |
| 209 |
void _accessibility_action_blur(const Variant &p_data, int p_index); |
| 210 |
|
| 211 |
public: |
| 212 |
virtual RID get_focused_accessibility_element() const override; |
| 213 |
|
| 214 |
virtual void gui_input(const Ref<InputEvent> &p_event) override; |
| 215 |
|
| 216 |
int add_item(const String &p_item, const Ref<Texture2D> &p_texture = Ref<Texture2D>(), bool p_selectable = true); |
| 217 |
int add_icon_item(const Ref<Texture2D> &p_item, bool p_selectable = true); |
| 218 |
|
| 219 |
void set_item_text(int p_idx, const String &p_text); |
| 220 |
String get_item_text(int p_idx) const; |
| 221 |
|
| 222 |
void set_item_text_direction(int p_idx, TextDirection p_text_direction); |
| 223 |
TextDirection get_item_text_direction(int p_idx) const; |
| 224 |
|
| 225 |
void set_item_language(int p_idx, const String &p_language); |
| 226 |
String get_item_language(int p_idx) const; |
| 227 |
|
| 228 |
void set_item_auto_translate_mode(int p_idx, AutoTranslateMode p_mode); |
| 229 |
AutoTranslateMode get_item_auto_translate_mode(int p_idx) const; |
| 230 |
|
| 231 |
void set_item_icon(int p_idx, const Ref<Texture2D> &p_icon); |
| 232 |
Ref<Texture2D> get_item_icon(int p_idx) const; |
| 233 |
|
| 234 |
void set_item_icon_transposed(int p_idx, const bool transposed); |
| 235 |
bool is_item_icon_transposed(int p_idx) const; |
| 236 |
|
| 237 |
void set_item_icon_region(int p_idx, const Rect2 &p_region); |
| 238 |
Rect2 get_item_icon_region(int p_idx) const; |
| 239 |
|
| 240 |
void set_item_icon_modulate(int p_idx, const Color &p_modulate); |
| 241 |
Color get_item_icon_modulate(int p_idx) const; |
| 242 |
|
| 243 |
void set_item_selectable(int p_idx, bool p_selectable); |
| 244 |
bool is_item_selectable(int p_idx) const; |
| 245 |
|
| 246 |
void set_item_disabled(int p_idx, bool p_disabled); |
| 247 |
bool is_item_disabled(int p_idx) const; |
| 248 |
|
| 249 |
void set_item_metadata(int p_idx, const Variant &p_metadata); |
| 250 |
Variant get_item_metadata(int p_idx) const; |
| 251 |
|
| 252 |
void set_item_tag_icon(int p_idx, const Ref<Texture2D> &p_tag_icon); |
| 253 |
|
| 254 |
void set_item_tooltip_enabled(int p_idx, const bool p_enabled); |
| 255 |
bool is_item_tooltip_enabled(int p_idx) const; |
| 256 |
|
| 257 |
void set_item_tooltip(int p_idx, const String &p_tooltip); |
| 258 |
String get_item_tooltip(int p_idx) const; |
| 259 |
|
| 260 |
void set_item_custom_bg_color(int p_idx, const Color &p_custom_bg_color); |
| 261 |
Color get_item_custom_bg_color(int p_idx) const; |
| 262 |
|
| 263 |
void set_item_custom_fg_color(int p_idx, const Color &p_custom_fg_color); |
| 264 |
Color get_item_custom_fg_color(int p_idx) const; |
| 265 |
|
| 266 |
Rect2 get_item_rect(int p_idx, bool p_expand = true) const; |
| 267 |
|
| 268 |
void set_text_overrun_behavior(TextServer::OverrunBehavior p_behavior); |
| 269 |
TextServer::OverrunBehavior get_text_overrun_behavior() const; |
| 270 |
|
| 271 |
void select(int p_idx, bool p_single = true); |
| 272 |
void deselect(int p_idx); |
| 273 |
void deselect_all(); |
| 274 |
bool is_selected(int p_idx) const; |
| 275 |
Vector<int> get_selected_items(); |
| 276 |
bool is_anything_selected(); |
| 277 |
|
| 278 |
void set_current(int p_current); |
| 279 |
int get_current() const; |
| 280 |
|
| 281 |
void move_item(int p_from_idx, int p_to_idx); |
| 282 |
|
| 283 |
void set_item_count(int p_count); |
| 284 |
int get_item_count() const; |
| 285 |
void remove_item(int p_idx); |
| 286 |
|
| 287 |
void clear(); |
| 288 |
|
| 289 |
void set_fixed_column_width(int p_size); |
| 290 |
int get_fixed_column_width() const; |
| 291 |
|
| 292 |
void set_same_column_width(bool p_enable); |
| 293 |
bool is_same_column_width() const; |
| 294 |
|
| 295 |
void set_max_text_lines(int p_lines); |
| 296 |
int get_max_text_lines() const; |
| 297 |
|
| 298 |
void set_max_columns(int p_amount); |
| 299 |
int get_max_columns() const; |
| 300 |
|
| 301 |
void set_select_mode(SelectMode p_mode); |
| 302 |
SelectMode get_select_mode() const; |
| 303 |
|
| 304 |
void set_icon_mode(IconMode p_mode); |
| 305 |
IconMode get_icon_mode() const; |
| 306 |
|
| 307 |
void set_fixed_icon_size(const Size2i &p_size); |
| 308 |
Size2i get_fixed_icon_size() const; |
| 309 |
|
| 310 |
void set_fixed_tag_icon_size(const Size2i &p_size); |
| 311 |
|
| 312 |
void set_allow_rmb_select(bool p_allow); |
| 313 |
bool get_allow_rmb_select() const; |
| 314 |
|
| 315 |
void set_allow_reselect(bool p_allow); |
| 316 |
bool get_allow_reselect() const; |
| 317 |
|
| 318 |
void set_allow_search(bool p_allow); |
| 319 |
bool get_allow_search() const; |
| 320 |
|
| 321 |
void ensure_current_is_visible(); |
| 322 |
|
| 323 |
void sort_items_by_text(); |
| 324 |
int find_metadata(const Variant &p_metadata) const; |
| 325 |
|
| 326 |
virtual String get_tooltip(const Point2 &p_pos) const override; |
| 327 |
int get_item_at_position(const Point2 &p_pos, bool p_exact = false) const; |
| 328 |
bool is_pos_at_end_of_items(const Point2 &p_pos) const; |
| 329 |
|
| 330 |
void set_icon_scale(real_t p_scale); |
| 331 |
real_t get_icon_scale() const; |
| 332 |
|
| 333 |
void set_auto_width(bool p_enable); |
| 334 |
bool has_auto_width() const; |
| 335 |
|
| 336 |
void set_auto_height(bool p_enable); |
| 337 |
bool has_auto_height() const; |
| 338 |
|
| 339 |
void set_wraparound_items(bool p_enable); |
| 340 |
bool has_wraparound_items() const; |
| 341 |
|
| 342 |
Size2 get_minimum_size() const override; |
| 343 |
|
| 344 |
void set_autoscroll_to_bottom(const bool p_enable); |
| 345 |
|
| 346 |
void force_update_list_size(); |
| 347 |
|
| 348 |
VScrollBar *get_v_scroll_bar() { return scroll_bar_v; } |
| 349 |
HScrollBar *get_h_scroll_bar() { return scroll_bar_h; } |
| 350 |
|
| 351 |
void set_scroll_hint_mode(ScrollHintMode p_mode); |
| 352 |
ScrollHintMode get_scroll_hint_mode() const; |
| 353 |
|
| 354 |
void set_tile_scroll_hint(bool p_enable); |
| 355 |
bool is_scroll_hint_tiled(); |
| 356 |
|
| 357 |
ItemList(); |
| 358 |
~ItemList(); |
| 359 |
}; |
| 360 |
|
| 361 |
VARIANT_ENUM_CAST(ItemList::SelectMode); |
| 362 |
VARIANT_ENUM_CAST(ItemList::IconMode); |
| 363 |
VARIANT_ENUM_CAST(ItemList::ScrollHintMode); |