Skip to content

Commit bb5efba

Browse files
committed
Add text input focus toggle to input_text test
Expose glfwSetTextInputFocus in the input_text test so IME and text input focus behavior can be exercised independently. The UI starts in compatibility mode, then shows explicit Focus In or Focus Out after the toggle is used.
1 parent a4c663d commit bb5efba

1 file changed

Lines changed: 39 additions & 2 deletions

File tree

tests/input_text.c

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ static int fontNum = 0;
112112
static int currentFontIndex = 0;
113113

114114
static int currentIMEStatus = GLFW_FALSE;
115+
enum text_input_focus_status
116+
{
117+
TEXT_INPUT_FOCUS_COMPATIBLE,
118+
TEXT_INPUT_FOCUS_IN,
119+
TEXT_INPUT_FOCUS_OUT
120+
};
121+
static enum text_input_focus_status currentTextInputFocusStatus =
122+
TEXT_INPUT_FOCUS_COMPATIBLE;
115123
#define MAX_PREEDIT_LEN 128
116124
static char preeditBuf[MAX_PREEDIT_LEN] = "";
117125

@@ -510,13 +518,27 @@ static int set_font_selecter(GLFWwindow* window, struct nk_context* nk, int heig
510518

511519
static void set_ime_buttons(GLFWwindow* window, struct nk_context* nk, int height)
512520
{
513-
nk_layout_row_dynamic(nk, height, 2);
521+
nk_layout_row_dynamic(nk, height, 3);
514522

515523
if (nk_button_label(nk, "Toggle IME status"))
516524
{
517525
glfwSetInputMode(window, GLFW_IME, !currentIMEStatus);
518526
}
519527

528+
if (nk_button_label(nk, "Toggle text input focus"))
529+
{
530+
if (currentTextInputFocusStatus == TEXT_INPUT_FOCUS_IN)
531+
{
532+
glfwSetTextInputFocus(window, GLFW_FALSE);
533+
currentTextInputFocusStatus = TEXT_INPUT_FOCUS_OUT;
534+
}
535+
else
536+
{
537+
glfwSetTextInputFocus(window, GLFW_TRUE);
538+
currentTextInputFocusStatus = TEXT_INPUT_FOCUS_IN;
539+
}
540+
}
541+
520542
if (nk_button_label(nk, "Reset preedit text"))
521543
{
522544
glfwResetPreeditText(window);
@@ -615,8 +637,23 @@ static void set_preedit_cursor_edit(GLFWwindow* window, struct nk_context* nk, i
615637

616638
static void set_ime_stauts_labels(GLFWwindow* window, struct nk_context* nk, int height)
617639
{
618-
nk_layout_row_dynamic(nk, height, 1);
640+
const char* textInputFocusStatus = "Text input focus: compatible";
641+
642+
switch (currentTextInputFocusStatus)
643+
{
644+
case TEXT_INPUT_FOCUS_IN:
645+
textInputFocusStatus = "Text input focus: Focus In";
646+
break;
647+
case TEXT_INPUT_FOCUS_OUT:
648+
textInputFocusStatus = "Text input focus: Focus Out";
649+
break;
650+
case TEXT_INPUT_FOCUS_COMPATIBLE:
651+
break;
652+
}
653+
654+
nk_layout_row_dynamic(nk, height, 2);
619655
nk_value_bool(nk, "IME status", currentIMEStatus);
656+
nk_label(nk, textInputFocusStatus, NK_TEXT_LEFT);
620657
}
621658

622659
static void set_preedit_labels(GLFWwindow* window, struct nk_context* nk, int height)

0 commit comments

Comments
 (0)