Merge pull request #76199 from needleful/incremental_search_property

Add allow_search property to ItemList and Tree to control incremental search
This commit is contained in:
Rémi Verschelde 2023-04-25 14:44:06 +02:00
commit ae7872fd02
No known key found for this signature in database
GPG Key ID: C3336907360768E1
6 changed files with 40 additions and 2 deletions

View File

@ -341,6 +341,9 @@
<member name="allow_rmb_select" type="bool" setter="set_allow_rmb_select" getter="get_allow_rmb_select" default="false"> <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. If [code]true[/code], right mouse button click can select items.
</member> </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"> <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. If [code]true[/code], the control will automatically resize the height to fit its content.
</member> </member>

View File

@ -335,6 +335,9 @@
<member name="allow_rmb_select" type="bool" setter="set_allow_rmb_select" getter="get_allow_rmb_select" default="false"> <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. If [code]true[/code], a right mouse button click can select items.
</member> </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="clip_contents" type="bool" setter="set_clip_contents" getter="is_clipping_contents" overrides="Control" default="true" /> <member name="clip_contents" type="bool" setter="set_clip_contents" getter="is_clipping_contents" overrides="Control" default="true" />
<member name="column_titles_visible" type="bool" setter="set_column_titles_visible" getter="are_column_titles_visible" default="false"> <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. If [code]true[/code], column titles are visible.

View File

@ -897,7 +897,7 @@ void ItemList::gui_input(const Ref<InputEvent> &p_event) {
} else { } else {
Ref<InputEventKey> k = p_event; 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 now = OS::get_singleton()->get_ticks_msec();
uint64_t diff = now - search_time_msec; uint64_t diff = now - search_time_msec;
uint64_t max_interval = uint64_t(GLOBAL_GET("gui/timers/incremental_search_max_interval_msec")); uint64_t max_interval = uint64_t(GLOBAL_GET("gui/timers/incremental_search_max_interval_msec"));
@ -1586,6 +1586,14 @@ bool ItemList::get_allow_reselect() const {
return allow_reselect; 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) { void ItemList::set_icon_scale(real_t p_scale) {
ERR_FAIL_COND(!Math::is_finite(p_scale)); ERR_FAIL_COND(!Math::is_finite(p_scale));
icon_scale = p_scale; icon_scale = p_scale;
@ -1828,6 +1836,9 @@ void ItemList::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_allow_reselect", "allow"), &ItemList::set_allow_reselect); 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("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("set_auto_height", "enable"), &ItemList::set_auto_height);
ClassDB::bind_method(D_METHOD("has_auto_height"), &ItemList::has_auto_height); ClassDB::bind_method(D_METHOD("has_auto_height"), &ItemList::has_auto_height);
@ -1845,6 +1856,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::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_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_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::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_PROPERTY(PropertyInfo(Variant::BOOL, "auto_height"), "set_auto_height", "has_auto_height");
ADD_PROPERTY(PropertyInfo(Variant::INT, "text_overrun_behavior", PROPERTY_HINT_ENUM, "Trim Nothing,Trim Characters,Trim Words,Ellipsis,Word Ellipsis"), "set_text_overrun_behavior", "get_text_overrun_behavior"); ADD_PROPERTY(PropertyInfo(Variant::INT, "text_overrun_behavior", PROPERTY_HINT_ENUM, "Trim Nothing,Trim Characters,Trim Words,Ellipsis,Word Ellipsis"), "set_text_overrun_behavior", "get_text_overrun_behavior");

View File

@ -90,6 +90,7 @@ private:
bool ensure_selected_visible = false; bool ensure_selected_visible = false;
bool same_column_width = false; bool same_column_width = false;
bool allow_search = true;
bool auto_height = false; bool auto_height = false;
float auto_height_value = 0.0; float auto_height_value = 0.0;
@ -258,6 +259,9 @@ public:
void set_allow_reselect(bool p_allow); void set_allow_reselect(bool p_allow);
bool get_allow_reselect() const; bool get_allow_reselect() const;
void set_allow_search(bool p_allow);
bool get_allow_search() const;
void ensure_current_is_visible(); void ensure_current_is_visible();
void sort_items_by_text(); void sort_items_by_text();

View File

@ -3395,7 +3395,7 @@ void Tree::gui_input(const Ref<InputEvent> &p_event) {
accept_event(); accept_event();
} }
if (k.is_valid()) { // Incremental search if (allow_search && k.is_valid()) { // Incremental search
if (!k->is_pressed()) { if (!k->is_pressed()) {
return; return;
@ -5246,6 +5246,14 @@ bool Tree::get_allow_reselect() const {
return allow_reselect; 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() { void Tree::_bind_methods() {
ClassDB::bind_method(D_METHOD("clear"), &Tree::clear); ClassDB::bind_method(D_METHOD("clear"), &Tree::clear);
ClassDB::bind_method(D_METHOD("create_item", "parent", "index"), &Tree::create_item, DEFVAL(Variant()), DEFVAL(-1)); ClassDB::bind_method(D_METHOD("create_item", "parent", "index"), &Tree::create_item, DEFVAL(Variant()), DEFVAL(-1));
@ -5326,10 +5334,14 @@ void Tree::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_allow_reselect", "allow"), &Tree::set_allow_reselect); 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("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::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, "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_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_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_folding"), "set_hide_folding", "is_folding_hidden");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enable_recursive_folding"), "set_enable_recursive_folding", "is_recursive_folding_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enable_recursive_folding"), "set_enable_recursive_folding", "is_recursive_folding_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hide_root"), "set_hide_root", "is_root_hidden"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hide_root"), "set_hide_root", "is_root_hidden");

View File

@ -625,6 +625,7 @@ private:
bool scrolling = false; bool scrolling = false;
bool allow_reselect = false; bool allow_reselect = false;
bool allow_search = true;
bool force_edit_checkbox_only_on_checkbox = false; bool force_edit_checkbox_only_on_checkbox = false;
@ -753,6 +754,9 @@ public:
void set_allow_reselect(bool p_allow); void set_allow_reselect(bool p_allow);
bool get_allow_reselect() const; bool get_allow_reselect() const;
void set_allow_search(bool p_allow);
bool get_allow_search() const;
Size2 get_minimum_size() const override; Size2 get_minimum_size() const override;
Tree(); Tree();