2019-08-23 10:46:59 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2019-08-27 09:24:30 -04:00
|
|
|
"image/color"
|
2019-08-23 10:46:59 -04:00
|
|
|
"log"
|
|
|
|
|
|
|
|
gio "git.wow.st/gmp/giowrap"
|
|
|
|
|
|
|
|
"gioui.org/ui"
|
|
|
|
"gioui.org/ui/app"
|
|
|
|
"gioui.org/ui/layout"
|
|
|
|
"gioui.org/ui/text"
|
|
|
|
|
|
|
|
"golang.org/x/image/font/gofont/goregular"
|
2019-08-27 09:24:30 -04:00
|
|
|
"golang.org/x/image/font/sfnt"
|
2019-08-23 10:46:59 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2019-08-27 09:24:30 -04:00
|
|
|
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}
|
2019-08-23 10:46:59 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type SLabel struct {
|
2019-08-27 09:24:30 -04:00
|
|
|
w gio.Clickable
|
|
|
|
bg *gio.Background
|
2019-08-23 10:46:59 -04:00
|
|
|
active *bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewSLabel(t string, active *bool, lops ...gio.LabelOption) *SLabel {
|
|
|
|
ret := &SLabel{}
|
2019-08-27 09:24:30 -04:00
|
|
|
lops = append([]gio.LabelOption{gio.Face(face)}, lops...)
|
2019-08-23 10:46:59 -04:00
|
|
|
lbl := gio.NewLabel(t, lops...)
|
|
|
|
bg := &gio.Background{
|
2019-08-27 09:24:30 -04:00
|
|
|
Color: gray2,
|
2019-08-23 10:46:59 -04:00
|
|
|
Radius: ui.Dp(4),
|
2019-08-27 09:24:30 -04:00
|
|
|
Inset: layout.UniformInset(ui.Dp(4)),
|
2019-08-23 10:46:59 -04:00
|
|
|
}
|
|
|
|
if *active {
|
|
|
|
bg.Color = gray1
|
|
|
|
}
|
2019-08-27 09:24:30 -04:00
|
|
|
l := gio.AsClickable(gio.Enclose(bg, lbl))
|
2019-08-23 10:46:59 -04:00
|
|
|
ret.w = l
|
|
|
|
ret.bg = bg
|
|
|
|
ret.active = active
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *SLabel) Layout(ctx *gio.Context) {
|
|
|
|
if *w.active {
|
|
|
|
w.bg.Color = gray1
|
|
|
|
} else {
|
|
|
|
w.bg.Color = gray2
|
|
|
|
}
|
|
|
|
w.w.Layout(ctx)
|
|
|
|
if w.w.Clicked(ctx) {
|
|
|
|
if *w.active {
|
|
|
|
*w.active = false
|
|
|
|
} else {
|
|
|
|
*w.active = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
log.Print("Staring event loop")
|
|
|
|
go eventloop()
|
|
|
|
app.Main()
|
|
|
|
log.Print("App closed")
|
|
|
|
}
|
|
|
|
|
|
|
|
func diffInsets(x, y app.Insets) bool {
|
2019-08-27 09:24:30 -04:00
|
|
|
return x.Top != y.Top ||
|
2019-08-23 10:46:59 -04:00
|
|
|
x.Bottom != y.Bottom ||
|
|
|
|
x.Left != y.Left ||
|
|
|
|
x.Right != y.Right
|
|
|
|
}
|
|
|
|
|
|
|
|
func eventloop() {
|
|
|
|
w := app.NewWindow(
|
2019-08-23 11:21:35 -04:00
|
|
|
app.WithWidth(ui.Dp(400)),
|
2019-08-23 10:46:59 -04:00
|
|
|
app.WithHeight(ui.Dp(400)),
|
|
|
|
app.WithTitle("Tickets"))
|
|
|
|
ctx := gio.NewContext(w)
|
|
|
|
|
|
|
|
regular, err := sfnt.Parse(goregular.TTF)
|
|
|
|
face = ctx.Faces.For(regular, ui.Sp(16))
|
2019-08-27 09:24:30 -04:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal("Cannot parse font.")
|
|
|
|
}
|
2019-08-23 10:46:59 -04:00
|
|
|
|
|
|
|
sysbg := gio.NewBackground(gio.Color(black))
|
|
|
|
bg := gio.NewBackground(gio.Color(gray2))
|
|
|
|
|
|
|
|
margin := gio.NewInset(gio.Size(ui.Dp(10)))
|
2019-08-23 11:21:35 -04:00
|
|
|
f1 := gio.NewFlex(gio.Axis(layout.Horizontal))
|
|
|
|
lbar := gio.NewLabel(" ", gio.Face(face))
|
|
|
|
f2 := gio.NewFlex(gio.Axis(layout.Vertical))
|
|
|
|
topbar := gio.NewLabel("Scroll X and Y. Click to select", gio.Face(face))
|
|
|
|
|
2019-08-23 10:46:59 -04:00
|
|
|
sh := gio.HScroll(gio.NewFlex(gio.Axis(layout.Horizontal)))
|
|
|
|
sv := gio.VScroll(gio.NewFlex(gio.Axis(layout.Vertical)))
|
2019-08-23 11:21:35 -04:00
|
|
|
|
2019-08-23 10:46:59 -04:00
|
|
|
numlabs := 50
|
|
|
|
labs := make([][]gio.Widget, numlabs)
|
|
|
|
sels := make([][]bool, numlabs)
|
|
|
|
for i := 0; i < 16; i++ {
|
|
|
|
labs[i] = make([]gio.Widget, numlabs)
|
|
|
|
sels[i] = make([]bool, numlabs)
|
|
|
|
for j := 0; j < numlabs; j++ {
|
2019-08-27 09:24:30 -04:00
|
|
|
labs[i][j] = NewSLabel(fmt.Sprintf("%03d", i*16+j), &sels[i][j])
|
2019-08-23 10:46:59 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sysinset := gio.NewInset(gio.Size(ui.Dp(0)))
|
|
|
|
resetSysinset := func(x app.Insets) {
|
|
|
|
sysinset = gio.NewInset(gio.Top(x.Top), gio.Bottom(x.Bottom),
|
2019-08-27 09:24:30 -04:00
|
|
|
gio.Left(x.Left), gio.Right(x.Right))
|
2019-08-23 10:46:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
var oldInsets app.Insets
|
|
|
|
|
2019-08-27 09:24:30 -04:00
|
|
|
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()
|
2019-08-23 10:46:59 -04:00
|
|
|
}
|
|
|
|
}
|
2019-08-27 09:24:30 -04:00
|
|
|
}
|
2019-08-23 10:46:59 -04:00
|
|
|
}
|