mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
app,widget,io: implement IME positioning
This change implements reporting of the caret position from Editor, as well as Windows, macOS, Android support. As a result, the IME composition window on Windows and macOS is now positioned correctly. References: https://todo.sr.ht/~eliasnaur/gio/246 Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -12,8 +12,10 @@ package key
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"math"
|
||||
"strings"
|
||||
|
||||
"gioui.org/f32"
|
||||
"gioui.org/internal/ops"
|
||||
"gioui.org/io/event"
|
||||
"gioui.org/op"
|
||||
@@ -45,6 +47,7 @@ type FocusOp struct {
|
||||
type SelectionOp struct {
|
||||
Tag event.Tag
|
||||
Range
|
||||
Caret
|
||||
}
|
||||
|
||||
// SnippetOp updates the content snippet for an input handler.
|
||||
@@ -67,6 +70,16 @@ type Snippet struct {
|
||||
Text string
|
||||
}
|
||||
|
||||
// Caret represents the position of a caret.
|
||||
type Caret struct {
|
||||
// Pos is the intersection point of the caret and its baseline.
|
||||
Pos f32.Point
|
||||
// Ascent is the length of the caret above its baseline.
|
||||
Ascent float32
|
||||
// Descent is the length of the caret below its baseline.
|
||||
Descent float32
|
||||
}
|
||||
|
||||
// SelectionEvent is generated when an input method changes the selection.
|
||||
type SelectionEvent Range
|
||||
|
||||
@@ -229,6 +242,10 @@ func (s SelectionOp) Add(o *op.Ops) {
|
||||
bo := binary.LittleEndian
|
||||
bo.PutUint32(data[1:], uint32(s.Start))
|
||||
bo.PutUint32(data[5:], uint32(s.End))
|
||||
bo.PutUint32(data[9:], math.Float32bits(s.Pos.X))
|
||||
bo.PutUint32(data[13:], math.Float32bits(s.Pos.Y))
|
||||
bo.PutUint32(data[17:], math.Float32bits(s.Ascent))
|
||||
bo.PutUint32(data[21:], math.Float32bits(s.Descent))
|
||||
}
|
||||
|
||||
func (EditEvent) ImplementsEvent() {}
|
||||
|
||||
Reference in New Issue
Block a user