Home  >  Article  >  Backend Development  >  Show/move main window at custom position

Show/move main window at custom position

王林
王林forward
2024-02-08 22:40:27463browse

Show/move main window at custom position

php editor Xigua will introduce to you how to display or move the main window in a custom position in this article. When developing web applications, sometimes we need to place the main window at a specific location or move it to a new location after user action. This provides a better user experience and increases the usability of the application. Below, we'll discuss several ways to implement this functionality to help developers better master this technique.

Question content

Question

I can't find the function to set the window position. I looked at the code and saw the setpos function for different elements and wondered why it wasn't added for the 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)    
    }

Solution

I forked the project and created func:

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

Expose unexported underlying window properties w.viewport. It unlocked many methods that I can use now

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

Looks like I'll be using it (the forked/edited version), but maybe you can suggest a fyne-way to do it :)

question

Is there an existing way to set the window's position? Or access the underlying w.viewport property?

Workaround

This is not possible with the exported API because many operating systems do not support it. For a discussion of the decision-making process, please visit https://github.com/fyne-io/fyne/issue/1155

The above is the detailed content of Show/move main window at custom position. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete