显示/移动主窗口到自定义位置

huangapple go评论78阅读模式
英文:

Show/Move main window at custom position

问题

问题
我找不到设置窗口位置的函数。我查看了代码,看到了为不同元素添加的SetPos函数,想知道为什么没有为fyne.Window类型添加这个函数。

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

    if drv, ok := fyne.CurrentApp().Driver().(desktop.Driver); ok {
        w = drv.CreateSplashWindow()
        // 类似这样的操作?
        // w.SetPos(x, y)
        // w.Move(x, y)
    }
}

解决方法
我fork了项目并创建了一个函数:

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

来公开未导出的底层窗口属性w.viewport,这样就可以使用一系列方法了:

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

看起来我要使用它(forked/edited版本),但也许你可以建议一种_fyne-way_来做到这一点 显示/移动主窗口到自定义位置

问题
有没有现有的方法来设置窗口的位置?或者访问底层的w.viewport属性?

英文:

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?

答案1

得分: 1

这在导出的API中是不可能的,因为许多操作系统不支持它。
请参阅有关决策过程的讨论,网址为https://github.com/fyne-io/fyne/issues/1155。

英文:

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

huangapple
  • 本文由 发表于 2023年1月10日 16:49:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/75067498.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定