Show/move main window at custom position

王林
Release: 2024-02-08 22:40:27
forward
462 people have browsed it

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)    
    }
Copy after login

Solution

I forked the project and created func:

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

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)
}
Copy after login

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!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!