diff --git a/ime.v b/ime.v index bb28eee..9041f0f 100644 --- a/ime.v +++ b/ime.v @@ -28,6 +28,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 +159,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() } diff --git a/ime.windows.v b/ime.windows.v new file mode 100644 index 0000000..f3b7cff --- /dev/null +++ b/ime.windows.v @@ -0,0 +1,39 @@ +module gui + +#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) + } + } +} 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