简体   繁体   中英

Show/Move main window at custom position

Problem

I can't find function to set position of the window. I'v looked into code and I see SetPos func for different elements and wondering why it's not added for fyne.Window type.

func main() {
    a := app.New()
    w := a.NewWindow("Trying to position window")

    if drv, ok := fyne.CurrentApp().Driver().(desktop.Driver); ok {
        w = drv.CreateSplashWindow()
        // something like this?
        // w.SetPos(x, y)  
        // w.Move(x, y)    
    }

Workaround

I forked project and created func:

func (w *window) GLFWindow() *glfw.Window {
    return w.view()
}  

to expose unexported underlying window attribute w.viewport . and it unlocks bunch of methods i can use now

if ww := w.GLFWindow(); ww != nil {
    ww.SetPos(x, y)
}

It looks I'm gonna use it (forked/edited version) but maybe you can suggest fyne-way to do it:)

Question

Is there existing way to set position of the window? Or access underlying w.viewport attribute?

This is not possible with the exported API, because many OS do not support it. See discussion about the decision process at https://github.com/fyne-io/fyne/issues/1155

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM