2016-06-18 12:46:12 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* item_list.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2016-06-18 12:46:12 +00:00
|
|
|
/*************************************************************************/
|
2021-01-01 19:13:46 +00:00
|
|
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
2016-06-18 12:46:12 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2015-06-06 12:44:38 +00:00
|
|
|
#ifndef ITEMLIST_H
|
|
|
|
#define ITEMLIST_H
|
|
|
|
|
|
|
|
#include "scene/gui/control.h"
|
|
|
|
#include "scene/gui/scroll_bar.h"
|
|
|
|
|
|
|
|
class ItemList : public Control {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GDCLASS(ItemList, Control);
|
2015-06-06 12:44:38 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
public:
|
2015-06-06 12:44:38 +00:00
|
|
|
enum IconMode {
|
|
|
|
ICON_MODE_TOP,
|
|
|
|
ICON_MODE_LEFT
|
|
|
|
};
|
|
|
|
|
|
|
|
enum SelectMode {
|
|
|
|
SELECT_SINGLE,
|
|
|
|
SELECT_MULTI
|
|
|
|
};
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2015-06-06 12:44:38 +00:00
|
|
|
private:
|
|
|
|
struct Item {
|
|
|
|
|
|
|
|
Ref<Texture> icon;
|
2018-10-29 16:16:18 +00:00
|
|
|
bool icon_transposed;
|
2016-03-13 15:23:49 +00:00
|
|
|
Rect2i icon_region;
|
2018-03-11 14:59:50 +00:00
|
|
|
Color icon_modulate;
|
2015-06-06 12:44:38 +00:00
|
|
|
Ref<Texture> tag_icon;
|
|
|
|
String text;
|
|
|
|
bool selectable;
|
|
|
|
bool selected;
|
|
|
|
bool disabled;
|
2016-09-07 15:21:20 +00:00
|
|
|
bool tooltip_enabled;
|
2015-06-06 12:44:38 +00:00
|
|
|
Variant metadata;
|
|
|
|
String tooltip;
|
2017-09-03 07:44:59 +00:00
|
|
|
Color custom_fg;
|
2015-06-22 03:03:19 +00:00
|
|
|
Color custom_bg;
|
|
|
|
|
2015-06-06 12:44:38 +00:00
|
|
|
Rect2 rect_cache;
|
2016-05-27 19:42:51 +00:00
|
|
|
Rect2 min_rect_cache;
|
2015-06-22 03:03:19 +00:00
|
|
|
|
2016-03-13 15:23:49 +00:00
|
|
|
Size2 get_icon_size() const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool operator<(const Item &p_another) const { return text < p_another.text; }
|
2015-06-06 12:44:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int current;
|
|
|
|
|
|
|
|
bool shape_changed;
|
|
|
|
|
2015-08-23 23:15:56 +00:00
|
|
|
bool ensure_selected_visible;
|
2016-05-27 19:42:51 +00:00
|
|
|
bool same_column_width;
|
2015-08-23 23:15:56 +00:00
|
|
|
|
2017-07-21 06:17:06 +00:00
|
|
|
bool auto_height;
|
|
|
|
float auto_height_value;
|
|
|
|
|
2015-06-06 12:44:38 +00:00
|
|
|
Vector<Item> items;
|
|
|
|
Vector<int> separators;
|
|
|
|
|
|
|
|
SelectMode select_mode;
|
|
|
|
IconMode icon_mode;
|
|
|
|
VScrollBar *scroll_bar;
|
|
|
|
|
|
|
|
uint64_t search_time_msec;
|
|
|
|
String search_string;
|
|
|
|
|
|
|
|
int current_columns;
|
|
|
|
int fixed_column_width;
|
|
|
|
int max_text_lines;
|
|
|
|
int max_columns;
|
2016-05-27 19:42:51 +00:00
|
|
|
|
2016-06-12 19:51:27 +00:00
|
|
|
Size2 fixed_icon_size;
|
2016-05-27 19:42:51 +00:00
|
|
|
|
|
|
|
Size2 max_item_size_cache;
|
|
|
|
|
2016-05-04 20:41:58 +00:00
|
|
|
int defer_select_single;
|
|
|
|
|
2016-05-15 23:25:51 +00:00
|
|
|
bool allow_rmb_select;
|
|
|
|
|
2018-02-14 03:24:57 +00:00
|
|
|
bool allow_reselect;
|
|
|
|
|
2016-05-27 16:54:46 +00:00
|
|
|
real_t icon_scale;
|
|
|
|
|
2017-12-17 22:16:11 +00:00
|
|
|
bool do_autoscroll_to_bottom;
|
|
|
|
|
2017-07-04 11:38:56 +00:00
|
|
|
Array _get_items() const;
|
|
|
|
void _set_items(const Array &p_items);
|
|
|
|
|
2015-06-06 12:44:38 +00:00
|
|
|
void _scroll_changed(double);
|
2017-05-20 15:38:03 +00:00
|
|
|
void _gui_input(const Ref<InputEvent> &p_event);
|
2016-06-12 19:51:27 +00:00
|
|
|
|
2015-06-06 12:44:38 +00:00
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
|
|
|
static void _bind_methods();
|
2016-05-03 14:10:28 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
public:
|
|
|
|
void add_item(const String &p_item, const Ref<Texture> &p_texture = Ref<Texture>(), bool p_selectable = true);
|
|
|
|
void add_icon_item(const Ref<Texture> &p_item, bool p_selectable = true);
|
2015-06-06 12:44:38 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_item_text(int p_idx, const String &p_text);
|
2015-06-06 12:44:38 +00:00
|
|
|
String get_item_text(int p_idx) const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_item_icon(int p_idx, const Ref<Texture> &p_icon);
|
2015-06-06 12:44:38 +00:00
|
|
|
Ref<Texture> get_item_icon(int p_idx) const;
|
|
|
|
|
2018-10-29 16:16:18 +00:00
|
|
|
void set_item_icon_transposed(int p_idx, const bool transposed);
|
|
|
|
bool is_item_icon_transposed(int p_idx) const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_item_icon_region(int p_idx, const Rect2 &p_region);
|
2016-03-13 15:23:49 +00:00
|
|
|
Rect2 get_item_icon_region(int p_idx) const;
|
|
|
|
|
2018-03-11 14:59:50 +00:00
|
|
|
void set_item_icon_modulate(int p_idx, const Color &p_modulate);
|
|
|
|
Color get_item_icon_modulate(int p_idx) const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_item_selectable(int p_idx, bool p_selectable);
|
2015-06-06 12:44:38 +00:00
|
|
|
bool is_item_selectable(int p_idx) const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_item_disabled(int p_idx, bool p_disabled);
|
2015-06-06 12:44:38 +00:00
|
|
|
bool is_item_disabled(int p_idx) const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_item_metadata(int p_idx, const Variant &p_metadata);
|
2015-06-06 12:44:38 +00:00
|
|
|
Variant get_item_metadata(int p_idx) const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_item_tag_icon(int p_idx, const Ref<Texture> &p_tag_icon);
|
2015-06-06 12:44:38 +00:00
|
|
|
Ref<Texture> get_item_tag_icon(int p_idx) const;
|
|
|
|
|
2016-09-07 15:21:20 +00:00
|
|
|
void set_item_tooltip_enabled(int p_idx, const bool p_enabled);
|
|
|
|
bool is_item_tooltip_enabled(int p_idx) const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_item_tooltip(int p_idx, const String &p_tooltip);
|
2015-06-06 12:44:38 +00:00
|
|
|
String get_item_tooltip(int p_idx) const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_item_custom_bg_color(int p_idx, const Color &p_custom_bg_color);
|
2015-06-22 03:03:19 +00:00
|
|
|
Color get_item_custom_bg_color(int p_idx) const;
|
|
|
|
|
2017-09-03 07:44:59 +00:00
|
|
|
void set_item_custom_fg_color(int p_idx, const Color &p_custom_fg_color);
|
|
|
|
Color get_item_custom_fg_color(int p_idx) const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void select(int p_idx, bool p_single = true);
|
2015-06-06 12:44:38 +00:00
|
|
|
void unselect(int p_idx);
|
2017-11-24 13:39:02 +00:00
|
|
|
void unselect_all();
|
2015-06-06 12:44:38 +00:00
|
|
|
bool is_selected(int p_idx) const;
|
2016-06-28 17:09:17 +00:00
|
|
|
Vector<int> get_selected_items();
|
2017-11-24 13:39:02 +00:00
|
|
|
bool is_anything_selected();
|
2015-06-06 12:44:38 +00:00
|
|
|
|
|
|
|
void set_current(int p_current);
|
|
|
|
int get_current() const;
|
|
|
|
|
2018-03-13 14:19:04 +00:00
|
|
|
void move_item(int p_from_idx, int p_to_idx);
|
2015-06-06 12:44:38 +00:00
|
|
|
|
|
|
|
int get_item_count() const;
|
|
|
|
void remove_item(int p_idx);
|
|
|
|
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
void set_fixed_column_width(int p_size);
|
|
|
|
int get_fixed_column_width() const;
|
|
|
|
|
2016-05-27 19:42:51 +00:00
|
|
|
void set_same_column_width(bool p_enable);
|
2017-08-11 11:34:06 +00:00
|
|
|
bool is_same_column_width() const;
|
2016-05-27 19:42:51 +00:00
|
|
|
|
2017-08-11 19:10:05 +00:00
|
|
|
void set_max_text_lines(int p_lines);
|
2015-06-06 12:44:38 +00:00
|
|
|
int get_max_text_lines() const;
|
|
|
|
|
|
|
|
void set_max_columns(int p_amount);
|
|
|
|
int get_max_columns() const;
|
|
|
|
|
|
|
|
void set_select_mode(SelectMode p_mode);
|
|
|
|
SelectMode get_select_mode() const;
|
|
|
|
|
|
|
|
void set_icon_mode(IconMode p_mode);
|
|
|
|
IconMode get_icon_mode() const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_fixed_icon_size(const Size2 &p_size);
|
2016-06-12 19:51:27 +00:00
|
|
|
Size2 get_fixed_icon_size() const;
|
2016-05-15 02:48:23 +00:00
|
|
|
|
2016-05-15 23:25:51 +00:00
|
|
|
void set_allow_rmb_select(bool p_allow);
|
|
|
|
bool get_allow_rmb_select() const;
|
|
|
|
|
2018-02-14 03:24:57 +00:00
|
|
|
void set_allow_reselect(bool p_allow);
|
|
|
|
bool get_allow_reselect() const;
|
|
|
|
|
2015-06-06 12:44:38 +00:00
|
|
|
void ensure_current_is_visible();
|
|
|
|
|
2015-06-22 03:03:19 +00:00
|
|
|
void sort_items_by_text();
|
2017-03-05 15:44:50 +00:00
|
|
|
int find_metadata(const Variant &p_metadata) const;
|
2015-06-06 12:44:38 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
virtual String get_tooltip(const Point2 &p_pos) const;
|
2017-09-10 13:37:49 +00:00
|
|
|
int get_item_at_position(const Point2 &p_pos, bool p_exact = false) const;
|
2017-03-05 15:44:50 +00:00
|
|
|
bool is_pos_at_end_of_items(const Point2 &p_pos) const;
|
2015-06-06 12:44:38 +00:00
|
|
|
|
2016-05-27 16:54:46 +00:00
|
|
|
void set_icon_scale(real_t p_scale);
|
|
|
|
real_t get_icon_scale() const;
|
2016-05-24 17:09:58 +00:00
|
|
|
|
2017-07-21 06:17:06 +00:00
|
|
|
void set_auto_height(bool p_enable);
|
|
|
|
bool has_auto_height() const;
|
|
|
|
|
|
|
|
Size2 get_minimum_size() const;
|
|
|
|
|
2017-12-17 22:16:11 +00:00
|
|
|
void set_autoscroll_to_bottom(const bool p_enable);
|
|
|
|
|
2016-09-09 14:20:57 +00:00
|
|
|
VScrollBar *get_v_scroll() { return scroll_bar; }
|
|
|
|
|
2015-06-06 12:44:38 +00:00
|
|
|
ItemList();
|
|
|
|
~ItemList();
|
|
|
|
};
|
|
|
|
|
|
|
|
VARIANT_ENUM_CAST(ItemList::SelectMode);
|
|
|
|
VARIANT_ENUM_CAST(ItemList::IconMode);
|
|
|
|
|
|
|
|
#endif // ITEMLIST_H
|