Make TreeSearch::_select_item consistent

This commit is contained in:
Alexander Montag 2024-09-26 15:36:59 +00:00
parent af15dde4c8
commit 0fc11bf05b
2 changed files with 16 additions and 12 deletions

View File

@ -35,6 +35,7 @@
#include <godot_cpp/classes/style_box_flat.hpp>
#include <godot_cpp/classes/viewport.hpp>
#include <godot_cpp/core/math.hpp>
#endif // LIMBOAI_GDEXTENSION
#define UPPER_BOUND (1 << 15) // for substring search.
@ -58,14 +59,16 @@ void TreeSearchPanel::_initialize_controls() {
this->set_anchors_and_offsets_preset(LayoutPreset::PRESET_BOTTOM_WIDE);
this->set_v_size_flags(SIZE_SHRINK_CENTER); // Do not expand vertically
// hack add separator to the left so line edit doesn't clip.
line_edit_search->set_h_size_flags(SIZE_EXPAND_FILL);
_add_spacer(0.25); // otherwise the lineedits expand margin touches the left border.
add_child(line_edit_search);
_add_spacer(0.25);
add_child(check_button_filter_highlight);
add_child(label_filter);
_add_spacer();
_add_spacer(0.25);
add_child(close_button);
_add_spacer(0.25);
}
@ -86,7 +89,7 @@ void TreeSearchPanel::_emit_text_submitted(const String &p_text) {
this->emit_signal("text_submitted");
}
void TreeSearchPanel::_emit_update_requested(){
void TreeSearchPanel::_emit_update_requested() {
emit_signal("update_requested");
}
@ -364,18 +367,21 @@ TreeSearch::StringSearchIndices TreeSearch::_substring_bounds(const String &p_se
void TreeSearch::_select_item(TreeItem *p_item) {
if (!p_item)
return;
tree_reference->set_selected(p_item, 0);
// first unfold ancestors
TreeItem * ancestor = p_item->get_parent();
TreeItem *ancestor = p_item->get_parent();
ancestor = ancestor->get_parent();
while (ancestor) {
ancestor->set_collapsed(false);
ancestor = ancestor->get_parent();
}
// then scroll to [item]
//then scroll to [item]
tree_reference->scroll_to_item(p_item);
// ...and select it
tree_reference->deselect_all();
tree_reference->set_selected(p_item, 0);
}
void TreeSearch::_select_first_match() {

View File

@ -95,7 +95,6 @@ private:
void _update_ordered_tree_items(TreeItem *p_tree_item);
void _update_number_matches();
Vector<TreeItem *> _find_matching_entries(TreeItem *p_tree_item, const String &p_search_mask, Vector<TreeItem *> &p_buffer);
StringSearchIndices _substring_bounds(const String &p_searchable, const String &p_search_mask) const;
@ -103,8 +102,9 @@ private:
void _select_first_match();
void _select_next_match();
template<typename T>
bool _vector_has_bsearch(Vector<T*> p_vec, T* element);
template <typename T>
bool _vector_has_bsearch(Vector<T *> p_vec, T *element);
protected:
static void _bind_methods() {}
@ -119,5 +119,3 @@ public:
#endif // TREE_SEARCH_H
#endif // ! TOOLS_ENABLED