@@ -112,6 +112,14 @@ static int fontNum = 0;
112112static int currentFontIndex = 0 ;
113113
114114static 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
116124static char preeditBuf [MAX_PREEDIT_LEN ] = "" ;
117125
@@ -510,13 +518,27 @@ static int set_font_selecter(GLFWwindow* window, struct nk_context* nk, int heig
510518
511519static 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
616638static 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
622659static void set_preedit_labels (GLFWwindow * window , struct nk_context * nk , int height )
0 commit comments