From dd1372b78e8182c1f15c7e113a7ffc75b75f8ef3 Mon Sep 17 00:00:00 2001 From: rune-scape Date: Mon, 17 Jun 2024 18:43:02 -0700 Subject: [PATCH] various gui nodes now listen for the changed signal on textures --- scene/gui/line_edit.cpp | 16 ++++++++++++++++ scene/gui/line_edit.h | 1 + scene/gui/texture_button.cpp | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 99678051346..bbba4425ffa 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -2482,11 +2482,27 @@ bool LineEdit::is_drag_and_drop_selection_enabled() const { return drag_and_drop_selection_enabled; } +void LineEdit::_texture_changed() { + _fit_to_width(); + update_minimum_size(); + queue_redraw(); +} + void LineEdit::set_right_icon(const Ref &p_icon) { if (right_icon == p_icon) { return; } + + if (right_icon.is_valid()) { + right_icon->disconnect_changed(callable_mp(this, &LineEdit::_texture_changed)); + } + right_icon = p_icon; + + if (right_icon.is_valid()) { + right_icon->connect_changed(callable_mp(this, &LineEdit::_texture_changed)); + } + _fit_to_width(); update_minimum_size(); queue_redraw(); diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h index 9253dd87119..f7d017ab033 100644 --- a/scene/gui/line_edit.h +++ b/scene/gui/line_edit.h @@ -248,6 +248,7 @@ private: void _move_caret_end(bool p_select); void _backspace(bool p_word = false, bool p_all_to_left = false); void _delete(bool p_word = false, bool p_all_to_right = false); + void _texture_changed(); protected: bool _is_over_clear_button(const Point2 &p_pos) const; diff --git a/scene/gui/texture_button.cpp b/scene/gui/texture_button.cpp index 47bb0643b37..392bb50ead9 100644 --- a/scene/gui/texture_button.cpp +++ b/scene/gui/texture_button.cpp @@ -343,7 +343,7 @@ Ref TextureButton::get_texture_focused() const { } void TextureButton::set_texture_focused(const Ref &p_focused) { - focused = p_focused; + _set_texture(&focused, p_focused); } void TextureButton::_set_texture(Ref *p_destination, const Ref &p_texture) {