Move Grid{} to a new file. Run go fmt.

This commit is contained in:
gmp
2019-08-27 09:24:30 -04:00
parent f96cdb619a
commit 9f60b99984
7 changed files with 544 additions and 398 deletions
+49 -37
View File
@@ -5,21 +5,21 @@ import (
)
func _daysIn(t time.Time) int {
y,m,_ := t.Date()
t2 := time.Date(y,m+1,1,0,0,0,0,time.UTC)
return t2.AddDate(0,0,-1).Day()
y, m, _ := t.Date()
t2 := time.Date(y, m+1, 1, 0, 0, 0, 0, time.UTC)
return t2.AddDate(0, 0, -1).Day()
}
type SelectableMonth struct {
Ws [7]bool
S [32]bool
Ws [7]bool
S [32]bool
Year, Pad, DaysIn int
Month time.Month
Weekday time.Weekday
Month time.Month
Weekday time.Weekday
}
func NewMonth(t time.Time) *SelectableMonth {
t = time.Date(t.Year(), t.Month(),1,0,0,0,0,time.Local)
t = time.Date(t.Year(), t.Month(), 1, 0, 0, 0, 0, time.Local)
ret := &SelectableMonth{}
ret.Year, ret.Month, ret.Weekday = t.Year(), t.Month(), t.Weekday()
ret.DaysIn = _daysIn(t)
@@ -28,7 +28,7 @@ func NewMonth(t time.Time) *SelectableMonth {
}
func _newMonth(y int, m time.Month) SelectableMonth {
return *NewMonth(time.Date(y,m,1,0,0,0,0,time.Local))
return *NewMonth(time.Date(y, m, 1, 0, 0, 0, 0, time.Local))
}
func (sm *SelectableMonth) Refresh() {
@@ -36,21 +36,21 @@ func (sm *SelectableMonth) Refresh() {
}
func (sm *SelectableMonth) Previous() {
m, y := sm.Month - 1, sm.Year
m, y := sm.Month-1, sm.Year
if m > 11 {
m = 0
y += 1
}
*sm = _newMonth(y,m)
*sm = _newMonth(y, m)
}
func (sm *SelectableMonth) Next() {
m, y := sm.Month + 1, sm.Year
if m <0 {
m, y := sm.Month+1, sm.Year
if m < 0 {
m = 11
y -= 1
}
*sm = _newMonth(y,m)
*sm = _newMonth(y, m)
}
func (sm *SelectableMonth) SelectWeekday(d time.Weekday) *SelectableMonth {
@@ -77,7 +77,7 @@ func (sm *SelectableMonth) DeselectWeekday(d time.Weekday) *SelectableMonth {
func (sm *SelectableMonth) CheckSel() *SelectableMonth {
alldays := func(d time.Weekday) bool {
for i := int(d) + 1 - sm.Pad; i <= 31; i+= 7 {
for i := int(d) + 1 - sm.Pad; i <= 31; i += 7 {
if i < 1 {
continue
}
@@ -102,8 +102,10 @@ func (sm *SelectableMonth) Weekdays() int {
var i int
for w := 0; w <= 6; w++ {
for d := 1; d < 6; d++ {
x := w * 7 + d + 1 - sm.Pad
if x < 0 || x >= sm.DaysIn { break }
x := w*7 + d + 1 - sm.Pad
if x < 0 || x >= sm.DaysIn {
break
}
if sm.S[x] {
i++
}
@@ -116,12 +118,22 @@ func (sm *SelectableMonth) Weekends() int {
var i int
for w := 0; w <= 6; w++ {
x := w*7 + 1 - sm.Pad
if x < 0 { continue }
if x >= sm.DaysIn { break }
if sm.S[x] { i++ }
x = w*7+6 + 1 - sm.Pad
if x < 0 || x >= sm.DaysIn { break }
if sm.S[x] { i++ }
if x < 0 {
continue
}
if x >= sm.DaysIn {
break
}
if sm.S[x] {
i++
}
x = w*7 + 6 + 1 - sm.Pad
if x < 0 || x >= sm.DaysIn {
break
}
if sm.S[x] {
i++
}
}
return i
}
@@ -129,7 +141,7 @@ func (sm *SelectableMonth) Weekends() int {
// a day within a SelectableMonth
type Day struct {
Num int
sm *SelectableMonth
sm *SelectableMonth
}
func (sm *SelectableMonth) Day(i int) *Day {
@@ -157,19 +169,19 @@ func (d *Day) ifexists() *Day {
}
func (d *Day) Next() *Day {
ret := &Day{d.Num+1, d.sm}
ret := &Day{d.Num + 1, d.sm}
return ret.ifexists()
}
func (d *Day) Prev() *Day {
ret := &Day{d.Num-1, d.sm}
ret := &Day{d.Num - 1, d.sm}
return ret.ifexists()
}
func (sm *SelectableMonth) Days() []*Day {
ret := make([]*Day,0)
ret := make([]*Day, 0)
for d := sm.Day(1); d.exists(); d = d.Next() {
ret = append(ret,d)
ret = append(ret, d)
}
return ret
}
@@ -186,7 +198,7 @@ func (d *Day) Selected() bool {
type Week struct {
Num int
sm *SelectableMonth
sm *SelectableMonth
}
func (w *Week) exists() bool {
@@ -211,9 +223,9 @@ func (sm *SelectableMonth) Week(i int) *Week {
}
func (sm *SelectableMonth) Weeks() []*Week {
ret := make([]*Week,0)
ret := make([]*Week, 0)
for w := sm.Week(1); w.exists(); w = w.Next() {
ret = append(ret,w)
ret = append(ret, w)
}
return ret
}
@@ -222,28 +234,28 @@ func (w *Week) Day(i int) *Day {
if i < 1 || i > 7 {
return nil
}
wday := (w.Num - 1) * 7 + i
wday := (w.Num-1)*7 + i
if w.Num != 1 {
wday -= w.sm.Pad
}
ret := &Day{ wday, w.sm }
ret := &Day{wday, w.sm}
return ret.ifexists()
}
func (w *Week) Next() *Week {
ret := &Week{ w.Num + 1, w.sm }
ret := &Week{w.Num + 1, w.sm}
return ret.ifexists()
}
func (w *Week) Prev() *Week {
ret := &Week{ w.Num - 1, w.sm }
ret := &Week{w.Num - 1, w.sm}
return ret.ifexists()
}
func (w *Week) Days() []*Day {
ret := make([]*Day,0)
ret := make([]*Day, 0)
for d := w.Day(1); d.In(w); d = d.Next() {
ret = append(ret,d)
ret = append(ret, d)
}
return ret
}
+69 -66
View File
@@ -4,8 +4,8 @@ package main
import (
"fmt"
"log"
"image/color"
"log"
"time"
gio "git.wow.st/gmp/giowrap"
@@ -15,12 +15,12 @@ import (
"gioui.org/ui/layout"
"gioui.org/ui/text"
"golang.org/x/image/font/sfnt"
"golang.org/x/image/font/gofont/goregular"
"golang.org/x/image/font/sfnt"
)
var (
sel int32
sel int32
face text.Face
)
@@ -41,24 +41,24 @@ func NewButton(t string, lops ...gio.LabelOption) gio.Clickable {
}
type SLabel struct {
w gio.Clickable
bg *gio.Background
w gio.Clickable
bg *gio.Background
active *bool
}
func NewSLabel(t string, active *bool, lops ...gio.LabelOption) *SLabel {
ret := &SLabel{}
lops = append([]gio.LabelOption{gio.Face(face)},lops...)
lops = append([]gio.LabelOption{gio.Face(face)}, lops...)
lbl := gio.NewLabel(t, lops...)
bg := &gio.Background{
Color: color.RGBA{A: 0xff, R: 0xf0, G: 0xf0, B: 0xe0},
Color: color.RGBA{A: 0xff, R: 0xf0, G: 0xf0, B: 0xe0},
Radius: ui.Dp(4),
Inset: layout.UniformInset(ui.Dp(4)),
Inset: layout.UniformInset(ui.Dp(4)),
}
if *active {
bg.Color = color.RGBA{A: 0xff, R: 0xf0, G: 0xf0, B: 0xe0}
}
l := gio.AsClickable(gio.Enclose(bg,lbl))
l := gio.AsClickable(gio.Enclose(bg, lbl))
ret.w = l
ret.bg = bg
ret.active = active
@@ -83,12 +83,12 @@ func (w *SLabel) Layout(ctx *gio.Context) {
func NewCal(sm *SelectableMonth) gio.Widget {
pad := gio.NewLabel("", gio.Face(face), gio.Align(text.End))
ds := make([]gio.Widget,42)
ds := make([]gio.Widget, 42)
for i := 0; i < len(ds); i++ {
if i < sm.Pad || i >= sm.DaysIn + sm.Pad {
if i < sm.Pad || i >= sm.DaysIn+sm.Pad {
ds[i] = pad
} else {
ds[i] = NewSLabel(fmt.Sprintf("%d",i+1-sm.Pad), &sm.S[i+1-sm.Pad], gio.Align(text.End))
ds[i] = NewSLabel(fmt.Sprintf("%d", i+1-sm.Pad), &sm.S[i+1-sm.Pad], gio.Align(text.End))
}
}
return gio.NewGrid(7)(ds...)
@@ -104,7 +104,9 @@ func eventloop() {
regular, err := sfnt.Parse(goregular.TTF)
face = ctx.Faces.For(regular, ui.Sp(20))
if err != nil { log.Fatal("Cannot parse font.") }
if err != nil {
log.Fatal("Cannot parse font.")
}
bg := gio.NewBackground(
gio.Color(color.RGBA{A: 0xff, R: 0xf0, G: 0xf0, B: 0xe0}))
@@ -113,7 +115,7 @@ func eventloop() {
f1 := gio.NewFlex(gio.Axis(layout.Vertical))
f2 := gio.NewFlex(gio.Axis(layout.Horizontal))
sidegrid := gio.NewGrid(1)
yrs := make([]gio.Widget,6)
yrs := make([]gio.Widget, 6)
curyr := sm.Year
topgrid := gio.NewGrid(3)
@@ -125,74 +127,75 @@ func eventloop() {
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))
tue := NewSLabel("Tue",&sm.Ws[time.Tuesday], gio.Align(text.End))
wed := NewSLabel("Wed",&sm.Ws[time.Wednesday], gio.Align(text.End))
thu := NewSLabel("Thu",&sm.Ws[time.Thursday], gio.Align(text.End))
fri := NewSLabel("Fri",&sm.Ws[time.Friday], gio.Align(text.End))
sat := NewSLabel("Sat",&sm.Ws[time.Saturday], gio.Align(text.End))
sun := NewSLabel("Sun", &sm.Ws[time.Sunday], gio.Align(text.End))
mon := NewSLabel("Mon", &sm.Ws[time.Monday], gio.Align(text.End))
tue := NewSLabel("Tue", &sm.Ws[time.Tuesday], gio.Align(text.End))
wed := NewSLabel("Wed", &sm.Ws[time.Wednesday], gio.Align(text.End))
thu := NewSLabel("Thu", &sm.Ws[time.Thursday], gio.Align(text.End))
fri := NewSLabel("Fri", &sm.Ws[time.Friday], gio.Align(text.End))
sat := NewSLabel("Sat", &sm.Ws[time.Saturday], gio.Align(text.End))
resetCal := func() {
cal = NewCal(sm)
for i,_ := range yrs {
yrs[i] = NewButton(fmt.Sprintf("%d",curyr - i),
for i, _ := range yrs {
yrs[i] = NewButton(fmt.Sprintf("%d", curyr-i),
gio.Align(text.Start))
}
w.Invalidate()
}
resetCal()
for { select {
case e:= <-w.Events():
switch e := e.(type) {
case app.DestroyEvent:
return
case app.UpdateEvent:
ctx.Reset(e)
for {
select {
case e := <-w.Events():
switch e := e.(type) {
case app.DestroyEvent:
return
case app.UpdateEvent:
ctx.Reset(e)
mth.SetText(fmt.Sprintf("%s %d",sm.Month.String(),sm.Year))
mth.SetText(fmt.Sprintf("%s %d", sm.Month.String(), sm.Year))
ows := sm.Ws
bg(margin(f1(
topgrid(lbtn,mth,rbtn),
f2(
sidegrid(yrs...),
f3(
daygrid(sun,mon,tue,wed,thu,fri,sat),
cal,
),
),
))).Layout(ctx)
ctx.Update()
ows := sm.Ws
bg(margin(f1(
topgrid(lbtn, mth, rbtn),
f2(
sidegrid(yrs...),
f3(
daygrid(sun, mon, tue, wed, thu, fri, sat),
cal,
),
),
))).Layout(ctx)
ctx.Update()
for i := time.Sunday; i < 7; i++ {
switch {
case sm.Ws[i] && !ows[i]:
sm.SelectWeekday(i)
resetCal()
case !sm.Ws[i] && ows[i]:
sm.DeselectWeekday(i)
for i := time.Sunday; i < 7; i++ {
switch {
case sm.Ws[i] && !ows[i]:
sm.SelectWeekday(i)
resetCal()
case !sm.Ws[i] && ows[i]:
sm.DeselectWeekday(i)
resetCal()
}
}
if lbtn.Clicked(ctx) {
sm.Previous()
resetCal()
}
}
if lbtn.Clicked(ctx) {
sm.Previous()
resetCal()
}
if rbtn.Clicked(ctx) {
sm.Next()
resetCal()
}
for i,y := range yrs {
if y.(gio.Clickable).Clicked(ctx) {
sm.Year = curyr - i
sm.Refresh()
if rbtn.Clicked(ctx) {
sm.Next()
resetCal()
}
for i, y := range yrs {
if y.(gio.Clickable).Clicked(ctx) {
sm.Year = curyr - i
sm.Refresh()
resetCal()
}
}
sm.CheckSel()
}
sm.CheckSel()
}
}}
}
}
+62
View File
@@ -0,0 +1,62 @@
package main
import (
"image"
"gioui.org/ui"
"gioui.org/ui/app"
"gioui.org/ui/f32"
"gioui.org/ui/layout"
"gioui.org/ui/paint"
gio "git.wow.st/gmp/giowrap"
)
func main() {
go func() {
w := app.NewWindow()
ops := new(ui.Ops)
gcs := make([]gio.GridChild, 0)
for e := range w.Events() {
if e, ok := e.(app.UpdateEvent); ok {
ops.Reset()
c := &e.Config
cs := layout.RigidConstraints(e.Size)
nrows := 5
ncols := 10
grid := gio.Grid{Cols: ncols}
cs = grid.Init(ops, cs)
for i := 0; i < nrows*ncols; i++ {
grid.Begin()
dims := layoutRect(c, ops, cs)
gcs = append(gcs, grid.End(dims))
}
grid.Layout(gcs...)
w.Update(ops)
gcs = gcs[0:0]
}
}
}()
app.Main()
}
func layoutRect(c ui.Config, ops *ui.Ops, cs layout.Constraints) layout.Dimens {
ins := layout.UniformInset(ui.Px(10))
cs = ins.Begin(c, ops, cs)
paint.PaintOp{Rect: f32.Rectangle{
Max: f32.Point{
X: float32(cs.Width.Max),
Y: float32(cs.Width.Max),
},
}}.Add(ops)
dims := layout.Dimens{
Size: image.Point{
X: cs.Width.Max,
Y: cs.Width.Max,
},
}
return ins.End(dims)
}
+53 -40
View File
@@ -14,25 +14,25 @@ import (
"gioui.org/ui"
"gioui.org/ui/app"
"gioui.org/ui/paint"
"gioui.org/ui/f32"
"gioui.org/ui/gesture"
"gioui.org/ui/layout"
"gioui.org/ui/measure"
"gioui.org/ui/paint"
"gioui.org/ui/pointer"
"gioui.org/ui/text"
"golang.org/x/image/font/sfnt"
"golang.org/x/image/font/gofont/goregular"
"golang.org/x/image/font/sfnt"
)
var (
FPS int = 100
frames int64
frametime int64 // nanoseconds
FPS int = 100
frames int64
frametime int64 // nanoseconds
maxframetime int64
mux sync.Mutex
Profile bool = false
mux sync.Mutex
Profile bool = false
)
func NewButton(face text.Face, t string, c color.RGBA) giowrap.Clickable {
@@ -56,25 +56,27 @@ func main() {
a1 = ms.Alloc
runtime.GC()
runtime.ReadMemStats(ms)
log.Printf("Alloc: %d - %d = %d (%d per frame)", a1, ms.Alloc, a1 - ms.Alloc, (a1 - ms.Alloc) / (3 * uint64(FPS)))
log.Printf("Frametime: %d max Frametime: %d us\n", frametime / (frames * 1000), maxframetime / 1000)
log.Printf("Alloc: %d - %d = %d (%d per frame)", a1, ms.Alloc, a1-ms.Alloc, (a1-ms.Alloc)/(3*uint64(FPS)))
log.Printf("Frametime: %d max Frametime: %d us\n", frametime/(frames*1000), maxframetime/1000)
frames = 0
frametime = 0
maxframetime = 0
mux.Unlock()
}
}()
switch os.Args[1] {
case "", "main1":
log.Print("main1()")
go main1()
case "main2":
log.Print("main2()")
go main2()
default:
log.Fatal(`Usage:
if len(os.Args) > 1 {
switch os.Args[1] {
case "", "main1":
log.Print("main1()")
go main1()
case "main2":
log.Print("main2()")
go main2()
default:
log.Fatal(`Usage:
hello [main1|main2]
`)
}
}
app.Main()
}
@@ -86,11 +88,11 @@ func main1() {
log.Fatal("Cannot parse font.")
}
ctx := giowrap.NewContext(w)
t := time.NewTicker(time.Second/time.Duration(FPS))
e1 := giowrap.NewEditor("text 1",giowrap.Face(ctx.Faces.For(regular, ui.Sp(24))))
t := time.NewTicker(time.Second / time.Duration(FPS))
e1 := giowrap.NewEditor("text 1", giowrap.Face(ctx.Faces.For(regular, ui.Sp(24))))
e1.Focus()
e2 := giowrap.NewEditor("text 2",giowrap.Face(ctx.Faces.For(regular, ui.Sp(24))))
e2 := giowrap.NewEditor("text 2", giowrap.Face(ctx.Faces.For(regular, ui.Sp(24))))
f1 := giowrap.NewFlex(giowrap.Axis(layout.Vertical))
OuterInset := giowrap.NewInset(giowrap.Size(ui.Dp(10)))
@@ -118,7 +120,7 @@ func main1() {
case app.UpdateEvent:
ctx.Reset(e)
OuterInset(
f1(
f1(
e1,
giowrap.Flexible(5),
InnerInset(e2),
@@ -131,21 +133,27 @@ func main1() {
)).Layout(ctx)
ctx.Update()
if btn1.Clicked(ctx) {
log.Print("Clicked: " + e1.Text() )
log.Print("Clicked: " + e1.Text())
}
if btn2.Clicked(ctx) {
log.Print("Clicked: " + e2.Text() )
log.Print("Clicked: " + e2.Text())
}
}
dur := time.Since(stime).Nanoseconds()
mux.Lock()
frames = frames + 1
frametime = frametime + dur
if dur > maxframetime { maxframetime = dur }
if dur > maxframetime {
maxframetime = dur
}
mux.Unlock()
}
if profiled { continue }
if time.Since(startTime) < time.Second * 10 { continue }
if profiled {
continue
}
if time.Since(startTime) < time.Second*10 {
continue
}
if Profile {
profiled = true
f, err := os.Create("memprofile.pprof")
@@ -170,26 +178,26 @@ func main2() {
if err != nil {
log.Fatal("Cannot parse font.")
}
t := time.NewTicker(time.Second/time.Duration(FPS))
t := time.NewTicker(time.Second / time.Duration(FPS))
e1 := &text.Editor{
Face: faces.For(regular, ui.Sp(24)),
Face: faces.For(regular, ui.Sp(24)),
SingleLine: true,
}
e1.Focus()
e1.SetText("text 1")
e2 := &text.Editor{
Face: faces.For(regular, ui.Sp(24)),
Face: faces.For(regular, ui.Sp(24)),
SingleLine: true,
}
e2.Focus()
e2.SetText("text 2")
f1 := layout.Flex{ Axis: layout.Vertical }
f1 := layout.Flex{Axis: layout.Vertical}
OuterInset := layout.UniformInset(ui.Dp(10))
InnerInset := layout.UniformInset(ui.Dp(10))
f2 := layout.Flex{ Axis: layout.Horizontal }
f2 := layout.Flex{Axis: layout.Horizontal}
btn1 := text.Label{
Face: faces.For(regular, ui.Sp(24)),
@@ -240,7 +248,7 @@ func main2() {
cs = b1ins.Begin(c, ops, cs)
dims = btn1.Layout(ops, cs)
dims = b1ins.End(dims)
pointer.RectAreaOp{image.Rect(0,0,dims.Size.X,dims.Size.Y)}.Add(ops)
pointer.RectAreaOp{image.Rect(0, 0, dims.Size.X, dims.Size.Y)}.Add(ops)
click1.Add(ops)
bg1.Stop()
wi, h := float32(dims.Size.X), float32(dims.Size.Y)
@@ -257,7 +265,7 @@ func main2() {
cs = b2ins.Begin(c, ops, cs)
dims = btn2.Layout(ops, cs)
dims = b2ins.End(dims)
pointer.RectAreaOp{image.Rect(0,0,dims.Size.X,dims.Size.Y)}.Add(ops)
pointer.RectAreaOp{image.Rect(0, 0, dims.Size.X, dims.Size.Y)}.Add(ops)
click2.Add(ops)
bg2.Stop()
wi, h = float32(dims.Size.X), float32(dims.Size.Y)
@@ -274,12 +282,12 @@ func main2() {
w.Update(ops)
for ev, ok := click1.Next(q); ok; ev, ok = click1.Next(q) {
if ev.Type == gesture.TypeClick {
log.Print("Clicked: " + e1.Text() )
log.Print("Clicked: " + e1.Text())
}
}
for ev, ok := click2.Next(q); ok; ev, ok = click2.Next(q) {
if ev.Type == gesture.TypeClick {
log.Print("Clicked: " + e2.Text() )
log.Print("Clicked: " + e2.Text())
}
}
}
@@ -287,11 +295,17 @@ func main2() {
mux.Lock()
frames = frames + 1
frametime = frametime + dur
if dur > maxframetime { maxframetime = dur }
if dur > maxframetime {
maxframetime = dur
}
mux.Unlock()
}
if profiled { continue }
if time.Since(startTime) < time.Second * 10 { continue }
if profiled {
continue
}
if time.Since(startTime) < time.Second*10 {
continue
}
if Profile {
profiled = true
f, err := os.Create("memprofile.pprof")
@@ -306,4 +320,3 @@ func main2() {
}
}
}
+52 -49
View File
@@ -1,8 +1,8 @@
package main
import (
"image/color"
"fmt"
"image/color"
"log"
gio "git.wow.st/gmp/giowrap"
@@ -12,36 +12,36 @@ import (
"gioui.org/ui/layout"
"gioui.org/ui/text"
"golang.org/x/image/font/sfnt"
"golang.org/x/image/font/gofont/goregular"
"golang.org/x/image/font/sfnt"
)
var (
face text.Face
black color.RGBA = color.RGBA{ A: 0xff, R: 0x00, G: 0x00, B: 0x00 }
gray2 color.RGBA = color.RGBA{ A: 0xff, R: 0x70, G: 0x70, B: 0x70 }
gray1 color.RGBA = color.RGBA{ A: 0xff, R: 0x50, G: 0x50, B: 0x50 }
face text.Face
black color.RGBA = color.RGBA{A: 0xff, R: 0x00, G: 0x00, B: 0x00}
gray2 color.RGBA = color.RGBA{A: 0xff, R: 0xc0, G: 0xc0, B: 0xc0}
gray1 color.RGBA = color.RGBA{A: 0xff, R: 0x70, G: 0x70, B: 0x70}
)
type SLabel struct {
w gio.Clickable
bg *gio.Background
w gio.Clickable
bg *gio.Background
active *bool
}
func NewSLabel(t string, active *bool, lops ...gio.LabelOption) *SLabel {
ret := &SLabel{}
lops = append([]gio.LabelOption{gio.Face(face)},lops...)
lops = append([]gio.LabelOption{gio.Face(face)}, lops...)
lbl := gio.NewLabel(t, lops...)
bg := &gio.Background{
Color: gray2,
Color: gray2,
Radius: ui.Dp(4),
Inset: layout.UniformInset(ui.Dp(4)),
Inset: layout.UniformInset(ui.Dp(4)),
}
if *active {
bg.Color = gray1
}
l := gio.AsClickable(gio.Enclose(bg,lbl))
l := gio.AsClickable(gio.Enclose(bg, lbl))
ret.w = l
ret.bg = bg
ret.active = active
@@ -72,7 +72,7 @@ func main() {
}
func diffInsets(x, y app.Insets) bool {
return x.Top != y.Top ||
return x.Top != y.Top ||
x.Bottom != y.Bottom ||
x.Left != y.Left ||
x.Right != y.Right
@@ -87,7 +87,9 @@ func eventloop() {
regular, err := sfnt.Parse(goregular.TTF)
face = ctx.Faces.For(regular, ui.Sp(16))
if err != nil { log.Fatal("Cannot parse font.") }
if err != nil {
log.Fatal("Cannot parse font.")
}
sysbg := gio.NewBackground(gio.Color(black))
bg := gio.NewBackground(gio.Color(gray2))
@@ -108,51 +110,52 @@ func eventloop() {
labs[i] = make([]gio.Widget, numlabs)
sels[i] = make([]bool, numlabs)
for j := 0; j < numlabs; j++ {
labs[i][j] = NewSLabel(fmt.Sprintf("%03d",i * j), &sels[i][j])
labs[i][j] = NewSLabel(fmt.Sprintf("%03d", i*16+j), &sels[i][j])
}
}
sysinset := gio.NewInset(gio.Size(ui.Dp(0)))
resetSysinset := func(x app.Insets) {
sysinset = gio.NewInset(gio.Top(x.Top), gio.Bottom(x.Bottom),
gio.Left(x.Left), gio.Right(x.Right))
gio.Left(x.Left), gio.Right(x.Right))
}
var oldInsets app.Insets
for { select {
case e:= <-w.Events():
switch e := e.(type) {
case app.DestroyEvent:
return
case app.UpdateEvent:
ctx.Reset(e)
if diffInsets(e.Insets, oldInsets) {
oldInsets = e.Insets
resetSysinset(e.Insets)
for {
select {
case e := <-w.Events():
switch e := e.(type) {
case app.DestroyEvent:
return
case app.UpdateEvent:
ctx.Reset(e)
if diffInsets(e.Insets, oldInsets) {
oldInsets = e.Insets
resetSysinset(e.Insets)
}
sysbg(sysinset(bg(margin(
f1(lbar, f2(topbar, sh(
sv(labs[0]...),
sv(labs[1]...),
sv(labs[2]...),
sv(labs[3]...),
sv(labs[4]...),
sv(labs[5]...),
sv(labs[6]...),
sv(labs[7]...),
sv(labs[8]...),
sv(labs[9]...),
sv(labs[10]...),
sv(labs[11]...),
sv(labs[12]...),
sv(labs[13]...),
sv(labs[14]...),
sv(labs[15]...),
))))))).Layout(ctx)
ctx.Update()
}
sysbg(sysinset(bg(margin(
f1(lbar,f2(topbar,sh(
sv(labs[0]...),
sv(labs[1]...),
sv(labs[2]...),
sv(labs[3]...),
sv(labs[4]...),
sv(labs[5]...),
sv(labs[6]...),
sv(labs[7]...),
sv(labs[8]...),
sv(labs[9]...),
sv(labs[10]...),
sv(labs[11]...),
sv(labs[12]...),
sv(labs[13]...),
sv(labs[14]...),
sv(labs[15]...),
))))))).Layout(ctx)
ctx.Update()
}
}}
}
}