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

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

Show/Move main window at custom position

问题

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

  1. func main() {
  2. a := app.New()
  3. w := a.NewWindow("Trying to position window")
  4. if drv, ok := fyne.CurrentApp().Driver().(desktop.Driver); ok {
  5. w = drv.CreateSplashWindow()
  6. // 类似这样的操作?
  7. // w.SetPos(x, y)
  8. // w.Move(x, y)
  9. }
  10. }

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

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

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

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

看起来我要使用它(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.

  1. func main() {
  2. a := app.New()
  3. w := a.NewWindow("Trying to position window")
  4. if drv, ok := fyne.CurrentApp().Driver().(desktop.Driver); ok {
  5. w = drv.CreateSplashWindow()
  6. // something like this?
  7. // w.SetPos(x, y)
  8. // w.Move(x, y)
  9. }

Workaround

I forked project and created func:

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

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

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

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:

确定