Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions ime.v
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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()
}
Expand Down
39 changes: 39 additions & 0 deletions ime.windows.v
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
6 changes: 5 additions & 1 deletion render_text.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down