本文主要是介绍fyne widget小部件2,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
fyne widget小部件2
form表单
package mainimport ("log""fyne.io/fyne/v2/app""fyne.io/fyne/v2/widget"
)func main() {myApp := app.New()myWindow := myApp.NewWindow("Form Widget")entry := widget.NewEntry()textArea := widget.NewMultiLineEntry()form := &widget.Form{Items: []*widget.FormItem{ // we can specify items in the constructor{Text: "Entry", Widget: entry}},OnSubmit: func() { // optional, handle form submissionlog.Println("Form submitted:", entry.Text)log.Println("multiline:", textArea.Text)myWindow.Close()},}// we can also append itemsform.Append("Text", textArea)myWindow.SetContent(form)myWindow.ShowAndRun()
}
progressbar进度条
package mainimport ("time""fyne.io/fyne/v2/app""fyne.io/fyne/v2/container""fyne.io/fyne/v2/widget"
)func main() {myApp := app.New()myWindow := myApp.NewWindow("ProgressBar Widget")progress := widget.NewProgressBar()infinite := widget.NewProgressBarInfinite()go func() {for i := 0.0; i <= 1.0; i += 0.1 {time.Sleep(time.Millisecond * 250)progress.SetValue(i)}}()myWindow.SetContent(container.NewVBox(progress, infinite))myWindow.ShowAndRun()
}
toolbar工具类
package mainimport ("log""fyne.io/fyne/v2/app""fyne.io/fyne/v2/container""fyne.io/fyne/v2/theme""fyne.io/fyne/v2/widget"
)func main() {myApp := app.New()myWindow := myApp.NewWindow("Toolbar Widget")toolbar := widget.NewToolbar(widget.NewToolbarAction(theme.DocumentCreateIcon(), func() {log.Println("New document")}),widget.NewToolbarSeparator(),widget.NewToolbarAction(theme.ContentCutIcon(), func() {}),widget.NewToolbarAction(theme.ContentCopyIcon(), func() {}),widget.NewToolbarAction(theme.ContentPasteIcon(), func() {}),widget.NewToolbarSpacer(),widget.NewToolbarAction(theme.HelpIcon(), func() {log.Println("Display help")}),)content := container.NewBorder(toolbar, nil, nil, nil, widget.NewLabel("Content"))myWindow.SetContent(content)myWindow.ShowAndRun()
}
list列表
package mainimport ("fyne.io/fyne/v2""fyne.io/fyne/v2/app""fyne.io/fyne/v2/widget"
)var data = []string{"a", "string", "list"}func main() {myApp := app.New()myWindow := myApp.NewWindow("List Widget")list := widget.NewList(func() int {return len(data)},func() fyne.CanvasObject {return widget.NewLabel("template")},func(i widget.ListItemID, o fyne.CanvasObject) {o.(*widget.Label).SetText(data[i])})myWindow.SetContent(list)myWindow.ShowAndRun()
}
table表格
package mainimport ("fyne.io/fyne/v2""fyne.io/fyne/v2/app""fyne.io/fyne/v2/widget"
)var data = [][]string{[]string{"top left", "top right"},[]string{"bottom center", "bottom center"}, []string{"bottom left", "bottom right"}}func main() {myApp := app.New()myWindow := myApp.NewWindow("Table Widget")list := widget.NewTable(func() (int, int) {return len(data), len(data[0])},func() fyne.CanvasObject {return widget.NewLabel("wide content")},func(i widget.TableCellID, o fyne.CanvasObject) {o.(*widget.Label).SetText(data[i.Row][i.Col])})myWindow.SetContent(list)myWindow.ShowAndRun()
}
这篇关于fyne widget小部件2的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!