From 454637f0a10c49ace5286d8c379e5270dd0297e4 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 12 Aug 2024 22:00:22 +1000 Subject: [PATCH] Virtual keyboard: Push slightly upwards to avoid overlapping chat --- src/Screens.c | 1 + src/VirtualKeyboard.h | 4 +++- src/Window.h | 12 +++++++++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Screens.c b/src/Screens.c index a3f37089b..a5e84925e 100644 --- a/src/Screens.c +++ b/src/Screens.c @@ -1551,6 +1551,7 @@ void ChatScreen_OpenInput(const cc_string* text) { OpenKeyboardArgs_Init(&args, text, KEYBOARD_TYPE_TEXT | KEYBOARD_FLAG_SEND); args.placeholder = "Enter chat"; args.multiline = true; + args.yOffset = 30; OnscreenKeyboard_Open(&args); Widget_SetDisabled(&s->input.base, args.opaque); diff --git a/src/VirtualKeyboard.h b/src/VirtualKeyboard.h index c33a7ae0d..557cb624a 100644 --- a/src/VirtualKeyboard.h +++ b/src/VirtualKeyboard.h @@ -18,6 +18,7 @@ static float kb_padXAcc, kb_padYAcc; static char kb_buffer[512]; static cc_string kb_str = String_FromArray(kb_buffer); static void (*KB_MarkDirty)(void); +static int kb_yOffset; #define KB_TILE_SIZE 32 static int kb_tileWidth = KB_TILE_SIZE; @@ -173,7 +174,7 @@ static void VirtualKeyboard_Draw(struct Context2D* ctx) { static void VirtualKeyboard_CalcPosition(int* x, int* y, int width, int height) { /* Draw virtual keyboard at centre of window bottom */ - *y = height - 1 - VirtualKeyboard_Height(); + *y = height - 1 - VirtualKeyboard_Height() - kb_yOffset; if (*y < 0) *y = 0; *x = (width - VirtualKeyboard_Width()) / 2; @@ -410,6 +411,7 @@ static void VirtualKeyboard_Open(struct OpenKeyboardArgs* args, cc_bool launcher kb_padXAcc = 0; kb_padYAcc = 0; kb_shift = false; + kb_yOffset = args->yOffset; int mode = args->type & 0xFF; int num = mode == KEYBOARD_TYPE_INTEGER || mode == KEYBOARD_TYPE_NUMBER; diff --git a/src/Window.h b/src/Window.h index c5eea13a6..0785ba51e 100644 --- a/src/Window.h +++ b/src/Window.h @@ -201,10 +201,16 @@ void Window_DrawFramebuffer(Rect2D r, struct Bitmap* bmp); /* Frees the previously allocated framebuffer. */ void Window_FreeFramebuffer(struct Bitmap* bmp); -struct OpenKeyboardArgs { const cc_string* text; int type; const char* placeholder; cc_bool opaque, multiline; }; +struct OpenKeyboardArgs { + const cc_string* text; + int type, yOffset; + const char* placeholder; + cc_bool opaque, multiline; +}; static CC_INLINE void OpenKeyboardArgs_Init(struct OpenKeyboardArgs* args, STRING_REF const cc_string* text, int type) { - args->text = text; - args->type = type; + args->text = text; + args->type = type; + args->yOffset = 0; args->placeholder = ""; args->opaque = false; args->multiline = false;