完成基本的创建使用功能
This commit is contained in:
@@ -1,20 +1,28 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/app"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"work_cation/assets"
|
||||
"work_cation/global"
|
||||
"work_cation/version"
|
||||
"work_cation/views"
|
||||
)
|
||||
|
||||
const preferenceCurrentTutorial = "currentTutorial"
|
||||
|
||||
func main() {
|
||||
|
||||
global.InitDB()
|
||||
|
||||
a := app.NewWithID("io.fyne.workCation")
|
||||
a.Settings().SetTheme(&assets.MyTheme{})
|
||||
a.SetIcon(assets.LogoDataSR)
|
||||
w := a.NewWindow("主页 " + version.NowVersion)
|
||||
w.Resize(fyne.NewSize(380, 300))
|
||||
w.Resize(fyne.NewSize(800, 550))
|
||||
w.SetContent(mainView(w))
|
||||
w.CenterOnScreen()
|
||||
w.SetMaster()
|
||||
@@ -23,11 +31,101 @@ func main() {
|
||||
a.Run()
|
||||
}
|
||||
|
||||
// 主界面
|
||||
func mainView(w fyne.Window) fyne.CanvasObject {
|
||||
return container.NewBorder(nil, nil, nil, nil,
|
||||
container.NewVBox(
|
||||
views.ErlangCardView(w, nil),
|
||||
views.ErlangCardView(w, nil),
|
||||
),
|
||||
var (
|
||||
content = container.NewMax()
|
||||
a = fyne.CurrentApp()
|
||||
topWindow = w
|
||||
//title = widget.NewLabel("Component name")
|
||||
//intro = widget.NewLabel("An introduction would probably go\nhere, as well as a")
|
||||
)
|
||||
|
||||
setTutorial := func(t views.Tutorial) {
|
||||
if fyne.CurrentDevice().IsMobile() {
|
||||
child := a.NewWindow(t.Title)
|
||||
topWindow = child
|
||||
child.SetContent(t.View(topWindow))
|
||||
child.Show()
|
||||
child.SetOnClosed(func() {
|
||||
topWindow = w
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
//title.SetText(t.Title)
|
||||
//intro.SetText(t.Intro)
|
||||
|
||||
content.Objects = []fyne.CanvasObject{t.View(w)}
|
||||
content.Refresh()
|
||||
}
|
||||
|
||||
tutorial := container.NewBorder(nil, nil, nil, nil, content)
|
||||
//container.NewVBox(title, widget.NewSeparator(), intro)
|
||||
|
||||
split := container.NewHSplit(makeNav(setTutorial, true), tutorial)
|
||||
split.Offset = 0.2
|
||||
return container.NewBorder(nil, nil, nil, nil, split)
|
||||
}
|
||||
|
||||
// 左侧菜单
|
||||
func makeNav(setTutorial func(tutorial views.Tutorial), loadPrevious bool) fyne.CanvasObject {
|
||||
a := fyne.CurrentApp()
|
||||
|
||||
tree := &widget.Tree{
|
||||
ChildUIDs: func(uid string) []string {
|
||||
return views.TutorialIndex[uid]
|
||||
},
|
||||
IsBranch: func(uid string) bool {
|
||||
children, ok := views.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 := views.Tutorials[uid]
|
||||
if !ok {
|
||||
fyne.LogError("Missing tutorial panel: "+uid, nil)
|
||||
return
|
||||
}
|
||||
obj.(*widget.Label).SetText(t.Title)
|
||||
if unsupportedTutorial(t) {
|
||||
obj.(*widget.Label).TextStyle = fyne.TextStyle{Italic: true}
|
||||
} else {
|
||||
obj.(*widget.Label).TextStyle = fyne.TextStyle{}
|
||||
}
|
||||
},
|
||||
OnSelected: func(uid string) {
|
||||
if t, ok := views.Tutorials[uid]; ok {
|
||||
if unsupportedTutorial(t) {
|
||||
return
|
||||
}
|
||||
a.Preferences().SetString(preferenceCurrentTutorial, uid)
|
||||
fmt.Println(t)
|
||||
setTutorial(t)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
if loadPrevious {
|
||||
currentPref := a.Preferences().StringWithFallback(preferenceCurrentTutorial, "welcome")
|
||||
tree.Select(currentPref)
|
||||
}
|
||||
|
||||
//themes := container.NewGridWithColumns(2,
|
||||
// widget.NewButton("Dark", func() {
|
||||
// a.Settings().SetTheme(theme.DarkTheme())
|
||||
// }),
|
||||
// widget.NewButton("Light", func() {
|
||||
// a.Settings().SetTheme(theme.LightTheme())
|
||||
// }),
|
||||
//)
|
||||
|
||||
return container.NewBorder(nil, nil, nil, nil, tree)
|
||||
}
|
||||
|
||||
func unsupportedTutorial(t views.Tutorial) bool {
|
||||
return !t.SupportWeb && fyne.CurrentDevice().IsBrowser()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user