Add allow_search property to ItemList and Tree

This commit is contained in:
needleful 2023-04-17 23:50:24 -07:00 committed by Hugo Locurcio
parent adee8cfee6
commit aac5558760
No known key found for this signature in database
GPG key ID: 39E8F8BE30B0A49C
6 changed files with 42 additions and 2 deletions

View file

@ -315,6 +315,9 @@
<member name="allow_rmb_select" type="bool" setter="set_allow_rmb_select" getter="get_allow_rmb_select" default="false">
If [code]true[/code], right mouse button click can select items.
</member>
<member name="allow_search" type="bool" setter="set_allow_search" getter="get_allow_search" default="true">
If [code]true[/code], allows navigating the [ItemList] with letter keys through incremental search.
</member>
<member name="auto_height" type="bool" setter="set_auto_height" getter="has_auto_height" default="false">
If [code]true[/code], the control will automatically resize the height to fit its content.
</member>

View file

@ -218,6 +218,9 @@
<member name="allow_rmb_select" type="bool" setter="set_allow_rmb_select" getter="get_allow_rmb_select" default="false">
If [code]true[/code], a right mouse button click can select items.
</member>
<member name="allow_search" type="bool" setter="set_allow_search" getter="get_allow_search" default="true">
If [code]true[/code], allows navigating the [Tree] with letter keys through incremental search.
</member>
<member name="column_titles_visible" type="bool" setter="set_column_titles_visible" getter="are_column_titles_visible" default="false">
If [code]true[/code], column titles are visible.
</member>

View file

@ -667,7 +667,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
} else {
Ref<InputEventKey> k = p_event;
if (k.is_valid() && k->get_unicode()) {
if (allow_search && k.is_valid() && k->get_unicode()) {
uint64_t now = OS::get_singleton()->get_ticks_msec();
uint64_t diff = now - search_time_msec;
uint64_t max_interval = uint64_t(GLOBAL_DEF("gui/timers/incremental_search_max_interval_msec", 2000));
@ -1273,6 +1273,14 @@ bool ItemList::get_allow_reselect() const {
return allow_reselect;
}
void ItemList::set_allow_search(bool p_allow) {
allow_search = p_allow;
}
bool ItemList::get_allow_search() const {
return allow_search;
}
void ItemList::set_icon_scale(real_t p_scale) {
ERR_FAIL_COND(Math::is_nan(p_scale) || Math::is_inf(p_scale));
icon_scale = p_scale;
@ -1437,6 +1445,9 @@ void ItemList::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_allow_reselect", "allow"), &ItemList::set_allow_reselect);
ClassDB::bind_method(D_METHOD("get_allow_reselect"), &ItemList::get_allow_reselect);
ClassDB::bind_method(D_METHOD("set_allow_search", "allow"), &ItemList::set_allow_search);
ClassDB::bind_method(D_METHOD("get_allow_search"), &ItemList::get_allow_search);
ClassDB::bind_method(D_METHOD("set_auto_height", "enable"), &ItemList::set_auto_height);
ClassDB::bind_method(D_METHOD("has_auto_height"), &ItemList::has_auto_height);
@ -1459,6 +1470,7 @@ void ItemList::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "select_mode", PROPERTY_HINT_ENUM, "Single,Multi"), "set_select_mode", "get_select_mode");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_reselect"), "set_allow_reselect", "get_allow_reselect");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_rmb_select"), "set_allow_rmb_select", "get_allow_rmb_select");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_search"), "set_allow_search", "get_allow_search");
ADD_PROPERTY(PropertyInfo(Variant::INT, "max_text_lines", PROPERTY_HINT_RANGE, "1,10,1,or_greater"), "set_max_text_lines", "get_max_text_lines");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_height"), "set_auto_height", "has_auto_height");
ADD_GROUP("Columns", "");
@ -1495,6 +1507,7 @@ ItemList::ItemList() {
fixed_column_width = 0;
same_column_width = false;
allow_search = true;
max_text_lines = 1;
max_columns = 1;
auto_height = false;

View file

@ -79,6 +79,7 @@ private:
bool ensure_selected_visible;
bool same_column_width;
bool allow_search;
bool auto_height;
float auto_height_value;
@ -209,6 +210,9 @@ public:
void set_allow_reselect(bool p_allow);
bool get_allow_reselect() const;
void set_allow_search(bool p_allow);
bool get_allow_search() const;
void ensure_current_is_visible();
void sort_items_by_text();

View file

@ -2332,7 +2332,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
accept_event();
}
if (k.is_valid()) { // Incremental search
if (allow_search && k.is_valid()) { // Incremental search
if (!k->is_pressed()) {
return;
@ -3817,6 +3817,14 @@ bool Tree::get_allow_reselect() const {
return allow_reselect;
}
void Tree::set_allow_search(bool p_allow) {
allow_search = p_allow;
}
bool Tree::get_allow_search() const {
return allow_search;
}
void Tree::_bind_methods() {
ClassDB::bind_method(D_METHOD("_range_click_timeout"), &Tree::_range_click_timeout);
ClassDB::bind_method(D_METHOD("_gui_input"), &Tree::_gui_input);
@ -3879,10 +3887,14 @@ void Tree::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_allow_reselect", "allow"), &Tree::set_allow_reselect);
ClassDB::bind_method(D_METHOD("get_allow_reselect"), &Tree::get_allow_reselect);
ClassDB::bind_method(D_METHOD("set_allow_search", "allow"), &Tree::set_allow_search);
ClassDB::bind_method(D_METHOD("get_allow_search"), &Tree::get_allow_search);
ADD_PROPERTY(PropertyInfo(Variant::INT, "columns"), "set_columns", "get_columns");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "column_titles_visible"), "set_column_titles_visible", "are_column_titles_visible");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_reselect"), "set_allow_reselect", "get_allow_reselect");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_rmb_select"), "set_allow_rmb_select", "get_allow_rmb_select");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_search"), "set_allow_search", "get_allow_search");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hide_folding"), "set_hide_folding", "is_folding_hidden");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hide_root"), "set_hide_root", "is_root_hidden");
ADD_PROPERTY(PropertyInfo(Variant::INT, "drop_mode_flags", PROPERTY_HINT_FLAGS, "On Item,In between"), "set_drop_mode_flags", "get_drop_mode_flags");
@ -4008,6 +4020,7 @@ Tree::Tree() {
cache.hover_cell = -1;
allow_reselect = false;
allow_search = true;
propagate_mouse_activated = false;
update_cache();

View file

@ -496,6 +496,7 @@ private:
bool scrolling;
bool allow_reselect;
bool allow_search;
bool force_edit_checkbox_only_on_checkbox;
@ -609,6 +610,9 @@ public:
void set_allow_reselect(bool p_allow);
bool get_allow_reselect() const;
void set_allow_search(bool p_allow);
bool get_allow_search() const;
Tree();
~Tree();
};