/
menu.go
106 lines (79 loc) · 3.49 KB
/
menu.go
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
package main
import (
"fmt"
"strings"
"time"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
)
func menuItem(w fyne.Window) *container.TabItem {
data, err := LoadMenu()
if err != nil {
fmt.Println(err)
}
menu := GenerateMenuCard(data, time.Now().Format("2006-01-02"))
breakfastCard := &widget.Card{
Title: "아침",
Content: widget.NewLabel(strings.Join(menu[time.Now().Format("2006-01-02")]["아침"], "\n")),
}
lunchCard := &widget.Card{
Title: "점심",
Content: widget.NewLabel(strings.Join(menu[time.Now().Format("2006-01-02")]["점심"], "\n")),
}
dinnerCard := &widget.Card{
Title: "저녁",
Content: widget.NewLabel(strings.Join(menu[time.Now().Format("2006-01-02")]["저녁"], "\n")),
}
var nowDateBtn *widget.Button
nowDateBtn = widget.NewButton(time.Now().Format("2006-01-02"), func() {
nowDateBtn.SetText(time.Now().Format("2006-01-02"))
menu = GenerateMenuCard(data, time.Now().Format("2006-01-02"))
breakfastCard.SetContent(widget.NewLabel(strings.Join(menu[nowDateBtn.Text]["아침"], "\n")))
lunchCard.SetContent(widget.NewLabel(strings.Join(menu[nowDateBtn.Text]["점심"], "\n")))
dinnerCard.SetContent(widget.NewLabel(strings.Join(menu[nowDateBtn.Text]["저녁"], "\n")))
})
beforeDateBtn := widget.NewButtonWithIcon("", theme.NavigateBackIcon(), func() {
nowDateBtnText, _ := time.Parse("2006-01-02", nowDateBtn.Text)
dateMove := nowDateBtnText.AddDate(0, 0, -1)
if !CheckDayExist(data, dateMove.Format("2006-01-02")) {
dialog.ShowInformation("안내", "더 이상 식단이 없습니다\n새로운 달이라면 업데이트를 해주세요", w)
return
}
nowDateBtn.SetText(dateMove.Format("2006-01-02"))
menu = GenerateMenuCard(data, nowDateBtn.Text)
breakfastCard.SetContent(widget.NewLabel(strings.Join(menu[nowDateBtn.Text]["아침"], "\n")))
lunchCard.SetContent(widget.NewLabel(strings.Join(menu[nowDateBtn.Text]["점심"], "\n")))
dinnerCard.SetContent(widget.NewLabel(strings.Join(menu[nowDateBtn.Text]["저녁"], "\n")))
})
afterDateBtn := widget.NewButtonWithIcon("", theme.NavigateNextIcon(), func() {
nowDateBtnText, _ := time.Parse("2006-01-02", nowDateBtn.Text)
dateMove := nowDateBtnText.AddDate(0, 0, 1)
if !CheckDayExist(data, dateMove.Format("2006-01-02")) {
dialog.ShowInformation("안내", "더 이상 식단이 없습니다\n새로운 달이라면 식단표 업데이트를 해주세요", w)
return
}
nowDateBtn.SetText(dateMove.Format("2006-01-02"))
menu = GenerateMenuCard(data, nowDateBtn.Text)
breakfastCard.SetContent(widget.NewLabel(strings.Join(menu[nowDateBtn.Text]["아침"], "\n")))
lunchCard.SetContent(widget.NewLabel(strings.Join(menu[nowDateBtn.Text]["점심"], "\n")))
dinnerCard.SetContent(widget.NewLabel(strings.Join(menu[nowDateBtn.Text]["저녁"], "\n")))
})
refreshBtn := widget.NewButtonWithIcon("식단표 업데이트", theme.ViewRefreshIcon(), func() {
updateProgress := widget.NewProgressBarInfinite()
updateDialog := dialog.NewCustom("식단표 업데이트 중...", "취소", updateProgress, w)
updateDialog.Show()
data, err = LoadMenu()
if err != nil {
fmt.Println(err)
}
updateDialog.Hide()
})
dateButton := container.NewBorder(nil, nil, beforeDateBtn, afterDateBtn, nowDateBtn)
return container.NewTabItemWithIcon("식단표", resourceIconTabFood,
container.NewVBox(dateButton, breakfastCard, lunchCard, dinnerCard, layout.NewSpacer(), refreshBtn),
)
}