Compare commits

..

1 Commits

Author SHA1 Message Date
monxa 0c30414258
Merge 8d29f16963 into 134bb3214a 2024-09-25 20:19:33 +02:00
3 changed files with 40 additions and 32 deletions

View File

@ -533,8 +533,10 @@ void TaskTree::_notification(int p_what) {
tree->connect("multi_selected", callable_mp(this, &TaskTree::_on_item_selected).unbind(3), CONNECT_DEFERRED);
tree->connect("item_activated", callable_mp(this, &TaskTree::_on_item_activated));
tree->connect("item_collapsed", callable_mp(this, &TaskTree::_on_item_collapsed));
tree_search->search_panel->connect("update_requested", callable_mp(this, &TaskTree::_update_tree));
// TODO: Simplify these signals into one (candidate names: changed, updated, update_requested):
tree_search->search_panel->connect("text_changed", callable_mp(this, &TaskTree::_update_tree).unbind(1));
tree_search->search_panel->connect("visibility_changed", callable_mp(this, &TaskTree::_update_tree));
tree_search->search_panel->connect("filter_toggled", callable_mp(this, &TaskTree::_update_tree));
} break;
case NOTIFICATION_THEME_CHANGED: {
_do_update_theme_item_cache();

View File

@ -82,30 +82,35 @@ void TreeSearchPanel::_add_spacer(float p_width_multiplier) {
add_child(spacer);
}
void TreeSearchPanel::_emit_text_changed(const String &p_text) {
this->emit_signal("text_changed", p_text);
}
void TreeSearchPanel::_emit_text_submitted(const String &p_text) {
this->emit_signal("text_submitted");
}
void TreeSearchPanel::_emit_update_requested(){
emit_signal("update_requested");
void TreeSearchPanel::_emit_filter_toggled() {
this->emit_signal("filter_toggled");
}
void TreeSearchPanel::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_READY: {
_initialize_controls();
line_edit_search->connect("text_changed", callable_mp(this, &TreeSearchPanel::_emit_update_requested).unbind(1));
line_edit_search->connect("text_changed", callable_mp(this, &TreeSearchPanel::_emit_text_changed));
_initialize_close_callbacks();
line_edit_search->connect("text_submitted", callable_mp(this, &TreeSearchPanel::_emit_text_submitted));
check_button_filter_highlight->connect("pressed", callable_mp(this, &TreeSearchPanel::_emit_update_requested));
check_button_filter_highlight->connect("pressed", callable_mp(this, &TreeSearchPanel::_emit_filter_toggled));
break;
}
}
}
void TreeSearchPanel::_bind_methods() {
ADD_SIGNAL(MethodInfo("update_requested"));
ADD_SIGNAL(MethodInfo("text_changed"));
ADD_SIGNAL(MethodInfo("text_submitted"));
ADD_SIGNAL(MethodInfo("filter_toggled"));
}
TreeSearchPanel::TreeSearchPanel() {
@ -168,6 +173,7 @@ void TreeSearch::_highlight_tree(const String &p_search_mask) {
int num_m = number_matches.has(entry) ? number_matches.get(entry) : 0;
if (num_m == 0) {
continue;
;
}
// make sure to also call any draw method already defined.
@ -211,7 +217,7 @@ void TreeSearch::_draw_highlight_item(TreeItem *p_tree_item, Rect2 p_rect, Strin
font = p_tree_item->get_tree()->get_theme_font(LW_NAME(font));
}
ERR_FAIL_NULL(font);
float font_size = p_tree_item->get_custom_font_size(0);
double font_size = p_tree_item->get_custom_font_size(0);
if (font_size == -1) {
font_size = p_tree_item->get_tree()->get_theme_font_size(LW_NAME(font));
}
@ -267,9 +273,9 @@ void TreeSearch::_draw_highlight_item(TreeItem *p_tree_item, Rect2 p_rect, Strin
}
}
void TreeSearch::_update_matching_entries(const String &p_search_mask) {
void TreeSearch::_update_matching_entries(const String &search_mask) {
Vector<TreeItem *> accum;
matching_entries = _find_matching_entries(tree_reference->get_root(), p_search_mask, accum);
matching_entries = _find_matching_entries(tree_reference->get_root(), search_mask, accum);
}
/* this linearizes the tree into [ordered_tree_items] like so:
@ -361,21 +367,16 @@ TreeSearch::StringSearchIndices TreeSearch::_substring_bounds(const String &p_se
return result;
}
void TreeSearch::_select_item(TreeItem *p_item) {
if (!p_item)
void TreeSearch::_select_item(TreeItem *item) {
if (!item)
return;
tree_reference->set_selected(p_item, 0);
// first unfold ancestors
TreeItem * ancestor = p_item->get_parent();
ancestor = ancestor->get_parent();
while (ancestor) {
ancestor->set_collapsed(false);
ancestor = ancestor->get_parent();
tree_reference->set_selected(item, 0);
tree_reference->scroll_to_item(item);
item = item->get_parent();
while (item) {
item->set_collapsed(false);
item = item->get_parent();
}
// then scroll to [item]
tree_reference->scroll_to_item(p_item);
}
void TreeSearch::_select_first_match() {
@ -476,6 +477,9 @@ TreeSearch::TreeSearch() {
search_panel = memnew(TreeSearchPanel);
}
TreeSearch::~TreeSearch() {
}
/* !TreeSearch */
#endif // TOOLS_ENABLED

View File

@ -52,9 +52,10 @@ private:
void _initialize_close_callbacks();
void _add_spacer(float width_multiplier = 1.f);
void _on_draw_highlight(TreeItem *p_item, Rect2 p_rect);
void _on_draw_highlight(TreeItem *item, Rect2 rect);
void _emit_text_changed(const String &text);
void _emit_text_submitted(const String &p_text);
void _emit_update_requested();
void _emit_filter_toggled();
void _notification(int p_what);
protected:
@ -90,16 +91,16 @@ private:
void _filter_tree(const String &p_search_mask);
void _highlight_tree(const String &p_search_mask);
void _draw_highlight_item(TreeItem *p_tree_item, Rect2 p_rect, String p_search_mask, Callable p_parent_draw_method);
void _update_matching_entries(const String &p_search_mask);
void _update_ordered_tree_items(TreeItem *p_tree_item);
void _draw_highlight_item(TreeItem *tree_item, Rect2 rect, String search_mask, Callable parent_draw_method);
void _update_matching_entries(const String &search_mask);
void _update_ordered_tree_items(TreeItem *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;
Vector<TreeItem *> _find_matching_entries(TreeItem *tree_item, const String &search_mask, Vector<TreeItem *> &buffer);
StringSearchIndices _substring_bounds(const String &searchable, const String &search_mask) const;
void _select_item(TreeItem *p_item);
void _select_item(TreeItem *item);
void _select_first_match();
void _select_next_match();
@ -110,11 +111,12 @@ protected:
public:
// we will add everything from TaskTree.h
void update_search(Tree *p_tree);
void on_item_edited(TreeItem *p_item);
void update_search(Tree *tree);
void on_item_edited(TreeItem *item);
TreeSearchPanel *search_panel;
TreeSearch();
~TreeSearch();
};
#endif // TREE_SEARCH_H