mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 10:25:37 +00:00
ui/app: introduce Insets for system decoration insets
Insets is like image.Rectangle, but with properly named fields and ui.Value instead of raw ints to make use with the layout package easier. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+8
-4
@@ -19,16 +19,20 @@ type Event interface {
|
|||||||
type DrawEvent struct {
|
type DrawEvent struct {
|
||||||
Config Config
|
Config Config
|
||||||
Size image.Point
|
Size image.Point
|
||||||
// Insets is the window space taken up by
|
Insets Insets
|
||||||
// system decoration such as translucent
|
|
||||||
// system bars and software keyboards.
|
|
||||||
Insets image.Rectangle
|
|
||||||
// Whether this draw is system generated
|
// Whether this draw is system generated
|
||||||
// and needs a complete frame before
|
// and needs a complete frame before
|
||||||
// proceeding.
|
// proceeding.
|
||||||
sync bool
|
sync bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Insets is the space taken up by
|
||||||
|
// system decoration such as translucent
|
||||||
|
// system bars and software keyboards.
|
||||||
|
type Insets struct {
|
||||||
|
Top, Bottom, Left, Right ui.Value
|
||||||
|
}
|
||||||
|
|
||||||
type StageEvent struct {
|
type StageEvent struct {
|
||||||
Stage Stage
|
Stage Stage
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
|
"gioui.org/ui"
|
||||||
"gioui.org/ui/f32"
|
"gioui.org/ui/f32"
|
||||||
"gioui.org/ui/key"
|
"gioui.org/ui/key"
|
||||||
"gioui.org/ui/pointer"
|
"gioui.org/ui/pointer"
|
||||||
@@ -36,7 +37,7 @@ type window struct {
|
|||||||
|
|
||||||
dpi int
|
dpi int
|
||||||
fontScale float32
|
fontScale float32
|
||||||
insets image.Rectangle
|
insets Insets
|
||||||
|
|
||||||
stage Stage
|
stage Stage
|
||||||
started bool
|
started bool
|
||||||
@@ -200,9 +201,11 @@ func onFocusChange(env *C.JNIEnv, class C.jclass, view C.jlong, focus C.jboolean
|
|||||||
//export onWindowInsets
|
//export onWindowInsets
|
||||||
func onWindowInsets(env *C.JNIEnv, class C.jclass, view C.jlong, top, right, bottom, left C.jint) {
|
func onWindowInsets(env *C.JNIEnv, class C.jclass, view C.jlong, top, right, bottom, left C.jint) {
|
||||||
w := views[view]
|
w := views[view]
|
||||||
w.insets = image.Rectangle{
|
w.insets = Insets{
|
||||||
Min: image.Point{X: int(left), Y: int(top)},
|
Top: ui.Px(float32(top)),
|
||||||
Max: image.Point{X: int(right), Y: int(bottom)},
|
Right: ui.Px(float32(right)),
|
||||||
|
Bottom: ui.Px(float32(bottom)),
|
||||||
|
Left: ui.Px(float32(left)),
|
||||||
}
|
}
|
||||||
if w.stage >= StageRunning {
|
if w.stage >= StageRunning {
|
||||||
w.draw(true)
|
w.draw(true)
|
||||||
|
|||||||
+6
-3
@@ -22,6 +22,7 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"gioui.org/ui"
|
||||||
"gioui.org/ui/f32"
|
"gioui.org/ui/f32"
|
||||||
"gioui.org/ui/key"
|
"gioui.org/ui/key"
|
||||||
"gioui.org/ui/pointer"
|
"gioui.org/ui/pointer"
|
||||||
@@ -82,9 +83,11 @@ func onDraw(view C.CFTypeRef, dpi, sdpi, width, height C.CGFloat, sync C.int, to
|
|||||||
X: int(width + .5),
|
X: int(width + .5),
|
||||||
Y: int(height + .5),
|
Y: int(height + .5),
|
||||||
},
|
},
|
||||||
Insets: image.Rectangle{
|
Insets: Insets{
|
||||||
Min: image.Point{X: int(left + .5), Y: int(top + .5)},
|
Top: ui.Px(float32(top)),
|
||||||
Max: image.Point{X: int(right + .5), Y: int(bottom + .5)},
|
Right: ui.Px(float32(right)),
|
||||||
|
Bottom: ui.Px(float32(bottom)),
|
||||||
|
Left: ui.Px(float32(left)),
|
||||||
},
|
},
|
||||||
Config: Config{
|
Config: Config{
|
||||||
pxPerDp: float32(dpi) * inchPrDp,
|
pxPerDp: float32(dpi) * inchPrDp,
|
||||||
|
|||||||
Reference in New Issue
Block a user