Update gio version. Add side grid for year selection to cmd/cal.

This commit is contained in:
gmp
2019-08-22 14:43:28 -04:00
parent 25847d5921
commit 014ace99a6
5 changed files with 112 additions and 63 deletions
+4
View File
@@ -31,6 +31,10 @@ func _newMonth(y int, m time.Month) SelectableMonth {
return *NewMonth(time.Date(y,m,1,0,0,0,0,time.Local))
}
func (sm *SelectableMonth) Refresh() {
*sm = _newMonth(sm.Year, sm.Month)
}
func (sm *SelectableMonth) Previous() {
m, y := sm.Month - 1, sm.Year
if m > 11 {
+39 -16
View File
@@ -13,7 +13,6 @@ import (
"gioui.org/ui"
"gioui.org/ui/app"
"gioui.org/ui/layout"
//"gioui.org/ui/measure"
"gioui.org/ui/text"
"golang.org/x/image/font/sfnt"
@@ -33,7 +32,7 @@ func main() {
}
func NewButton(t string, lops ...gio.LabelOption) gio.Clickable {
lops = append([]gio.LabelOption{gio.Face(face), gio.Align(text.Center)}, lops...)
lops = append([]gio.LabelOption{gio.Face(face), gio.Align(text.Middle)}, lops...)
lbl := gio.NewLabel(t, lops...)
bg := gio.NewBackground(
gio.Color(color.RGBA{A: 0xff, R: 0xf0, G: 0xf0, B: 0xe0}),
@@ -96,8 +95,10 @@ func NewCal(sm *SelectableMonth) gio.Widget {
}
func eventloop() {
w := app.NewWindow(&app.WindowOptions{
Width: ui.Dp(600), Height: ui.Dp(600), Title: "Tickets"})
w := app.NewWindow(
app.WithWidth(ui.Dp(600)),
app.WithHeight(ui.Dp(600)),
app.WithTitle("Calendar"))
ctx := gio.NewContext(w)
sm := NewMonth(time.Now())
@@ -105,18 +106,24 @@ func eventloop() {
face = ctx.Faces.For(regular, ui.Sp(20))
if err != nil { log.Fatal("Cannot parse font.") }
margin := gio.NewInset(gio.Size(ui.Dp(10)))
topgrid := gio.NewGrid(3)
lbtn := NewButton(" < ")
mth := gio.NewLabel("", gio.Face(face), gio.Align(text.Center))
rbtn := NewButton(" > ")
f1 := gio.NewFlex(gio.Axis(layout.Vertical))
bg := gio.NewBackground(
gio.Color(color.RGBA{A: 0xff, R: 0xf0, G: 0xf0, B: 0xe0}))
margin := gio.NewInset(gio.Size(ui.Dp(10)))
f1 := gio.NewFlex(gio.Axis(layout.Vertical))
f2 := gio.NewFlex(gio.Axis(layout.Horizontal))
sidegrid := gio.NewGrid(1)
yrs := make([]gio.Widget,6)
curyr := sm.Year
topgrid := gio.NewGrid(3)
lbtn := NewButton(" < ")
mth := gio.NewLabel("", gio.Face(face), gio.Align(text.Middle))
rbtn := NewButton(" > ")
var cal gio.Widget
f3 := gio.NewFlex(gio.Axis(layout.Vertical))
daygrid := gio.NewGrid(7)
sun := NewSLabel("Sun",&sm.Ws[time.Sunday], gio.Align(text.End))
mon := NewSLabel("Mon",&sm.Ws[time.Monday], gio.Align(text.End))
@@ -128,6 +135,10 @@ func eventloop() {
resetCal := func() {
cal = NewCal(sm)
for i,_ := range yrs {
yrs[i] = NewButton(fmt.Sprintf("%d",curyr - i),
gio.Align(text.Start))
}
w.Invalidate()
}
resetCal()
@@ -137,18 +148,23 @@ func eventloop() {
switch e := e.(type) {
case app.DestroyEvent:
return
case app.DrawEvent:
case app.UpdateEvent:
ctx.Reset(e)
mth.SetText(fmt.Sprintf("%s %d",sm.Month.String(),sm.Year))
ows := sm.Ws
bg(margin(f1(
topgrid(lbtn,mth,rbtn),
daygrid(sun,mon,tue,wed,thu,fri,sat),
cal,
topgrid(lbtn,mth,rbtn),
f2(
sidegrid(yrs...),
f3(
daygrid(sun,mon,tue,wed,thu,fri,sat),
cal,
),
),
))).Layout(ctx)
ctx.Draw()
ctx.Update()
for i := time.Sunday; i < 7; i++ {
switch {
@@ -168,6 +184,13 @@ func eventloop() {
sm.Next()
resetCal()
}
for i,y := range yrs {
if y.(gio.Clickable).Clicked(ctx) {
sm.Year = curyr - i
sm.Refresh()
resetCal()
}
}
sm.CheckSel()
}
}}