Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Fix TouchActionsPanel hiding behind virtual keyboard when in portrait

Anish Kumarda4a65a3653b
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index c3e10f6e373..b2174f134fc 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -975,6 +975,16 @@ void EditorNode::_notification(int p_what) {
EditorSettings::get_singleton()->emit_signal(SNAME("settings_changed"));
settings_overrides_changed = false;
}
+
+#ifdef ANDROID_ENABLED
+ if (portrait_mode) {
+ const int vk_height = DisplayServer::get_singleton()->virtual_keyboard_get_height();
+ if (vk_height != last_vk_height) {
+ last_vk_height = vk_height;
+ vk_spacer->set_custom_minimum_size(Size2(0, vk_height));
+ }
+ }
+#endif
} break;
case NOTIFICATION_ENTER_TREE: {
@@ -1003,6 +1013,7 @@ void EditorNode::_notification(int p_what) {
if (is_fullscreen) {
DisplayServer::get_singleton()->window_set_mode(DisplayServerEnums::WINDOW_MODE_FULLSCREEN);
}
+ DisplayServer::get_singleton()->connect("orientation_changed", callable_mp(this, &EditorNode::_screen_orientation_changed));
#endif
get_tree()->get_root()->connect("files_dropped", callable_mp(this, &EditorNode::_dropped_files));
@@ -8459,6 +8470,11 @@ void EditorNode::_touch_actions_panel_mode_changed() {
break;
}
}
+
+void EditorNode::_screen_orientation_changed(int p_new_orientation) {
+ portrait_mode = p_new_orientation == DisplayServerEnums::SENSOR_ORIENTATION_PORTRAIT;
+ vk_spacer->set_custom_minimum_size(Size2()); // Reset size.
+}
#endif
#ifdef MACOS_ENABLED
@@ -8847,6 +8863,9 @@ EditorNode::EditorNode() {
_touch_actions_panel_mode_changed();
+ vk_spacer = memnew(Control);
+ base_vbox->add_child(vk_spacer);
+
gui_base->add_child(base_vbox);
#else
gui_base->add_child(main_vbox);
diff --git a/editor/editor_node.h b/editor/editor_node.h
index 2a95f25af56..f943b00d4b9 100644
--- a/editor/editor_node.h
+++ b/editor/editor_node.h
@@ -299,12 +299,18 @@ private:
OptionButton *renderer = nullptr;
#ifdef ANDROID_ENABLED
- VBoxContainer *base_vbox = nullptr; // It only contains the title_bar and main_box.
+ VBoxContainer *base_vbox = nullptr; // It only contains the title_bar, main_box, and vk_spacer.
BoxContainer *main_box = nullptr; // It only contains the touch_actions_panel and main_vbox.
TouchActionsPanel *touch_actions_panel = nullptr;
void _touch_actions_panel_mode_changed();
+
+ Control *vk_spacer = nullptr;
+ int last_vk_height = -1;
+ void _screen_orientation_changed(int p_new_orientation);
#endif
+ bool portrait_mode = false;
+
ConfirmationDialog *video_restart_dialog = nullptr;
// Split containers.
@@ -1069,6 +1075,8 @@ public:
bool validate_custom_directory();
void run_editor_script(const Ref<Script> &p_script);
bool is_scene_unsaved(int p_idx);
+
+ bool is_portrait() const { return portrait_mode; }
};
struct EditorProgressBG {
diff --git a/editor/script/script_editor_plugin.cpp b/editor/script/script_editor_plugin.cpp
index c9bfb139298..76147c73e8e 100644
--- a/editor/script/script_editor_plugin.cpp
+++ b/editor/script/script_editor_plugin.cpp
@@ -2200,6 +2200,10 @@ void DocumentEditorContainer::_notification(int p_what) {
} break;
case NOTIFICATION_PROCESS: {
+ if (!is_visible()) {
+ break;
+ }
+
const int kb_height = DisplayServer::get_singleton()->virtual_keyboard_get_height();
if (kb_height == last_kb_height) {
break;
@@ -2207,32 +2211,30 @@ void DocumentEditorContainer::_notification(int p_what) {
last_kb_height = kb_height;
float spacer_height = 0.0f;
- const float status_bar_height = 28 * EDSCALE; // Magic number
- const bool kb_visible = kb_height > 0;
-
- if (kb_visible) {
- if (TextEditorBase *editor = Object::cast_to<TextEditorBase>(_get_current_editor())) {
- if (CodeTextEditor *code_editor = editor->get_code_editor()) {
- if (CodeEdit *text_editor = code_editor->get_text_editor()) {
- if (!text_editor->has_focus()) {
- break;
- }
- text_editor->adjust_viewport_to_caret();
- }
- }
- }
+ if (EditorNode::get_singleton()->is_portrait()) {
+ // Reset virtual_keyboard_spacer and let EditorNode handle resizing in portrait mode.
+ virtual_keyboard_spacer->set_custom_minimum_size(Size2());
+ } else {
+ const float status_bar_height = 28 * EDSCALE;
const float control_bottom = get_global_position().y + get_size().y;
const float extra_bottom = get_viewport_rect().size.y - control_bottom;
spacer_height = float(kb_height) - extra_bottom - status_bar_height;
+ spacer_height = fmax(0, spacer_height);
+ virtual_keyboard_spacer->set_custom_minimum_size(Size2(0, spacer_height));
+ EditorSceneTabs::get_singleton()->set_visible(kb_height == 0);
+ }
- if (spacer_height < 0.0f) {
- spacer_height = 0.0f;
+ // Make sure caret is visible after resize.
+ if (TextEditorBase *editor = Object::cast_to<TextEditorBase>(_get_current_editor())) {
+ if (CodeTextEditor *code_editor = editor->get_code_editor()) {
+ if (CodeEdit *text_editor = code_editor->get_text_editor()) {
+ if (text_editor->has_focus()) {
+ text_editor->adjust_viewport_to_caret();
+ }
+ }
}
}
-
- virtual_keyboard_spacer->set_custom_minimum_size(Size2(0, spacer_height));
- EditorSceneTabs::get_singleton()->set_visible(!kb_visible);
} break;
#endif
case NOTIFICATION_APPLICATION_FOCUS_IN: {