all: rename more *layout.Context names to gtx

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-09-25 09:43:15 +02:00
parent a89c6d1c33
commit 9c33550644
4 changed files with 43 additions and 43 deletions
+4 -4
View File
@@ -77,7 +77,7 @@ func initProfiling() {
func (a *App) run() error { func (a *App) run() error {
a.ui.profiling = *stats a.ui.profiling = *stats
c := &layout.Context{ gtx := &layout.Context{
Queue: a.w.Queue(), Queue: a.w.Queue(),
} }
for { for {
@@ -127,9 +127,9 @@ func (a *App) run() error {
} }
} }
case app.UpdateEvent: case app.UpdateEvent:
c.Reset(&e.Config, layout.RigidConstraints(e.Size)) gtx.Reset(&e.Config, layout.RigidConstraints(e.Size))
a.ui.Layout(c) a.ui.Layout(gtx)
a.w.Update(c.Ops) a.w.Update(gtx.Ops)
} }
} }
} }
+3 -3
View File
@@ -19,12 +19,12 @@ func BenchmarkUI(b *testing.B) {
fetch := func(_ string) {} fetch := func(_ string) {}
u := newUI(fetch) u := newUI(fetch)
cfg := new(config) cfg := new(config)
c := &layout.Context{ gtx := &layout.Context{
Queue: new(queue), Queue: new(queue),
} }
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
c.Reset(cfg, layout.RigidConstraints(image.Point{800, 600})) gtx.Reset(cfg, layout.RigidConstraints(image.Point{800, 600}))
u.Layout(c) u.Layout(gtx)
} }
} }
+7 -7
View File
@@ -13,17 +13,17 @@ in an implicit Context to keep the Widget declaration short.
For example, to add space above a widget: For example, to add space above a widget:
c := &layout.Context{...} gtx := &layout.Context{...}
c.Reset(...) gtx.Reset(...)
// Configure a top inset. // Configure a top inset.
inset := layout.Inset{Top: ui.Dp(8), ...} inset := layout.Inset{Top: ui.Dp(8), ...}
// Use the inset to lay out a widget. // Use the inset to lay out a widget.
inset.Layout(c, func() { inset.Layout(gtx, func() {
// Lay out widget and determine its size given the constraints. // Lay out widget and determine its size given the constraints.
... ...
dims := layout.Dimensions{...} dims := layout.Dimensions{...}
c.Dimensions = dims gtx.Dimensions = dims
}) })
Note that the example does not generate any garbage even though the Note that the example does not generate any garbage even though the
@@ -37,10 +37,10 @@ be created from a few generic layouts.
This example both aligns and insets a child: This example both aligns and insets a child:
inset := layout.Inset{...} inset := layout.Inset{...}
inset.Layout(c, func() { inset.Layout(gtx, func() {
align := layout.Align(...) align := layout.Align(...)
align.Layout(c, func() { align.Layout(gtx, func() {
widget.Layout(c, ...) widget.Layout(gtx, ...)
}) })
}) })
+29 -29
View File
@@ -17,22 +17,22 @@ var q queue
var cfg = new(config) var cfg = new(config)
func ExampleInset() { func ExampleInset() {
c := &layout.Context{Queue: q} gtx := &layout.Context{Queue: q}
// Loose constraints with no minimal size. // Loose constraints with no minimal size.
var cs layout.Constraints var cs layout.Constraints
cs.Width.Max = 100 cs.Width.Max = 100
cs.Height.Max = 100 cs.Height.Max = 100
c.Reset(cfg, cs) gtx.Reset(cfg, cs)
// Inset all edges by 10. // Inset all edges by 10.
inset := layout.UniformInset(ui.Dp(10)) inset := layout.UniformInset(ui.Dp(10))
inset.Layout(c, func() { inset.Layout(gtx, func() {
// Lay out a 50x50 sized widget. // Lay out a 50x50 sized widget.
layoutWidget(c, 50, 50) layoutWidget(gtx, 50, 50)
fmt.Println(c.Dimensions.Size) fmt.Println(gtx.Dimensions.Size)
}) })
fmt.Println(c.Dimensions.Size) fmt.Println(gtx.Dimensions.Size)
// Output: // Output:
// (50,50) // (50,50)
@@ -40,19 +40,19 @@ func ExampleInset() {
} }
func ExampleAlign() { func ExampleAlign() {
c := &layout.Context{Queue: q} gtx := &layout.Context{Queue: q}
// Rigid constraints with both minimum and maximum set. // Rigid constraints with both minimum and maximum set.
cs := layout.RigidConstraints(image.Point{X: 100, Y: 100}) cs := layout.RigidConstraints(image.Point{X: 100, Y: 100})
c.Reset(cfg, cs) gtx.Reset(cfg, cs)
align := layout.Align(layout.Center) align := layout.Align(layout.Center)
align.Layout(c, func() { align.Layout(gtx, func() {
// Lay out a 50x50 sized widget. // Lay out a 50x50 sized widget.
layoutWidget(c, 50, 50) layoutWidget(gtx, 50, 50)
fmt.Println(c.Dimensions.Size) fmt.Println(gtx.Dimensions.Size)
}) })
fmt.Println(c.Dimensions.Size) fmt.Println(gtx.Dimensions.Size)
// Output: // Output:
// (50,50) // (50,50)
@@ -60,23 +60,23 @@ func ExampleAlign() {
} }
func ExampleFlex() { func ExampleFlex() {
c := &layout.Context{Queue: q} gtx := &layout.Context{Queue: q}
cs := layout.RigidConstraints(image.Point{X: 100, Y: 100}) cs := layout.RigidConstraints(image.Point{X: 100, Y: 100})
c.Reset(cfg, cs) gtx.Reset(cfg, cs)
flex := layout.Flex{} flex := layout.Flex{}
flex.Init(c) flex.Init(gtx)
// Rigid 10x10 widget. // Rigid 10x10 widget.
child1 := flex.Rigid(func() { child1 := flex.Rigid(func() {
fmt.Printf("Rigid: %v\n", c.Constraints.Width) fmt.Printf("Rigid: %v\n", gtx.Constraints.Width)
layoutWidget(c, 10, 10) layoutWidget(gtx, 10, 10)
}) })
// Child with 50% space allowance. // Child with 50% space allowance.
child2 := flex.Flexible(0.5, func() { child2 := flex.Flexible(0.5, func() {
fmt.Printf("50%%: %v\n", c.Constraints.Width) fmt.Printf("50%%: %v\n", gtx.Constraints.Width)
layoutWidget(c, 10, 10) layoutWidget(gtx, 10, 10)
}) })
flex.Layout(child1, child2) flex.Layout(child1, child2)
@@ -87,22 +87,22 @@ func ExampleFlex() {
} }
func ExampleStack() { func ExampleStack() {
c := &layout.Context{Queue: q} gtx := &layout.Context{Queue: q}
cs := layout.RigidConstraints(image.Point{X: 100, Y: 100}) cs := layout.RigidConstraints(image.Point{X: 100, Y: 100})
c.Reset(cfg, cs) gtx.Reset(cfg, cs)
stack := layout.Stack{} stack := layout.Stack{}
stack.Init(c) stack.Init(gtx)
// Rigid 50x50 widget. // Rigid 50x50 widget.
child1 := stack.Rigid(func() { child1 := stack.Rigid(func() {
layoutWidget(c, 50, 50) layoutWidget(gtx, 50, 50)
}) })
// Force widget to the same size as the first. // Force widget to the same size as the first.
child2 := stack.Expand(func() { child2 := stack.Expand(func() {
fmt.Printf("Expand: %v\n", c.Constraints) fmt.Printf("Expand: %v\n", gtx.Constraints)
layoutWidget(c, 10, 10) layoutWidget(gtx, 10, 10)
}) })
stack.Layout(child1, child2) stack.Layout(child1, child2)
@@ -112,18 +112,18 @@ func ExampleStack() {
} }
func ExampleList() { func ExampleList() {
c := &layout.Context{Queue: q} gtx := &layout.Context{Queue: q}
cs := layout.RigidConstraints(image.Point{X: 100, Y: 100}) cs := layout.RigidConstraints(image.Point{X: 100, Y: 100})
c.Reset(cfg, cs) gtx.Reset(cfg, cs)
// The list is 1e6 elements, but only 5 fit the constraints. // The list is 1e6 elements, but only 5 fit the constraints.
const listLen = 1e6 const listLen = 1e6
var list layout.List var list layout.List
count := 0 count := 0
list.Layout(c, listLen, func(i int) { list.Layout(gtx, listLen, func(i int) {
count++ count++
layoutWidget(c, 20, 20) layoutWidget(gtx, 20, 20)
}) })
fmt.Println(count) fmt.Println(count)