main.go (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
package main
import (
//"fmt"
"strconv"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/widget"
)
func tableView(w fyne.Window, category string) {
items := loadCategory(category)
table := widget.NewTable(
func() (int, int) {
return len(items), 5
},
func() fyne.CanvasObject {
return widget.NewLabel("uhh, something went wrong")
},
func(id widget.TableCellID, cell fyne.CanvasObject) {
label := cell.(*widget.Label)
label.Truncation = fyne.TextTruncateEllipsis
switch id.Col {
case 0:
label.SetText(items[id.Row].name.String)
case 1:
label.SetText(items[id.Row].artist.String)
case 2:
label.SetText(strconv.FormatFloat(items[id.Row].price, 'f', 2, 64) + " " + "€")
case 3:
label.SetText(items[id.Row].seller.String)
case 4:
label.SetText(items[id.Row].purchase_date.String)
}
},
)
table.SetColumnWidth(0, 100)
table.SetColumnWidth(1, 100)
table.SetColumnWidth(2, 100)
table.SetColumnWidth(3, 100)
/*
headers := []string{"Name", "Price", "Seller", "Purchase Date"}
for i, header := range headers {
fmt.Printf("i: %d\nheader: %s", i, header)
table.UpdateHeader(widget.TableCellID{Row: -1, Col: i},
widget.NewLabel(header))
}
*/
editForm := widget.NewForm()
nameEntry := widget.NewEntry()
nameEntry.SetPlaceHolder("test")
editForm.Append("Name", nameEntry)
artistEntry := widget.NewEntry()
artistEntry.SetPlaceHolder("test")
editForm.Append("Artist", artistEntry)
priceEntry := widget.NewEntry()
priceEntry.SetPlaceHolder("test")
editForm.Append("Price", priceEntry)
split := container.NewHSplit(table, editForm)
/*
table.OnSelected = func(id widget.TableCellID) {
editForm := widget.NewForm()
for colIndex := 0; colIndex < 4; colIndex++ {
entry := widget.NewEntry()
entry.SetText(table.Cel)
}
}
*/
w.SetContent(split)
}
func mainMenu(w fyne.Window) {
musicButton := widget.NewButton("Music", func() {tableView(w, "music")})
groceriesButton := widget.NewButton("Groceries", func() {tableView(w, "groceries")})
recurringButton := widget.NewButton("Recurring", func() {tableView(w, "recurring")})
otherButton := widget.NewButton("Other", func() {tableView(w, "other")})
content := container.New(
layout.NewVBoxLayout(),
layout.NewSpacer(),
musicButton,
groceriesButton,
recurringButton,
otherButton,
layout.NewSpacer(),
)
w.SetContent(container.New(
layout.NewHBoxLayout(),
layout.NewSpacer(),
content,
layout.NewSpacer(),
))
}
func main() {
a := app.New()
w := a.NewWindow("Hello World")
mainMenu(w)
w.ShowAndRun()
}
|