I am trying to center my application's window using window.Perform(system.ActionCenter)
. However it has no effect.
I am using gioui v0.7.1 on macOS 15.1.1.
package main
import (
"image/color"
"log"
"os"
"gioui.org/app"
"gioui.org/io/system"
"gioui.org/op"
"gioui.org/op/paint"
)
func main() {
go func() {
window := new(app.Window)
window.Perform(system.ActionCenter)
err := run(window)
if err != nil {
log.Fatal(err)
}
os.Exit(0)
}()
app.Main()
}
func run(window *app.Window) error {
bg := color.NRGBA{A: 255}
ops := new(op.Ops)
for {
switch e := window.Event().(type) {
case app.DestroyEvent:
return e.Err
case app.FrameEvent:
ops.Reset()
paint.Fill(ops, bg)
e.Frame(ops)
}
}
}
If you're using the release version v0.7.1 and not the
@latest
revision, you are running into the same issue like me at https://todo.sr.ht/~eliasnaur/gio/602. I'm still using v0.7.1, but with a workaround like this:func run(window *app.Window) error { applyOptions := sync.OnceFunc(func() { w.Perform(system.ActionCenter) }) bg := color.NRGBA{A: 255} ops := new(op.Ops) for { switch e := window.Event().(type) { case app.DestroyEvent: return e.Err case app.FrameEvent: // TODO work around https://todo.sr.ht/~eliasnaur/gio/602 // this should only be required shortly after creating the window w. applyOptions() ops.Reset() paint.Fill(ops, bg) e.Frame(ops) } } }
Thank you! This workaround does indeed work for me as well.
I take it that the latest version fixes this issue?