item_list.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /*************************************************************************/
  2. /* item_list.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef ITEMLIST_H
  31. #define ITEMLIST_H
  32. #include "scene/gui/control.h"
  33. #include "scene/gui/scroll_bar.h"
  34. class ItemList : public Control {
  35. GDCLASS(ItemList, Control);
  36. public:
  37. enum IconMode {
  38. ICON_MODE_TOP,
  39. ICON_MODE_LEFT
  40. };
  41. enum SelectMode {
  42. SELECT_SINGLE,
  43. SELECT_MULTI
  44. };
  45. private:
  46. struct Item {
  47. Ref<Texture> icon;
  48. bool icon_transposed;
  49. Rect2i icon_region;
  50. Color icon_modulate;
  51. Ref<Texture> tag_icon;
  52. String text;
  53. bool selectable;
  54. bool selected;
  55. bool disabled;
  56. bool tooltip_enabled;
  57. Variant metadata;
  58. String tooltip;
  59. Color custom_fg;
  60. Color custom_bg;
  61. Rect2 rect_cache;
  62. Rect2 min_rect_cache;
  63. Size2 get_icon_size() const;
  64. bool operator<(const Item &p_another) const { return text < p_another.text; }
  65. };
  66. int current;
  67. bool shape_changed;
  68. bool ensure_selected_visible;
  69. bool same_column_width;
  70. bool auto_height;
  71. float auto_height_value;
  72. Vector<Item> items;
  73. Vector<int> separators;
  74. SelectMode select_mode;
  75. IconMode icon_mode;
  76. VScrollBar *scroll_bar;
  77. uint64_t search_time_msec;
  78. String search_string;
  79. int current_columns;
  80. int fixed_column_width;
  81. int max_text_lines;
  82. int max_columns;
  83. Size2 fixed_icon_size;
  84. Size2 max_item_size_cache;
  85. int defer_select_single;
  86. bool allow_rmb_select;
  87. bool allow_reselect;
  88. real_t icon_scale;
  89. bool do_autoscroll_to_bottom;
  90. Array _get_items() const;
  91. void _set_items(const Array &p_items);
  92. void _scroll_changed(double);
  93. void _gui_input(const Ref<InputEvent> &p_event);
  94. protected:
  95. void _notification(int p_what);
  96. static void _bind_methods();
  97. public:
  98. void add_item(const String &p_item, const Ref<Texture> &p_texture = Ref<Texture>(), bool p_selectable = true);
  99. void add_icon_item(const Ref<Texture> &p_item, bool p_selectable = true);
  100. void set_item_text(int p_idx, const String &p_text);
  101. String get_item_text(int p_idx) const;
  102. void set_item_icon(int p_idx, const Ref<Texture> &p_icon);
  103. Ref<Texture> get_item_icon(int p_idx) const;
  104. void set_item_icon_transposed(int p_idx, const bool transposed);
  105. bool is_item_icon_transposed(int p_idx) const;
  106. void set_item_icon_region(int p_idx, const Rect2 &p_region);
  107. Rect2 get_item_icon_region(int p_idx) const;
  108. void set_item_icon_modulate(int p_idx, const Color &p_modulate);
  109. Color get_item_icon_modulate(int p_idx) const;
  110. void set_item_selectable(int p_idx, bool p_selectable);
  111. bool is_item_selectable(int p_idx) const;
  112. void set_item_disabled(int p_idx, bool p_disabled);
  113. bool is_item_disabled(int p_idx) const;
  114. void set_item_metadata(int p_idx, const Variant &p_metadata);
  115. Variant get_item_metadata(int p_idx) const;
  116. void set_item_tag_icon(int p_idx, const Ref<Texture> &p_tag_icon);
  117. Ref<Texture> get_item_tag_icon(int p_idx) const;
  118. void set_item_tooltip_enabled(int p_idx, const bool p_enabled);
  119. bool is_item_tooltip_enabled(int p_idx) const;
  120. void set_item_tooltip(int p_idx, const String &p_tooltip);
  121. String get_item_tooltip(int p_idx) const;
  122. void set_item_custom_bg_color(int p_idx, const Color &p_custom_bg_color);
  123. Color get_item_custom_bg_color(int p_idx) const;
  124. void set_item_custom_fg_color(int p_idx, const Color &p_custom_fg_color);
  125. Color get_item_custom_fg_color(int p_idx) const;
  126. void select(int p_idx, bool p_single = true);
  127. void unselect(int p_idx);
  128. void unselect_all();
  129. bool is_selected(int p_idx) const;
  130. Vector<int> get_selected_items();
  131. bool is_anything_selected();
  132. void set_current(int p_current);
  133. int get_current() const;
  134. void move_item(int p_from_idx, int p_to_idx);
  135. int get_item_count() const;
  136. void remove_item(int p_idx);
  137. void clear();
  138. void set_fixed_column_width(int p_size);
  139. int get_fixed_column_width() const;
  140. void set_same_column_width(bool p_enable);
  141. bool is_same_column_width() const;
  142. void set_max_text_lines(int p_lines);
  143. int get_max_text_lines() const;
  144. void set_max_columns(int p_amount);
  145. int get_max_columns() const;
  146. void set_select_mode(SelectMode p_mode);
  147. SelectMode get_select_mode() const;
  148. void set_icon_mode(IconMode p_mode);
  149. IconMode get_icon_mode() const;
  150. void set_fixed_icon_size(const Size2 &p_size);
  151. Size2 get_fixed_icon_size() const;
  152. void set_allow_rmb_select(bool p_allow);
  153. bool get_allow_rmb_select() const;
  154. void set_allow_reselect(bool p_allow);
  155. bool get_allow_reselect() const;
  156. void ensure_current_is_visible();
  157. void sort_items_by_text();
  158. int find_metadata(const Variant &p_metadata) const;
  159. virtual String get_tooltip(const Point2 &p_pos) const;
  160. int get_item_at_position(const Point2 &p_pos, bool p_exact = false) const;
  161. bool is_pos_at_end_of_items(const Point2 &p_pos) const;
  162. void set_icon_scale(real_t p_scale);
  163. real_t get_icon_scale() const;
  164. void set_auto_height(bool p_enable);
  165. bool has_auto_height() const;
  166. Size2 get_minimum_size() const;
  167. void set_autoscroll_to_bottom(const bool p_enable);
  168. VScrollBar *get_v_scroll() { return scroll_bar; }
  169. ItemList();
  170. ~ItemList();
  171. };
  172. VARIANT_ENUM_CAST(ItemList::SelectMode);
  173. VARIANT_ENUM_CAST(ItemList::IconMode);
  174. #endif // ITEMLIST_H