go - 自动调整主窗口大小

标签 go electron

我正在使用 Go-Astilectron 创建一个应用程序(Go 的 Electron 框架)。

我的应用程序有一个无框透明窗口,应根据其内容调整大小。据我所知,我有义务在 Electron 中设置窗口的 widthheight 属性,否则它将默认为 800x600。

我想知道的是,Electron 是否有一种方法可以根据其内容自动调整窗口大小。

我可以使用“一刀切”的方法,但由于我的窗口是无框和透明的,它的某些部分最终会位于其他内容之上,并且由于没有点击,用户会感到困惑以为他正在点击其他应用程序,而实际上他正在点击我的应用程序。

这是我创建窗口的代码:

var w *astilectron.Window

log.Debug("Starting astilectron...")
window := []*bootstrap.Window{{
    Homepage: "http://localhost:3000",
    Adapter: func(i *astilectron.Window) {
        w = i
    },
    Options: &astilectron.WindowOptions{
        MinHeight:          astilectron.PtrInt(50),
        MinWidth:           astilectron.PtrInt(50),
        AlwaysOnTop:         astilectron.PtrBool(true),
        Transparent:         astilectron.PtrBool(true),
        Closable:            astilectron.PtrBool(false),
        Minimizable:         astilectron.PtrBool(false),
        Frame:                   astilectron.PtrBool(false),
        Movable:                 astilectron.PtrBool(true),
        SkipTaskbar:         astilectron.PtrBool(false),
        Resizable:           astilectron.PtrBool(false),
    },
}}

go func() {
    err := bootstrap.Run(bootstrap.Options{
        Windows: window,
        Debug: true,
    })

    if err != nil {
        log.WithError(err).Fatal("Error with Astilectron")
    }
}()

最佳答案

尝试设置 UseContentSize: astilectron.PtrBool(true)

UseContentSize 根据页面大小调整窗口大小。这是它在文档中所说的:

The width and height would be used as web page's size, which means the actual window's size will include window frame's size and be slightly larger. Default is false.

Docs

关于go - 自动调整主窗口大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53768072/

相关文章:

go - 具有许多属性的 UpdateItem

go - Heroku 去构建包 : Cannot find import path for my created module

shell - Golang exec.Command 在退出代码不为零时返回 nil 错误

json - 从键值对中提取 "filtering"JSON 对象的最有效方法是什么?

python - Electron-builder 没有捆绑 python 文件

electron - 如何确定应用程序是否由 Electron 构建?

go - 如何避免 VSCode 在 Golang 中删除未使用的 var 或导入

javascript - 在安装 ElectronJS 应用程序期间安装节点模块

javascript - 有没有一种方法可以使用检查元素在Electron中选择元素?

node.js - 在 Electron 中使用 gRPC