You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
2.5 KiB

package framework
import (
"freeCaculator/global"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/cmd/fyne_demo/tutorials"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
)
/*
*
@author: sre
@date: 2022/8/22 0022
@desc: todo
*
*/
func ShowNav(w fyne.Window) {
a := fyne.CurrentApp()
content := container.NewMax()
title := widget.NewLabel("组件名称")
intro := widget.NewLabel("An introduction would probably go\nhere, as well as a")
intro.Wrapping = fyne.TextWrapWord
setTutorial := func(t tutorials.Tutorial) {
if fyne.CurrentDevice().IsMobile() {
child := a.NewWindow(t.Title)
global.TopWindow = child
child.SetContent(t.View(global.TopWindow))
child.Show()
child.SetOnClosed(func() {
global.TopWindow = w
})
return
}
title.SetText(t.Title)
intro.SetText(t.Intro)
content.Objects = []fyne.CanvasObject{t.View(w)}
content.Refresh()
}
tutorial := container.NewBorder(
container.NewVBox(title, widget.NewSeparator(), intro), nil, nil, nil, content)
// 设置窗口内容
if fyne.CurrentDevice().IsMobile() {
w.SetContent(makeNav(setTutorial, false))
} else {
split := container.NewHSplit(makeNav(setTutorial, true), tutorial)
split.Offset = 0.2
w.SetContent(split)
}
}
func makeNav(setTutorial func(tutorial tutorials.Tutorial), loadPrevious bool) fyne.CanvasObject {
a := fyne.CurrentApp()
tree := &widget.Tree{
ChildUIDs: func(uid string) []string {
return tutorials.TutorialIndex[uid]
},
IsBranch: func(uid string) bool {
children, ok := tutorials.TutorialIndex[uid]
return ok && len(children) > 0
},
CreateNode: func(branch bool) fyne.CanvasObject {
return widget.NewLabel("Collection Widgets")
},
UpdateNode: func(uid string, branch bool, obj fyne.CanvasObject) {
t, ok := tutorials.Tutorials[uid]
if !ok {
fyne.LogError("Missing tutorial panel: "+uid, nil)
return
}
obj.(*widget.Label).SetText(t.Title)
},
OnSelected: func(uid string) {
if t, ok := tutorials.Tutorials[uid]; ok {
a.Preferences().SetString(global.PreferenceCurrentTutorial, uid)
setTutorial(t)
}
},
}
if loadPrevious {
currentPref := a.Preferences().StringWithFallback(global.PreferenceCurrentTutorial, "欢迎")
tree.Select(currentPref)
}
themes := container.New(layout.NewGridLayout(2),
widget.NewButton("Dark", func() {
a.Settings().SetTheme(theme.DarkTheme())
}),
widget.NewButton("Light", func() {
a.Settings().SetTheme(theme.LightTheme())
}),
)
return container.NewBorder(nil, themes, nil, nil, tree)
}