Compare commits

..

2 Commits

Author SHA1 Message Date
Alexander Montag af15dde4c8 Simplify signals of TreeSearchPanel 2024-09-26 07:53:02 +02:00
Alexander Montag 1145ce0252 Clean up TreeSearch: Consistent p_params, -Destructor 2024-09-26 05:28:59 +00:00
3 changed files with 32 additions and 40 deletions

View File

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

View File

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

View File

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