英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论