Skip to content

Commit

Permalink
updated gio version
Browse files Browse the repository at this point in the history
  • Loading branch information
eliasnaur committed Oct 12, 2019
1 parent 8411b6e commit bd0a77e
Show file tree
Hide file tree
Showing 14 changed files with 114 additions and 100 deletions.
6 changes: 3 additions & 3 deletions animatedclipping.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func main() {
w := app.NewWindow()
ops := new(op.Ops)
for e := range w.Events() {
if e, ok := e.(app.UpdateEvent); ok {
if e, ok := e.(app.FrameEvent); ok {
ops.Reset()

// START OMIT
Expand All @@ -38,7 +38,7 @@ func main() {
op.InvalidateOp{}.Add(ops) // HLdraw

// Submit operations to the window.
w.Update(ops) // HLdraw
e.Frame(ops) // HLdraw
// END OMIT
}
}
Expand All @@ -61,7 +61,7 @@ func roundRect(ops *op.Ops, width, height, se, sw, nw, ne float32) {
b.Cube(f32.Point{X: 0, Y: -nw * c}, f32.Point{X: nw - nw*c, Y: -nw}, f32.Point{X: nw, Y: -nw})
b.Line(f32.Point{X: w - ne - nw, Y: 0})
b.Cube(f32.Point{X: ne * c, Y: 0}, f32.Point{X: ne, Y: ne - ne*c}, f32.Point{X: ne, Y: ne})
b.End()
b.End().Add(ops)
}

// END RR OMIT
Expand Down
4 changes: 2 additions & 2 deletions animatedcolor.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func main() {
// START OMIT
ops := new(op.Ops) // HLops
for e := range w.Events() {
if e, ok := e.(app.UpdateEvent); ok {
if e, ok := e.(app.FrameEvent); ok {
ops.Reset() // HLops

color := animateColor(e.Config.Now())
Expand All @@ -32,7 +32,7 @@ func main() {
op.InvalidateOp{}.Add(ops) // HLops

// Submit operations.
w.Update(ops) // HLops
e.Frame(ops) // HLops
}
}
// END OMIT
Expand Down
25 changes: 12 additions & 13 deletions centering.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,41 @@ import (
"gioui.org/layout"
"gioui.org/op"
"gioui.org/text"
"gioui.org/text/shape"
"gioui.org/unit"
"gioui.org/text/opentype"
"gioui.org/widget/material"

"golang.org/x/image/font/gofont/goregular"
"golang.org/x/image/font/sfnt"
)

func main() {
go func() {
w := app.NewWindow()
regular, _ := sfnt.Parse(goregular.TTF)
family := &shape.Family{
Regular: regular,
}
shaper := new(text.Shaper)
shaper.Register(text.Font{}, opentype.Must(
opentype.Parse(goregular.TTF),
))
th := material.NewTheme(shaper)
gtx := &layout.Context{
Queue: w.Queue(),
}
for e := range w.Events() {
if e, ok := e.(app.UpdateEvent); ok {
if e, ok := e.(app.FrameEvent); ok {
gtx.Reset(&e.Config, e.Size)
drawLabels(gtx, family, unit.Sp(72))
w.Update(gtx.Ops)
drawLabels(gtx, th)
e.Frame(gtx.Ops)
}
}
}()
app.Main()
}

// START OMIT
func drawLabels(gtx *layout.Context, family text.Family, size unit.Value) {
func drawLabels(gtx *layout.Context, th *material.Theme) {
gtx.Constraints.Width.Min = 0
gtx.Constraints.Height.Min = 0
lbl := text.Label{Size: size, Text: "I'm centered!"}
var macro op.MacroOp // HLcenter
macro.Record(gtx.Ops) // Start recording // HLcenter
lbl.Layout(gtx, family)
th.H2("I'm centered!").Layout(gtx)
dimensions := gtx.Dimensions
macro.Stop() // End recording // HLcenter
op.TransformOp{}.Offset(f32.Point{
Expand Down
27 changes: 14 additions & 13 deletions editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,38 @@ import (
"gioui.org/app"
"gioui.org/layout"
"gioui.org/text"
"gioui.org/text/shape"
"gioui.org/text/opentype"
"gioui.org/unit"
"gioui.org/widget"
"gioui.org/widget/material"

"golang.org/x/image/font/gofont/goregular"
"golang.org/x/image/font/sfnt"
)

func main() {
go func() {
w := app.NewWindow()
regular, _ := sfnt.Parse(goregular.TTF) // HLdraw
shaper := new(text.Shaper)
shaper.Register(text.Font{}, opentype.Must(
opentype.Parse(goregular.TTF),
))
th := material.NewTheme(shaper)
// START INIT OMIT
fml := &shape.Family{ // HLdraw
Regular: regular, // HLdraw
} // HLdraw
editor := &text.Editor{
Family: fml,
Size: unit.Sp(52),
}
editor := new(widget.Editor)
editor.SetText("Hello, Gophercon! Edit me.")
gtx := &layout.Context{
Queue: w.Queue(),
}
// END INIT OMIT
for e := range w.Events() {
if e, ok := e.(app.UpdateEvent); ok {
if e, ok := e.(app.FrameEvent); ok {
gtx.Reset(&e.Config, e.Size) // HLdraw
// START OMIT
editor.Layout(gtx)
ed := th.Editor("Hint")
ed.Font.Size = unit.Sp(52)
ed.Layout(gtx, editor)
// END OMIT
w.Update(gtx.Ops) // HLdraw
e.Frame(gtx.Ops) // HLdraw
}
} // HLeventloop
}()
Expand Down
4 changes: 2 additions & 2 deletions flex.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ func main() {
Queue: w.Queue(),
}
for e := range w.Events() {
if e, ok := e.(app.UpdateEvent); ok {
if e, ok := e.(app.FrameEvent); ok {
gtx.Reset(&e.Config, e.Size)
drawRects(gtx)
w.Update(gtx.Ops)
e.Frame(gtx.Ops)
}
}
}()
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module gophercon2019
go 1.13

require (
gioui.org v0.0.0-20191006072302-e7fabcf77487
golang.org/x/image v0.0.0-20190703141733-d6a02ce849c9
gioui.org v0.0.0-20191012133950-48cf8af2f255
golang.org/x/image v0.0.0-20190802002840-cff245a6509b
)
27 changes: 23 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
gioui.org v0.0.0-20191006072302-e7fabcf77487 h1:JfNhjB3AMgJn0xIJWXao7JHHbLpdDSjuj1+pwan48Do=
gioui.org v0.0.0-20191006072302-e7fabcf77487/go.mod h1:+CEjc9B//HrBfWsQOVxjCyih7HGIj3Pww1xFHVDZyyk=
golang.org/x/image v0.0.0-20190703141733-d6a02ce849c9 h1:uc17S921SPw5F2gJo7slQ3aqvr2RwpL7eb3+DZncu3s=
golang.org/x/image v0.0.0-20190703141733-d6a02ce849c9/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
gioui.org v0.0.0-20191012133950-48cf8af2f255 h1:W5SExD9kB2pI1duCVvKuSFS6e8W1j+EZ8WLYru+SWKM=
gioui.org v0.0.0-20191012133950-48cf8af2f255/go.mod h1:KqFFi2Dq5gYA3FJ0sDOt8OBXoMsuxMtE8v2f0JExXAY=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20191002040644-a1355ae1e2c3 h1:n9HxLrNxWWtEb1cA950nuEEj3QnKbtsCJ6KjcgisNUs=
golang.org/x/exp v0.0.0-20191002040644-a1355ae1e2c3/go.mod h1:NOZ3BPKG0ec/BKJQgnvsSFpcKLM5xXVWnvZS97DWHgE=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b h1:+qEpEAPhDZ1o0x3tHzZTQDArnOixOzGD9HUJfcg0mb4=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a h1:aYOabOQFp6Vj6W1F80affTUvO9UxmJRx8K0gsfABByQ=
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190927191325-030b2cf1153e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
6 changes: 3 additions & 3 deletions gophercon-2019.slide
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ Only the app package depends on platform libraries

import "gioui.org/app"

var w app.Window
w.Update(&ops)
var e app.FrameEvent
e.Frame(&ops)


: In Gio, the basic building block is the operation. There are operations for clipping, transforming and drawing as well as ops for controlling input flow and requesting a redraw for animation.
Expand Down Expand Up @@ -302,7 +302,7 @@ Or to an outline
b.Line(...)
b.Quad(...) // Quadratic Beziér curve
b.Cube(...) // Cubic Beziér curve
b.End()
b.End().Add(ops)

: The major parts of any UI program are drawing, layout and input handling.

Expand Down
21 changes: 10 additions & 11 deletions helloworld.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,30 @@ import (
"gioui.org/app"
"gioui.org/layout"
"gioui.org/text"
"gioui.org/text/shape"
"gioui.org/unit"
"gioui.org/text/opentype"
"gioui.org/widget/material"
"golang.org/x/image/font/gofont/goregular"
"golang.org/x/image/font/sfnt"
)

// START OMIT
func main() {
go func() {
regular, _ := sfnt.Parse(goregular.TTF)
w := app.NewWindow()
family := &shape.Family{
Regular: regular,
}
shaper := new(text.Shaper)
shaper.Register(text.Font{}, opentype.Must(
opentype.Parse(goregular.TTF),
))
th := material.NewTheme(shaper)
gtx := &layout.Context{
Queue: w.Queue(),
}
for e := range w.Events() {
if e, ok := e.(app.UpdateEvent); ok {
if e, ok := e.(app.FrameEvent); ok {
gtx.Reset(&e.Config, e.Size)

lbl := text.Label{Size: unit.Sp(72), Text: "Hello, World!"} // HLdraw
lbl.Layout(gtx, family) // HLdraw
th.H1("Hello, World!").Layout(gtx) // HLdraw

w.Update(gtx.Ops)
e.Frame(gtx.Ops)
}
} // HLeventloop
}()
Expand Down
25 changes: 12 additions & 13 deletions list.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import (
"gioui.org/app"
"gioui.org/layout"
"gioui.org/text"
"gioui.org/text/shape"
"gioui.org/unit"
"gioui.org/text/opentype"
"gioui.org/widget/material"

"golang.org/x/image/font/gofont/goregular"
"golang.org/x/image/font/sfnt"
)

func main() {
go func() {
w := app.NewWindow()
regular, _ := sfnt.Parse(goregular.TTF)
fml := &shape.Family{
Regular: regular,
}
shaper := new(text.Shaper)
shaper.Register(text.Font{}, opentype.Must(
opentype.Parse(goregular.TTF),
))
th := material.NewTheme(shaper)
// START INIT OMIT
list := &layout.List{
Axis: layout.Vertical,
Expand All @@ -29,24 +29,23 @@ func main() {
}
// END INIT OMIT
for e := range w.Events() {
if e, ok := e.(app.UpdateEvent); ok {
if e, ok := e.(app.FrameEvent); ok {
gtx.Reset(&e.Config, e.Size)
drawList(gtx, list, fml, unit.Sp(42))
w.Update(gtx.Ops)
drawList(gtx, list, th)
e.Frame(gtx.Ops)
}
}
}()
app.Main()
}

// START OMIT
func drawList(gtx *layout.Context, list *layout.List, fml text.Family, size unit.Value) {
func drawList(gtx *layout.Context, list *layout.List, th *material.Theme) {
const n = 1e6
list.Layout(gtx, n, func(i int) {
txt := fmt.Sprintf("List element #%d", i)

lbl := text.Label{Size: size, Text: txt}
lbl.Layout(gtx, fml)
th.H3(txt).Layout(gtx)
})
}

Expand Down
4 changes: 2 additions & 2 deletions pointer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ func main() {
button := new(Button)
ops := new(op.Ops) // HLops
for e := range w.Events() {
if _, ok := e.(app.UpdateEvent); ok {
if e, ok := e.(app.FrameEvent); ok {
ops.Reset()
queue := w.Queue() // HLqueue
button.Layout(queue, ops)
w.Update(ops)
e.Frame(ops)
}
}
}()
Expand Down
4 changes: 2 additions & 2 deletions stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ func main() {
Queue: w.Queue(),
}
for e := range w.Events() {
if e, ok := e.(app.UpdateEvent); ok {
if e, ok := e.(app.FrameEvent); ok {
gtx.Reset(&e.Config, e.Size)
drawRects(gtx)
w.Update(gtx.Ops)
e.Frame(gtx.Ops)
}
}
}()
Expand Down
Loading

0 comments on commit bd0a77e

Please sign in to comment.