mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-02 16:06:19 +00:00
all: rename more *layout.Context names to gtx
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -77,7 +77,7 @@ func initProfiling() {
|
||||
|
||||
func (a *App) run() error {
|
||||
a.ui.profiling = *stats
|
||||
c := &layout.Context{
|
||||
gtx := &layout.Context{
|
||||
Queue: a.w.Queue(),
|
||||
}
|
||||
for {
|
||||
@@ -127,9 +127,9 @@ func (a *App) run() error {
|
||||
}
|
||||
}
|
||||
case app.UpdateEvent:
|
||||
c.Reset(&e.Config, layout.RigidConstraints(e.Size))
|
||||
a.ui.Layout(c)
|
||||
a.w.Update(c.Ops)
|
||||
gtx.Reset(&e.Config, layout.RigidConstraints(e.Size))
|
||||
a.ui.Layout(gtx)
|
||||
a.w.Update(gtx.Ops)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,12 +19,12 @@ func BenchmarkUI(b *testing.B) {
|
||||
fetch := func(_ string) {}
|
||||
u := newUI(fetch)
|
||||
cfg := new(config)
|
||||
c := &layout.Context{
|
||||
gtx := &layout.Context{
|
||||
Queue: new(queue),
|
||||
}
|
||||
for i := 0; i < b.N; i++ {
|
||||
c.Reset(cfg, layout.RigidConstraints(image.Point{800, 600}))
|
||||
u.Layout(c)
|
||||
gtx.Reset(cfg, layout.RigidConstraints(image.Point{800, 600}))
|
||||
u.Layout(gtx)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -13,17 +13,17 @@ in an implicit Context to keep the Widget declaration short.
|
||||
|
||||
For example, to add space above a widget:
|
||||
|
||||
c := &layout.Context{...}
|
||||
c.Reset(...)
|
||||
gtx := &layout.Context{...}
|
||||
gtx.Reset(...)
|
||||
|
||||
// Configure a top inset.
|
||||
inset := layout.Inset{Top: ui.Dp(8), ...}
|
||||
// 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.
|
||||
...
|
||||
dims := layout.Dimensions{...}
|
||||
c.Dimensions = dims
|
||||
gtx.Dimensions = dims
|
||||
})
|
||||
|
||||
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:
|
||||
|
||||
inset := layout.Inset{...}
|
||||
inset.Layout(c, func() {
|
||||
inset.Layout(gtx, func() {
|
||||
align := layout.Align(...)
|
||||
align.Layout(c, func() {
|
||||
widget.Layout(c, ...)
|
||||
align.Layout(gtx, func() {
|
||||
widget.Layout(gtx, ...)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
+29
-29
@@ -17,22 +17,22 @@ var q queue
|
||||
var cfg = new(config)
|
||||
|
||||
func ExampleInset() {
|
||||
c := &layout.Context{Queue: q}
|
||||
gtx := &layout.Context{Queue: q}
|
||||
// Loose constraints with no minimal size.
|
||||
var cs layout.Constraints
|
||||
cs.Width.Max = 100
|
||||
cs.Height.Max = 100
|
||||
c.Reset(cfg, cs)
|
||||
gtx.Reset(cfg, cs)
|
||||
|
||||
// Inset all edges by 10.
|
||||
inset := layout.UniformInset(ui.Dp(10))
|
||||
inset.Layout(c, func() {
|
||||
inset.Layout(gtx, func() {
|
||||
// Lay out a 50x50 sized widget.
|
||||
layoutWidget(c, 50, 50)
|
||||
fmt.Println(c.Dimensions.Size)
|
||||
layoutWidget(gtx, 50, 50)
|
||||
fmt.Println(gtx.Dimensions.Size)
|
||||
})
|
||||
|
||||
fmt.Println(c.Dimensions.Size)
|
||||
fmt.Println(gtx.Dimensions.Size)
|
||||
|
||||
// Output:
|
||||
// (50,50)
|
||||
@@ -40,19 +40,19 @@ func ExampleInset() {
|
||||
}
|
||||
|
||||
func ExampleAlign() {
|
||||
c := &layout.Context{Queue: q}
|
||||
gtx := &layout.Context{Queue: q}
|
||||
// Rigid constraints with both minimum and maximum set.
|
||||
cs := layout.RigidConstraints(image.Point{X: 100, Y: 100})
|
||||
c.Reset(cfg, cs)
|
||||
gtx.Reset(cfg, cs)
|
||||
|
||||
align := layout.Align(layout.Center)
|
||||
align.Layout(c, func() {
|
||||
align.Layout(gtx, func() {
|
||||
// Lay out a 50x50 sized widget.
|
||||
layoutWidget(c, 50, 50)
|
||||
fmt.Println(c.Dimensions.Size)
|
||||
layoutWidget(gtx, 50, 50)
|
||||
fmt.Println(gtx.Dimensions.Size)
|
||||
})
|
||||
|
||||
fmt.Println(c.Dimensions.Size)
|
||||
fmt.Println(gtx.Dimensions.Size)
|
||||
|
||||
// Output:
|
||||
// (50,50)
|
||||
@@ -60,23 +60,23 @@ func ExampleAlign() {
|
||||
}
|
||||
|
||||
func ExampleFlex() {
|
||||
c := &layout.Context{Queue: q}
|
||||
gtx := &layout.Context{Queue: q}
|
||||
cs := layout.RigidConstraints(image.Point{X: 100, Y: 100})
|
||||
c.Reset(cfg, cs)
|
||||
gtx.Reset(cfg, cs)
|
||||
|
||||
flex := layout.Flex{}
|
||||
flex.Init(c)
|
||||
flex.Init(gtx)
|
||||
|
||||
// Rigid 10x10 widget.
|
||||
child1 := flex.Rigid(func() {
|
||||
fmt.Printf("Rigid: %v\n", c.Constraints.Width)
|
||||
layoutWidget(c, 10, 10)
|
||||
fmt.Printf("Rigid: %v\n", gtx.Constraints.Width)
|
||||
layoutWidget(gtx, 10, 10)
|
||||
})
|
||||
|
||||
// Child with 50% space allowance.
|
||||
child2 := flex.Flexible(0.5, func() {
|
||||
fmt.Printf("50%%: %v\n", c.Constraints.Width)
|
||||
layoutWidget(c, 10, 10)
|
||||
fmt.Printf("50%%: %v\n", gtx.Constraints.Width)
|
||||
layoutWidget(gtx, 10, 10)
|
||||
})
|
||||
|
||||
flex.Layout(child1, child2)
|
||||
@@ -87,22 +87,22 @@ func ExampleFlex() {
|
||||
}
|
||||
|
||||
func ExampleStack() {
|
||||
c := &layout.Context{Queue: q}
|
||||
gtx := &layout.Context{Queue: q}
|
||||
cs := layout.RigidConstraints(image.Point{X: 100, Y: 100})
|
||||
c.Reset(cfg, cs)
|
||||
gtx.Reset(cfg, cs)
|
||||
|
||||
stack := layout.Stack{}
|
||||
stack.Init(c)
|
||||
stack.Init(gtx)
|
||||
|
||||
// Rigid 50x50 widget.
|
||||
child1 := stack.Rigid(func() {
|
||||
layoutWidget(c, 50, 50)
|
||||
layoutWidget(gtx, 50, 50)
|
||||
})
|
||||
|
||||
// Force widget to the same size as the first.
|
||||
child2 := stack.Expand(func() {
|
||||
fmt.Printf("Expand: %v\n", c.Constraints)
|
||||
layoutWidget(c, 10, 10)
|
||||
fmt.Printf("Expand: %v\n", gtx.Constraints)
|
||||
layoutWidget(gtx, 10, 10)
|
||||
})
|
||||
|
||||
stack.Layout(child1, child2)
|
||||
@@ -112,18 +112,18 @@ func ExampleStack() {
|
||||
}
|
||||
|
||||
func ExampleList() {
|
||||
c := &layout.Context{Queue: q}
|
||||
gtx := &layout.Context{Queue: q}
|
||||
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.
|
||||
const listLen = 1e6
|
||||
|
||||
var list layout.List
|
||||
count := 0
|
||||
list.Layout(c, listLen, func(i int) {
|
||||
list.Layout(gtx, listLen, func(i int) {
|
||||
count++
|
||||
layoutWidget(c, 20, 20)
|
||||
layoutWidget(gtx, 20, 20)
|
||||
})
|
||||
|
||||
fmt.Println(count)
|
||||
|
||||
Reference in New Issue
Block a user