~eliasnaur/gio#626: 
ActionCenter has no effect

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)
		}
	}
}
Status
RESOLVED DUPLICATE
Submitter
~ritepaw
Assigned to
No-one
Submitted
3 months ago
Updated
2 months ago
Labels
No labels applied.

~gesellix 2 months ago*

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)
		}
	}
}

~ritepaw 2 months ago

Thank you! This workaround does indeed work for me as well.

~eliasnaur REPORTED DUPLICATE 2 months ago

I take it that the latest version fixes this issue?

Register here or Log in to comment, or comment via email.