Skip to content

Commit 7b7b61e

Browse files
committed
Add API: SetPreeditCallback
This is for GLFW3 Preedit Callback: glfwSetPreeditCallback
1 parent c2b56c5 commit 7b7b61e

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/raylib.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,14 @@ RLAPI unsigned char *DecodeDataBase64(const unsigned char *data, int *outputSize
10921092
//------------------------------------------------------------------------------------
10931093
// Input Handling Functions (Module: core)
10941094
//------------------------------------------------------------------------------------
1095+
// Callback for preedit text.
1096+
// preeditLength: The length of preedit text
1097+
// preeditString: The preedit text (unicode)
1098+
// blockCount: The number of all converting blocks
1099+
// blockSizes: The size of each converting block
1100+
// focusedBlock: The index of the current converting block
1101+
// caret: The index of the caret in preeditString
1102+
typedef void (*PreeditCallback)(int preeditLength, int *preeditString, int blockCount, int *blockSizes, int focusedBlock, int caret);
10951103

10961104
// Input-related functions: keyboard
10971105
RLAPI bool IsKeyPressed(int key); // Check if a key has been pressed once
@@ -1101,6 +1109,7 @@ RLAPI bool IsKeyUp(int key); // Check if a key
11011109
RLAPI void SetExitKey(int key); // Set a custom key to exit program (default is ESC)
11021110
RLAPI int GetKeyPressed(void); // Get key pressed (keycode), call it multiple times for keys queued, returns 0 when the queue is empty
11031111
RLAPI int GetCharPressed(void); // Get char pressed (unicode), call it multiple times for chars queued, returns 0 when the queue is empty
1112+
RLAPI void SetPreeditCallback(PreeditCallback callback); // Set a callback for preedit
11041113

11051114
// Input-related functions: gamepads
11061115
RLAPI bool IsGamepadAvailable(int gamepad); // Check if a gamepad is available

src/rcore.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,8 @@ typedef struct CoreData {
438438
int charPressedQueue[MAX_CHAR_PRESSED_QUEUE]; // Input characters queue (unicode)
439439
int charPressedQueueCount; // Input characters queue count
440440

441+
PreeditCallback preeditCallback; // Preedit callback
442+
441443
#if defined(PLATFORM_RPI) || defined(PLATFORM_DRM)
442444
int defaultMode; // Default keyboard mode
443445
#if defined(SUPPORT_SSH_KEYBOARD_RPI)
@@ -639,6 +641,7 @@ static void WindowDropCallback(GLFWwindow *window, int count, const char **paths
639641
// Input callbacks events
640642
static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods); // GLFW3 Keyboard Callback, runs on key pressed
641643
static void CharCallback(GLFWwindow *window, unsigned int key); // GLFW3 Char Key Callback, runs on key pressed (get char value)
644+
static void PreeditCallbackInner(GLFWwindow *window, int preeditLength, unsigned int *preeditString, int blockCount, int *blockSizes, int focusedBlock, int caret); // GLFW3 Preedit Callback
642645
static void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods); // GLFW3 Mouse Button Callback, runs on mouse button pressed
643646
static void MouseCursorPosCallback(GLFWwindow *window, double x, double y); // GLFW3 Cursor Position Callback, runs on mouse move
644647
static void MouseScrollCallback(GLFWwindow *window, double xoffset, double yoffset); // GLFW3 Srolling Callback, runs on mouse wheel
@@ -3548,6 +3551,12 @@ int GetCharPressed(void)
35483551
return value;
35493552
}
35503553

3554+
// Set a callback for preedit
3555+
void SetPreeditCallback(PreeditCallback callback)
3556+
{
3557+
CORE.Input.Keyboard.preeditCallback = callback;
3558+
}
3559+
35513560
// Set a custom key to exit program
35523561
// NOTE: default exitKey is ESCAPE
35533562
void SetExitKey(int key)
@@ -4144,6 +4153,7 @@ static bool InitGraphicsDevice(int width, int height)
41444153
// Set input callback events
41454154
glfwSetKeyCallback(CORE.Window.handle, KeyCallback);
41464155
glfwSetCharCallback(CORE.Window.handle, CharCallback);
4156+
glfwSetPreeditCallback(CORE.Window.handle, PreeditCallbackInner);
41474157
glfwSetMouseButtonCallback(CORE.Window.handle, MouseButtonCallback);
41484158
glfwSetCursorPosCallback(CORE.Window.handle, MouseCursorPosCallback); // Track mouse position changes
41494159
glfwSetScrollCallback(CORE.Window.handle, MouseScrollCallback);
@@ -5383,6 +5393,14 @@ static void CharCallback(GLFWwindow *window, unsigned int key)
53835393
}
53845394
}
53855395

5396+
// GLFW3 Preedit Callback
5397+
static void PreeditCallbackInner(GLFWwindow *window, int preeditLength, unsigned int *preeditString, int blockCount, int *blockSizes, int focusedBlock, int caret)
5398+
{
5399+
if (!CORE.Input.Keyboard.preeditCallback) return;
5400+
CORE.Input.Keyboard.preeditCallback(preeditLength, (int *)preeditString, blockCount, blockSizes, focusedBlock, caret);
5401+
}
5402+
5403+
53865404
// GLFW3 Mouse Button Callback, runs on mouse button pressed
53875405
static void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods)
53885406
{

0 commit comments

Comments
 (0)