all: rename c to gtx for *layout.Context parameters

Short like `ctx` but not as easily confused with context.Context
values.

Suggested by Larry Clapp.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-09-25 09:31:24 +02:00
parent 4d84f46edb
commit a89c6d1c33
8 changed files with 176 additions and 176 deletions
+2 -2
View File
@@ -68,12 +68,12 @@ const (
)
// Init must be called before Rigid or Flexible.
func (f *Flex) Init(c *Context) *Flex {
func (f *Flex) Init(gtx *Context) *Flex {
if f.mode > modeBegun {
panic("must End the current child before calling Init again")
}
f.mode = modeBegun
f.ctx = c
f.ctx = gtx
f.size = 0
f.rigidSize = 0
f.maxCross = 0
+19 -19
View File
@@ -133,12 +133,12 @@ type Inset struct {
type Align Direction
// Layout a widget.
func (in Inset) Layout(c *Context, w Widget) {
top := c.Px(in.Top)
right := c.Px(in.Right)
bottom := c.Px(in.Bottom)
left := c.Px(in.Left)
mcs := c.Constraints
func (in Inset) Layout(gtx *Context, w Widget) {
top := gtx.Px(in.Top)
right := gtx.Px(in.Right)
bottom := gtx.Px(in.Bottom)
left := gtx.Px(in.Left)
mcs := gtx.Constraints
mcs.Width.Min -= left + right
mcs.Width.Max -= left + right
if mcs.Width.Min < 0 {
@@ -156,12 +156,12 @@ func (in Inset) Layout(c *Context, w Widget) {
mcs.Height.Max = mcs.Height.Min
}
var stack ui.StackOp
stack.Push(c.Ops)
ui.TransformOp{}.Offset(toPointF(image.Point{X: left, Y: top})).Add(c.Ops)
dims := c.Layout(mcs, w)
stack.Push(gtx.Ops)
ui.TransformOp{}.Offset(toPointF(image.Point{X: left, Y: top})).Add(gtx.Ops)
dims := gtx.Layout(mcs, w)
stack.Pop()
c.Dimensions = Dimensions{
Size: c.Constraints.Constrain(dims.Size.Add(image.Point{X: right + left, Y: top + bottom})),
gtx.Dimensions = Dimensions{
Size: gtx.Constraints.Constrain(dims.Size.Add(image.Point{X: right + left, Y: top + bottom})),
Baseline: dims.Baseline + top,
}
}
@@ -173,14 +173,14 @@ func UniformInset(v ui.Value) Inset {
}
// Layout a widget.
func (a Align) Layout(c *Context, w Widget) {
func (a Align) Layout(gtx *Context, w Widget) {
var macro ui.MacroOp
macro.Record(c.Ops)
cs := c.Constraints
macro.Record(gtx.Ops)
cs := gtx.Constraints
mcs := cs
mcs.Width.Min = 0
mcs.Height.Min = 0
dims := c.Layout(mcs, w)
dims := gtx.Layout(mcs, w)
macro.Stop()
sz := dims.Size
if sz.X < cs.Width.Min {
@@ -203,11 +203,11 @@ func (a Align) Layout(c *Context, w Widget) {
p.Y = sz.Y - dims.Size.Y
}
var stack ui.StackOp
stack.Push(c.Ops)
ui.TransformOp{}.Offset(toPointF(p)).Add(c.Ops)
macro.Add(c.Ops)
stack.Push(gtx.Ops)
ui.TransformOp{}.Offset(toPointF(p)).Add(gtx.Ops)
macro.Add(gtx.Ops)
stack.Pop()
c.Dimensions = Dimensions{
gtx.Dimensions = Dimensions{
Size: sz,
Baseline: dims.Baseline,
}
+7 -7
View File
@@ -67,11 +67,11 @@ const (
const inf = 1e6
// Init prepares the list for iterating through its children with Next.
func (l *List) init(c *Context, len int) {
func (l *List) init(gtx *Context, len int) {
if l.more() {
panic("unfinished child")
}
l.ctx = c
l.ctx = gtx
l.maxSize = 0
l.children = l.children[:0]
l.len = len
@@ -84,20 +84,20 @@ func (l *List) init(c *Context, len int) {
l.offset = 0
l.first = len
}
l.macro.Record(c.Ops)
l.macro.Record(gtx.Ops)
l.next()
}
// Layout the List and return its dimensions.
func (l *List) Layout(c *Context, len int, w ListElement) {
for l.init(c, len); l.more(); l.next() {
func (l *List) Layout(gtx *Context, len int, w ListElement) {
for l.init(gtx, len); l.more(); l.next() {
cs := axisConstraints(l.Axis, Constraint{Max: inf}, axisCrossConstraint(l.Axis, l.ctx.Constraints))
i := l.index()
l.end(c.Layout(cs, func() {
l.end(gtx.Layout(cs, func() {
w(i)
}))
}
c.Dimensions = l.layout()
gtx.Dimensions = l.layout()
}
func (l *List) scrollToEnd() bool {
+2 -2
View File
@@ -29,8 +29,8 @@ type StackChild struct {
}
// Init a stack before calling Rigid or Expand.
func (s *Stack) Init(c *Context) *Stack {
s.ctx = c
func (s *Stack) Init(gtx *Context) *Stack {
s.ctx = gtx
s.constrained = true
s.maxSZ = image.Point{}
s.baseline = 0