From 045f65827d880d212aa9b01616dd7c62f1b4f6c7 Mon Sep 17 00:00:00 2001 From: Q191 <83848311+Q191@users.noreply.github.com> Date: Fri, 10 Jul 2026 12:11:01 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E9=BC=A0=E6=A0=87=E8=B7=9F=E9=9A=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ime.v | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/ime.v b/ime.v index bb28eee..766a9fe 100644 --- a/ime.v +++ b/ime.v @@ -9,6 +9,43 @@ module gui import sokol.sapp import vglyph +#flag windows -limm32 +struct C.POINT { +mut: + x int + y int +} +struct C.COMPOSITIONFORM { +mut: + dwStyle u32 + ptCurrentPos C.POINT + rcArea voidptr +} +fn C.ImmGetContext(hwnd voidptr) voidptr +fn C.ImmSetCompositionWindow(himc voidptr, form &C.COMPOSITIONFORM) bool +fn C.ImmReleaseContext(hwnd voidptr, himc voidptr) bool +const cfs_point = u32(0x0002) +fn set_ime_position(hwnd voidptr, x int, y int) { + println([x, y]) + if hwnd == unsafe { nil } { + return + } + $if windows { + himc := C.ImmGetContext(hwnd) + if himc != unsafe { nil } { + mut windows_ime_form := C.COMPOSITIONFORM{ + dwStyle: cfs_point + ptCurrentPos: C.POINT{ + x: x + y: y + } + rcArea: unsafe { nil } + } + C.ImmSetCompositionWindow(himc, &windows_ime_form) + C.ImmReleaseContext(hwnd, himc) + } + } +} // IME holds per-window Input Method Editor state. // Created lazily because the native window is not ready during // init_fn. @@ -28,6 +65,12 @@ fn ime_create_overlay() voidptr { return unsafe { nil } } return vglyph.ime_overlay_create_auto(ns_window) + } $if windows { + hwnd := sapp.win32_get_hwnd() + if hwnd == unsafe { nil } { + return unsafe { nil } + } + return hwnd } $else { // Linux: vglyph stubs return nil (no overlay yet). return unsafe { nil } @@ -153,6 +196,11 @@ fn ime_get_offset(data voidptr) (f32, f32) { } mut w := unsafe { &Window(data) } shape := ime_focused_text_shape(w) or { return 0, 0 } + $if windows { + cx := shape.x + shape.padding_left() + cy := shape.y + shape.padding_top() + set_ime_position(w.ime.overlay, int(cx), int(cy)+5) + } return shape.x + shape.padding_left() + text_layout_render_offset_x(&shape, mut w), shape.y + shape.padding_top() } From 5e35d34e6d589f8812ecc5c2d7c0a5f62e7f52a1 Mon Sep 17 00:00:00 2001 From: Q191 <83848311+Q191@users.noreply.github.com> Date: Fri, 10 Jul 2026 12:11:56 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E9=BC=A0=E6=A0=87=E8=B7=9F=E9=9A=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- render_text.v | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/render_text.v b/render_text.v index bc85875..5d1cc28 100644 --- a/render_text.v +++ b/render_text.v @@ -458,7 +458,11 @@ fn render_cursor(shape &Shape, _ DrawClip, mut window Window) { rect.x cy := shape.y + shape.padding_top() + rect.y ch := rect.height - + $if windows { + if window.ime.overlay != unsafe { nil } { + set_ime_position(window.ime.overlay, int(cx), int(cy)+5) + } + } // Draw cursor line emit_renderer(DrawRect{ x: cx From 65acdad43a67268f940db8fd0fa34c13f2d16db5 Mon Sep 17 00:00:00 2001 From: Q191 <83848311+Q191@users.noreply.github.com> Date: Thu, 16 Jul 2026 09:59:51 +0800 Subject: [PATCH 3/7] Implement Windows IME support and overlay creation Added IME support for Windows, including functions to set the IME position and create an IME overlay. --- ime.windows.v | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 ime.windows.v diff --git a/ime.windows.v b/ime.windows.v new file mode 100644 index 0000000..165794a --- /dev/null +++ b/ime.windows.v @@ -0,0 +1,67 @@ +#flag windows -limm32 +struct C.POINT { +mut: + x int + y int +} +struct C.COMPOSITIONFORM { +mut: + dwStyle u32 + ptCurrentPos C.POINT + rcArea voidptr +} +fn C.ImmGetContext(hwnd voidptr) voidptr +fn C.ImmSetCompositionWindow(himc voidptr, form &C.COMPOSITIONFORM) bool +fn C.ImmReleaseContext(hwnd voidptr, himc voidptr) bool +const cfs_point = u32(0x0002) +fn set_ime_position(hwnd voidptr, x int, y int) { + println([x, y]) + if hwnd == unsafe { nil } { + return + } + $if windows { + himc := C.ImmGetContext(hwnd) + if himc != unsafe { nil } { + mut windows_ime_form := C.COMPOSITIONFORM{ + dwStyle: cfs_point + ptCurrentPos: C.POINT{ + x: x + y: y + } + rcArea: unsafe { nil } + } + C.ImmSetCompositionWindow(himc, &windows_ime_form) + C.ImmReleaseContext(hwnd, himc) + } + } +} +// IME holds per-window Input Method Editor state. +// Created lazily because the native window is not ready during +// init_fn. +struct IME { +mut: + overlay voidptr = unsafe { nil } + handler voidptr = unsafe { nil } + initialized bool +} + +// ime_create_overlay creates the platform-specific IME overlay. +// Returns nil on platforms without IME overlay support. +fn ime_create_overlay() voidptr { + $if macos { + ns_window := sapp.macos_get_window() + if ns_window == unsafe { nil } { + return unsafe { nil } + } + return vglyph.ime_overlay_create_auto(ns_window) + } $if windows { + hwnd := sapp.win32_get_hwnd() + if hwnd == unsafe { nil } { + return unsafe { nil } + } + return hwnd + } $else { + // Linux: vglyph stubs return nil (no overlay yet). + return unsafe { nil } + } +} From 039d3c76b5b049181457a0529f5c9a08692aaecd Mon Sep 17 00:00:00 2001 From: Q191 <83848311+Q191@users.noreply.github.com> Date: Thu, 16 Jul 2026 10:00:36 +0800 Subject: [PATCH 4/7] Remove Windows IME support and structures Removed Windows-specific IME implementation and related structures. --- ime.v | 68 ----------------------------------------------------------- 1 file changed, 68 deletions(-) diff --git a/ime.v b/ime.v index 766a9fe..f4009b9 100644 --- a/ime.v +++ b/ime.v @@ -9,74 +9,6 @@ module gui import sokol.sapp import vglyph -#flag windows -limm32 -struct C.POINT { -mut: - x int - y int -} -struct C.COMPOSITIONFORM { -mut: - dwStyle u32 - ptCurrentPos C.POINT - rcArea voidptr -} -fn C.ImmGetContext(hwnd voidptr) voidptr -fn C.ImmSetCompositionWindow(himc voidptr, form &C.COMPOSITIONFORM) bool -fn C.ImmReleaseContext(hwnd voidptr, himc voidptr) bool -const cfs_point = u32(0x0002) -fn set_ime_position(hwnd voidptr, x int, y int) { - println([x, y]) - if hwnd == unsafe { nil } { - return - } - $if windows { - himc := C.ImmGetContext(hwnd) - if himc != unsafe { nil } { - mut windows_ime_form := C.COMPOSITIONFORM{ - dwStyle: cfs_point - ptCurrentPos: C.POINT{ - x: x - y: y - } - rcArea: unsafe { nil } - } - C.ImmSetCompositionWindow(himc, &windows_ime_form) - C.ImmReleaseContext(hwnd, himc) - } - } -} -// IME holds per-window Input Method Editor state. -// Created lazily because the native window is not ready during -// init_fn. -struct IME { -mut: - overlay voidptr = unsafe { nil } - handler voidptr = unsafe { nil } - initialized bool -} - -// ime_create_overlay creates the platform-specific IME overlay. -// Returns nil on platforms without IME overlay support. -fn ime_create_overlay() voidptr { - $if macos { - ns_window := sapp.macos_get_window() - if ns_window == unsafe { nil } { - return unsafe { nil } - } - return vglyph.ime_overlay_create_auto(ns_window) - } $if windows { - hwnd := sapp.win32_get_hwnd() - if hwnd == unsafe { nil } { - return unsafe { nil } - } - return hwnd - } $else { - // Linux: vglyph stubs return nil (no overlay yet). - return unsafe { nil } - } -} - // init_ime lazily creates the IME overlay and registers // callbacks via VGlyph's StandardIMEHandler. fn (mut w Window) init_ime() { From c34b1e71d73fc38c0770100b9305af0490c3d348 Mon Sep 17 00:00:00 2001 From: Q191 <83848311+Q191@users.noreply.github.com> Date: Thu, 16 Jul 2026 10:02:55 +0800 Subject: [PATCH 5/7] Update ime.windows.v --- ime.windows.v | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/ime.windows.v b/ime.windows.v index 165794a..240f8ca 100644 --- a/ime.windows.v +++ b/ime.windows.v @@ -35,33 +35,3 @@ fn set_ime_position(hwnd voidptr, x int, y int) { } } } -// IME holds per-window Input Method Editor state. -// Created lazily because the native window is not ready during -// init_fn. -struct IME { -mut: - overlay voidptr = unsafe { nil } - handler voidptr = unsafe { nil } - initialized bool -} - -// ime_create_overlay creates the platform-specific IME overlay. -// Returns nil on platforms without IME overlay support. -fn ime_create_overlay() voidptr { - $if macos { - ns_window := sapp.macos_get_window() - if ns_window == unsafe { nil } { - return unsafe { nil } - } - return vglyph.ime_overlay_create_auto(ns_window) - } $if windows { - hwnd := sapp.win32_get_hwnd() - if hwnd == unsafe { nil } { - return unsafe { nil } - } - return hwnd - } $else { - // Linux: vglyph stubs return nil (no overlay yet). - return unsafe { nil } - } -} From 47959836705423950c128ae9d3b104d7ad8c9cec Mon Sep 17 00:00:00 2001 From: Q191 <83848311+Q191@users.noreply.github.com> Date: Thu, 16 Jul 2026 10:03:22 +0800 Subject: [PATCH 6/7] Update ime.v --- ime.v | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/ime.v b/ime.v index f4009b9..9041f0f 100644 --- a/ime.v +++ b/ime.v @@ -9,6 +9,37 @@ module gui import sokol.sapp import vglyph +// IME holds per-window Input Method Editor state. +// Created lazily because the native window is not ready during +// init_fn. +struct IME { +mut: + overlay voidptr = unsafe { nil } + handler voidptr = unsafe { nil } + initialized bool +} + +// ime_create_overlay creates the platform-specific IME overlay. +// Returns nil on platforms without IME overlay support. +fn ime_create_overlay() voidptr { + $if macos { + ns_window := sapp.macos_get_window() + if ns_window == unsafe { nil } { + return unsafe { nil } + } + return vglyph.ime_overlay_create_auto(ns_window) + } $if windows { + hwnd := sapp.win32_get_hwnd() + if hwnd == unsafe { nil } { + return unsafe { nil } + } + return hwnd + } $else { + // Linux: vglyph stubs return nil (no overlay yet). + return unsafe { nil } + } +} + // init_ime lazily creates the IME overlay and registers // callbacks via VGlyph's StandardIMEHandler. fn (mut w Window) init_ime() { From c459370d381076c99dc6b3b7857c84419e576fab Mon Sep 17 00:00:00 2001 From: Q191 <83848311+Q191@users.noreply.github.com> Date: Thu, 16 Jul 2026 10:16:47 +0800 Subject: [PATCH 7/7] Add gui module to ime.windows.v --- ime.windows.v | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ime.windows.v b/ime.windows.v index 240f8ca..f3b7cff 100644 --- a/ime.windows.v +++ b/ime.windows.v @@ -1,3 +1,5 @@ +module gui + #flag windows -limm32 struct C.POINT { mut: