go_dreamfactory/cmd/v2/ui/toolwindow.go
2022-08-23 16:43:38 +08:00

74 lines
1.4 KiB
Go

package ui
import (
"go_dreamfactory/cmd/v2/lib/common"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"github.com/sirupsen/logrus"
)
type ToolWindow interface {
WindowInterface
}
type ToolWindowImpl struct {
UIImpl
w fyne.Window
tb *toolBar //工具条
sb *statusBar //状态栏
at *appContainer //tabs
}
func NewToolWindow(ui *UIImpl) ToolWindow {
mw := &ToolWindowImpl{
UIImpl: *ui,
}
toolWin = mw
mw.sb = newStatusBar()
toolbar := widget.NewToolbar(
widget.NewToolbarAction(theme.ContentCopyIcon(), func() {
openApp1(common.TOOLBAR_GEN)
}),
widget.NewToolbarAction(theme.DownloadIcon(), func() {
openApp1(common.TOOLBAR_SEC)
}),
widget.NewToolbarSpacer(),
widget.NewToolbarAction(theme.HelpIcon(), func() {
showAbout()
}),
)
mw.tb = newToolBar(toolbar)
mw.at = newAppContainer(toolRegister, ui.obs)
return mw
}
func (ui *ToolWindowImpl) CreateWindow(title string, width, height float32, _ bool) {
w := ui.app.NewWindow(title)
ui.AddWindow("tool", w)
ui.w = w
// content
content := container.NewBorder(ui.tb.toolbar, ui.sb.widget,
nil, nil, ui.at)
ui.w.SetContent(content)
appName, err := ui.at.openDefaultApp()
if err != nil {
logrus.WithField("appName", appName).Error(err)
}
w.Resize(fyne.NewSize(width, height))
w.SetMaster()
w.CenterOnScreen()
w.Show()
}