1
0
mirror of https://github.com/godotengine/godot.git synced 2025-12-02 16:48:55 +00:00

Android Editor: Adjust script editor size for virtual keyboard

This commit is contained in:
Anish Kumar
2025-11-12 00:17:52 +05:30
parent b15a13eed3
commit e7bf3ec52d
2 changed files with 54 additions and 0 deletions

View File

@@ -1864,8 +1864,51 @@ void ScriptEditor::_notification(int p_what) {
EditorSettings::get_singleton()->connect("settings_changed", callable_mp(this, &ScriptEditor::_editor_settings_changed));
EditorFileSystem::get_singleton()->connect("filesystem_changed", callable_mp(this, &ScriptEditor::_filesystem_changed));
#ifdef ANDROID_ENABLED
set_process(true);
#endif
} break;
#ifdef ANDROID_ENABLED
case NOTIFICATION_VISIBILITY_CHANGED: {
set_process(is_visible_in_tree());
} break;
case NOTIFICATION_PROCESS: {
const int kb_height = DisplayServer::get_singleton()->virtual_keyboard_get_height();
if (kb_height == last_kb_height) {
break;
}
last_kb_height = kb_height;
float spacer_height = 0.0f;
const float status_bar_height = 28 * EDSCALE; // Magic number
if (kb_height > 0) {
if (ScriptEditorBase *editor = _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();
}
}
}
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;
if (spacer_height < 0.0f) {
spacer_height = 0.0f;
}
}
virtual_keyboard_spacer->set_custom_minimum_size(Size2(0, spacer_height));
} break;
#endif
case NOTIFICATION_EXIT_TREE: {
EditorRunBar::get_singleton()->disconnect("stop_pressed", callable_mp(this, &ScriptEditor::_editor_stop));
} break;
@@ -4187,6 +4230,12 @@ ScriptEditor::ScriptEditor(WindowWrapper *p_wrapper) {
main_container->add_child(script_split);
script_split->set_v_size_flags(SIZE_EXPAND_FILL);
#ifdef ANDROID_ENABLED
virtual_keyboard_spacer = memnew(Control);
virtual_keyboard_spacer->set_h_size_flags(SIZE_EXPAND_FILL);
main_container->add_child(virtual_keyboard_spacer);
#endif
list_split = memnew(VSplitContainer);
script_split->add_child(list_split);
list_split->set_v_size_flags(SIZE_EXPAND_FILL);