/
screens.go
115 lines (96 loc) · 2.64 KB
/
screens.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
107
108
109
110
111
112
113
114
115
package app
import (
"fmt"
"image"
"github.com/fogleman/gg"
"github.com/golang/freetype/truetype"
)
func CreateStartScreen(projectSummary ProjectSummary) image.Image {
dc := gg.NewContext(screenW, screenH)
dc.SetRGB(1, 1, 1)
dc.Clear()
dc.SetRGB(0, 0, 0)
fnt := getRegularFont()
face := truetype.NewFace(fnt, &truetype.Options{
Size: 18,
})
dc.SetFontFace(face)
drawHeadline(dc)
if len(projectSummary.Projects) > 0 {
drawButton(dc, face, fnt, buttonDown().SetY(20).SetX(20))
drawButton(dc, face, fnt, buttonPreviousDay().SetY(54).SetX(20))
drawButton(dc, face, fnt, buttonPagination().SetY(88).SetX(20))
face = truetype.NewFace(fnt, &truetype.Options{
Size: 12,
})
dc.SetFontFace(face)
drawHCentered(dc, 42, projectSummary.Date.Format("Mon, 02 Jan"))
face := truetype.NewFace(fnt, &truetype.Options{
Size: 16,
})
dc.SetFontFace(face)
const vMargin = 20
const xOffset = 50.0
const yOffset = 68.0
var maxWidth = 0.0
y := yOffset
for _, item := range projectSummary.Pagination.GetCurrentPageItems(projectSummary.Projects) {
project := item.(Project)
if project.Capture == "" {
continue
}
text := project.Name
textWidth, _ := dc.MeasureString(text)
if maxWidth < textWidth {
maxWidth = textWidth
}
dc.DrawString(text, xOffset, y)
y += vMargin
}
y = yOffset
for _, item := range projectSummary.Pagination.GetCurrentPageItems(projectSummary.Projects) {
project := item.(Project)
text := project.Capture
dc.DrawString(text, xOffset+maxWidth+12, y)
y += vMargin
}
drawHCentered(dc, y, fmt.Sprintf("%v/%v", projectSummary.Pagination.Page, projectSummary.Pagination.GetLastPage()))
} else {
drawHCentered(dc, 80, "No Projects available")
}
dc.InvertX()
dc.Push()
dc.InvertY()
dc.Push()
return dc.Image()
}
func CreateProjectScreen(p Project) image.Image {
dc := gg.NewContext(screenW, screenH)
dc.SetRGB(1, 1, 1)
dc.Clear()
dc.SetRGB(0, 0, 0)
fnt := getRegularFont()
face := truetype.NewFace(fnt, &truetype.Options{
Size: 14,
})
dc.SetFontFace(face)
drawHeadline(dc)
drawButton(dc, face, fnt, buttonUp().SetX(20).SetY(20))
drawButton(dc, face, getBoldFont(), buttonClose().SetX(20).SetY(54))
drawButton(dc, face, fnt, buttonRight().SetY(screenH-54).SetX(20))
drawButton(dc, face, fnt, buttonLeft().SetY(screenH-20).SetX(20))
drawProjectName(dc, fnt, 60, p.Name)
drawProjectDescription(dc, fnt, 90, p.Description)
drawTodayCapture(dc, fnt, 128, p.Capture)
if p.Closed {
dc.SetFontFace(truetype.NewFace(fnt, &truetype.Options{
Size: 44,
}))
drawHCentered(dc, 150, "√")
}
dc.InvertX()
dc.Push()
dc.InvertY()
dc.Push()
return dc.Image()
}