diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-11-22 16:22:57 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-22 16:22:57 +0100 |
commit | 76aa1d0a433441e9bd863e1f489e9905c545f630 (patch) | |
tree | a5b299f1bd5bbeee6bf717ae5a02f28977f04af5 /scene/gui | |
parent | 8daf0cc49c4bab8dd039ced214e527b21708661e (diff) | |
parent | eabf8f5edf6dc3346bd6a6e771e382f1a20a5c29 (diff) |
Merge pull request #55151 from Chaosus/control_reset_size
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/control.cpp | 5 | ||||
-rw-r--r-- | scene/gui/control.h | 1 | ||||
-rw-r--r-- | scene/gui/line_edit.cpp | 4 | ||||
-rw-r--r-- | scene/gui/text_edit.cpp | 4 |
4 files changed, 10 insertions, 4 deletions
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index fdf10e2f42..9f715be155 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -1825,6 +1825,10 @@ Size2 Control::get_size() const { return data.size_cache; } +void Control::reset_size() { + set_size(Size2()); +} + Rect2 Control::get_global_rect() const { return Rect2(get_global_position(), get_size()); } @@ -2845,6 +2849,7 @@ void Control::_bind_methods() { ClassDB::bind_method(D_METHOD("set_position", "position", "keep_offsets"), &Control::set_position, DEFVAL(false)); ClassDB::bind_method(D_METHOD("_set_position", "position"), &Control::_set_position); ClassDB::bind_method(D_METHOD("set_size", "size", "keep_offsets"), &Control::set_size, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("reset_size"), &Control::reset_size); ClassDB::bind_method(D_METHOD("_set_size", "size"), &Control::_set_size); ClassDB::bind_method(D_METHOD("set_custom_minimum_size", "size"), &Control::set_custom_minimum_size); ClassDB::bind_method(D_METHOD("set_global_position", "position", "keep_offsets"), &Control::set_global_position, DEFVAL(false)); diff --git a/scene/gui/control.h b/scene/gui/control.h index 2eb714eae6..1a94cc68a6 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -401,6 +401,7 @@ public: void set_size(const Size2 &p_size, bool p_keep_offsets = false); Size2 get_size() const; + void reset_size(); Rect2 get_rect() const; Rect2 get_global_rect() const; diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 4a85cf2c45..69b08fda3c 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -228,7 +228,7 @@ void LineEdit::gui_input(const Ref<InputEvent> &p_event) { if (b->is_pressed() && b->get_button_index() == MouseButton::RIGHT && context_menu_enabled) { _ensure_menu(); menu->set_position(get_screen_transform().xform(get_local_mouse_position())); - menu->set_size(Vector2(1, 1)); + menu->reset_size(); menu->popup(); grab_focus(); accept_event(); @@ -393,7 +393,7 @@ void LineEdit::gui_input(const Ref<InputEvent> &p_event) { _ensure_menu(); Point2 pos = Point2(get_caret_pixel_pos().x, (get_size().y + get_theme_font(SNAME("font"))->get_height(get_theme_font_size(SNAME("font_size")))) / 2); menu->set_position(get_global_transform().xform(pos)); - menu->set_size(Vector2(1, 1)); + menu->reset_size(); menu->popup(); menu->grab_focus(); } diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index ad1790f61d..c8f6ecdafd 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -1595,7 +1595,7 @@ void TextEdit::gui_input(const Ref<InputEvent> &p_gui_input) { _generate_context_menu(); menu->set_position(get_screen_transform().xform(mpos)); - menu->set_size(Vector2(1, 1)); + menu->reset_size(); menu->popup(); grab_focus(); } @@ -1828,7 +1828,7 @@ void TextEdit::gui_input(const Ref<InputEvent> &p_gui_input) { _generate_context_menu(); adjust_viewport_to_caret(); menu->set_position(get_screen_transform().xform(get_caret_draw_pos())); - menu->set_size(Vector2(1, 1)); + menu->reset_size(); menu->popup(); menu->grab_focus(); } |