我正在使用 Go-Astilectron 创建一个应用程序(Go 的 Electron 框架)。
我的应用程序有一个无框透明窗口,应根据其内容调整大小。据我所知,我有义务在 Electron 中设置窗口的 width
和 height
属性,否则它将默认为 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.
关于go - 自动调整主窗口大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53768072/