Skip to content

Commit

Permalink
update gio version
Browse files Browse the repository at this point in the history
  • Loading branch information
eliasnaur committed Oct 5, 2019
1 parent eeb26d0 commit c96ddd8
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 45 deletions.
14 changes: 7 additions & 7 deletions centering.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ func main() {
go func() {
w := app.NewWindow()
regular, _ := sfnt.Parse(goregular.TTF)
var faces shape.Faces
family := &shape.Family{
Regular: regular,
}
gtx := &layout.Context{
Queue: w.Queue(),
}
for e := range w.Events() {
if e, ok := e.(app.UpdateEvent); ok {
gtx.Reset(&e.Config, e.Size)
faces.Reset()
f := faces.For(regular)
drawLabels(gtx, f, unit.Sp(72))
drawLabels(gtx, family, unit.Sp(72))
w.Update(gtx.Ops)
}
}
Expand All @@ -35,13 +35,13 @@ func main() {
}

// START OMIT
func drawLabels(gtx *layout.Context, face text.Face, size unit.Value) {
func drawLabels(gtx *layout.Context, family text.Family, size unit.Value) {
gtx.Constraints.Width.Min = 0
gtx.Constraints.Height.Min = 0
lbl := text.Label{Face: face, Size: size, Text: "I'm centered!"}
lbl := text.Label{Size: size, Text: "I'm centered!"}
var macro op.MacroOp // HLcenter
macro.Record(gtx.Ops) // Start recording // HLcenter
lbl.Layout(gtx)
lbl.Layout(gtx, family)
dimensions := gtx.Dimensions
macro.Stop() // End recording // HLcenter
op.TransformOp{}.Offset(f32.Point{
Expand Down
9 changes: 5 additions & 4 deletions editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ func main() {
w := app.NewWindow()
regular, _ := sfnt.Parse(goregular.TTF) // HLdraw
// START INIT OMIT
var faces shape.Faces // HLdraw
fml := &shape.Family{ // HLdraw
Regular: regular, // HLdraw
} // HLdraw
editor := &text.Editor{
Face: faces.For(regular),
Size: unit.Sp(52),
Family: fml,
Size: unit.Sp(52),
}
editor.SetText("Hello, Gophercon! Edit me.")
gtx := &layout.Context{
Expand All @@ -29,7 +31,6 @@ func main() {
for e := range w.Events() {
if e, ok := e.(app.UpdateEvent); ok {
gtx.Reset(&e.Config, e.Size) // HLdraw
faces.Reset() // HLdraw
// START OMIT
editor.Layout(gtx)
// END OMIT
Expand Down
2 changes: 1 addition & 1 deletion 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-20191005093250-404a065a0e03
gioui.org v0.0.0-20191005205337-1b445944119b
golang.org/x/image v0.0.0-20190703141733-d6a02ce849c9
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
gioui.org v0.0.0-20191005093250-404a065a0e03 h1:TB8lM0pzF2mOM/PQ5MVHBmVLeY+l+ziP/K3ItF3nDys=
gioui.org v0.0.0-20191005093250-404a065a0e03/go.mod h1:+CEjc9B//HrBfWsQOVxjCyih7HGIj3Pww1xFHVDZyyk=
gioui.org v0.0.0-20191005205337-1b445944119b h1:OABWy71Tu7Fe0NdwRcBPCHZrS5ORwZzrKGl189NcAoE=
gioui.org v0.0.0-20191005205337-1b445944119b/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=
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a h1:aYOabOQFp6Vj6W1F80affTUvO9UxmJRx8K0gsfABByQ=
Expand Down
12 changes: 6 additions & 6 deletions helloworld.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@ import (
"gioui.org/text"
"gioui.org/text/shape"
"gioui.org/unit"

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

// START OMIT
func main() {
go func() {
w := app.NewWindow()
regular, _ := sfnt.Parse(goregular.TTF)
var faces shape.Faces
w := app.NewWindow()
family := &shape.Family{
Regular: regular,
}
gtx := &layout.Context{
Queue: w.Queue(),
}
for e := range w.Events() {
if e, ok := e.(app.UpdateEvent); ok {
gtx.Reset(&e.Config, e.Size)
faces.Reset()

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

w.Update(gtx.Ops)
}
Expand Down
14 changes: 7 additions & 7 deletions list.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ func main() {
go func() {
w := app.NewWindow()
regular, _ := sfnt.Parse(goregular.TTF)
var faces shape.Faces
fml := &shape.Family{
Regular: regular,
}
// START INIT OMIT
list := &layout.List{
Axis: layout.Vertical,
Expand All @@ -29,9 +31,7 @@ func main() {
for e := range w.Events() {
if e, ok := e.(app.UpdateEvent); ok {
gtx.Reset(&e.Config, e.Size)
faces.Reset()
f := faces.For(regular)
drawList(gtx, list, f, unit.Sp(42))
drawList(gtx, list, fml, unit.Sp(42))
w.Update(gtx.Ops)
}
}
Expand All @@ -40,13 +40,13 @@ func main() {
}

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

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

Expand Down
18 changes: 9 additions & 9 deletions twolabels1.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ func main() {
go func() {
w := app.NewWindow()
regular, _ := sfnt.Parse(goregular.TTF)
var faces shape.Faces
fml := &shape.Family{
Regular: regular,
}
gtx := &layout.Context{
Queue: w.Queue(),
}
// START OMIT
for e := range w.Events() {
if e, ok := e.(app.UpdateEvent); ok {
gtx.Reset(&e.Config, e.Size)
faces.Reset()
f := faces.For(regular)
drawLabels(gtx, f, unit.Sp(122)) // HLdraw
drawLabels(gtx, fml, unit.Sp(122)) // HLdraw
w.Update(gtx.Ops)
}
}
Expand All @@ -35,11 +35,11 @@ func main() {
}

// START DRAW OMIT
func drawLabels(gtx *layout.Context, face text.Face, size unit.Value) {
lbl := text.Label{Face: face, Size: size, Text: "One label"}
lbl.Layout(gtx)
lbl2 := text.Label{Face: face, Text: "Another label"}
lbl2.Layout(gtx)
func drawLabels(gtx *layout.Context, fml text.Family, size unit.Value) {
lbl := text.Label{Size: size, Text: "One label"}
lbl.Layout(gtx, fml)
lbl2 := text.Label{Text: "Another label"}
lbl2.Layout(gtx, fml)
}

// END DRAW OMIT
18 changes: 9 additions & 9 deletions twolabels2.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ func main() {
go func() {
w := app.NewWindow()
regular, _ := sfnt.Parse(goregular.TTF)
var faces shape.Faces
fml := &shape.Family{
Regular: regular,
}
gtx := &layout.Context{
Queue: w.Queue(),
}
// START OMIT
for e := range w.Events() {
if e, ok := e.(app.UpdateEvent); ok {
gtx.Reset(&e.Config, e.Size)
faces.Reset()
f := faces.For(regular)
drawLabels(gtx, f, unit.Sp(122)) // HLdraw
drawLabels(gtx, fml, unit.Sp(122)) // HLdraw
w.Update(gtx.Ops)
}
}
Expand All @@ -37,16 +37,16 @@ func main() {
}

// START DRAW OMIT
func drawLabels(gtx *layout.Context, face text.Face, size unit.Value) {
func drawLabels(gtx *layout.Context, fml text.Family, size unit.Value) {
gtx.Constraints.Height.Min = 0 // HLdraw
lbl := text.Label{Face: face, Size: size, Text: "One label"}
lbl.Layout(gtx) // HLdraw
lbl := text.Label{Size: size, Text: "One label"}
lbl.Layout(gtx, fml) // HLdraw
dimensions := gtx.Dimensions
op.TransformOp{}.Offset(f32.Point{
Y: float32(dimensions.Size.Y), // HLdraw
}).Add(gtx.Ops)
lbl2 := text.Label{Face: face, Text: "Another label"}
lbl2.Layout(gtx)
lbl2 := text.Label{Text: "Another label"}
lbl2.Layout(gtx, fml)
}

// END DRAW OMIT

0 comments on commit c96ddd8

Please sign in to comment.