app: [android] fix insets

Previously, the Inset could be report wrongly when the bottom inset
is smaller than the top.

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
This commit is contained in:
Inkeliz
2022-07-29 01:25:35 +01:00
committed by Elias Naur
parent 61b2e37691
commit 65a4366e44
+15 -6
View File
@@ -154,7 +154,7 @@ type window struct {
dpi int
fontScale float32
insets image.Rectangle
insets pixelInsets
stage system.Stage
started bool
@@ -195,6 +195,10 @@ var gioView struct {
updateCaret C.jmethodID
}
type pixelInsets struct {
top, bottom, left, right int
}
// ViewEvent is sent whenever the Window's underlying Android view
// changes.
type ViewEvent struct {
@@ -586,7 +590,12 @@ func Java_org_gioui_GioView_onFocusChange(env *C.JNIEnv, class C.jclass, view C.
//export Java_org_gioui_GioView_onWindowInsets
func Java_org_gioui_GioView_onWindowInsets(env *C.JNIEnv, class C.jclass, view C.jlong, top, right, bottom, left C.jint) {
w := cgo.Handle(view).Value().(*window)
w.insets = image.Rect(int(left), int(top), int(right), int(bottom))
w.insets = pixelInsets{
top: int(top),
bottom: int(bottom),
left: int(left),
right: int(right),
}
if w.stage >= system.StageRunning {
w.draw(env, true)
}
@@ -827,10 +836,10 @@ func (w *window) draw(env *C.JNIEnv, sync bool) {
ppdp := float32(w.dpi) * inchPrDp
dppp := unit.Dp(1.0 / ppdp)
insets := system.Insets{
Top: unit.Dp(w.insets.Min.Y) * dppp,
Bottom: unit.Dp(w.insets.Max.Y) * dppp,
Left: unit.Dp(w.insets.Min.X) * dppp,
Right: unit.Dp(w.insets.Max.X) * dppp,
Top: unit.Dp(w.insets.top) * dppp,
Bottom: unit.Dp(w.insets.bottom) * dppp,
Left: unit.Dp(w.insets.left) * dppp,
Right: unit.Dp(w.insets.right) * dppp,
}
w.callbacks.Event(frameEvent{
FrameEvent: system.FrameEvent{