forked from joejulian/gio
layout: replace NewContext with a Queue argument to Context.Reset
We're about to reduce the scope of the Window.Queue by moving it to FrameEvent. As a consequence, Context can no longer rely on a Queue constant over its lifetime. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+2
-8
@@ -29,13 +29,6 @@ type Context struct {
|
|||||||
*op.Ops
|
*op.Ops
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewContext returns a Context for an event queue.
|
|
||||||
func NewContext(q event.Queue) *Context {
|
|
||||||
return &Context{
|
|
||||||
queue: q,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// layout a widget with a set of constraints and return its
|
// layout a widget with a set of constraints and return its
|
||||||
// dimensions. The widget dimensions are constrained and the previous
|
// dimensions. The widget dimensions are constrained and the previous
|
||||||
// constraints are restored after layout.
|
// constraints are restored after layout.
|
||||||
@@ -51,10 +44,11 @@ func ctxLayout(gtx *Context, cs Constraints, w Widget) Dimensions {
|
|||||||
|
|
||||||
// Reset the context. The constraints' minimum and maximum values are
|
// Reset the context. The constraints' minimum and maximum values are
|
||||||
// set to the size.
|
// set to the size.
|
||||||
func (c *Context) Reset(cfg system.Config, size image.Point) {
|
func (c *Context) Reset(q event.Queue, cfg system.Config, size image.Point) {
|
||||||
c.Constraints = RigidConstraints(size)
|
c.Constraints = RigidConstraints(size)
|
||||||
c.Dimensions = Dimensions{}
|
c.Dimensions = Dimensions{}
|
||||||
c.cfg = cfg
|
c.cfg = cfg
|
||||||
|
c.queue = q
|
||||||
if c.Ops == nil {
|
if c.Ops == nil {
|
||||||
c.Ops = new(op.Ops)
|
c.Ops = new(op.Ops)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
func ExampleInset() {
|
func ExampleInset() {
|
||||||
gtx := new(layout.Context)
|
gtx := new(layout.Context)
|
||||||
gtx.Reset(nil, image.Point{X: 100, Y: 100})
|
gtx.Reset(nil, nil, image.Point{X: 100, Y: 100})
|
||||||
// Loose constraints with no minimal size.
|
// Loose constraints with no minimal size.
|
||||||
gtx.Constraints.Width.Min = 0
|
gtx.Constraints.Width.Min = 0
|
||||||
gtx.Constraints.Height.Min = 0
|
gtx.Constraints.Height.Min = 0
|
||||||
@@ -33,7 +33,7 @@ func ExampleInset() {
|
|||||||
func ExampleDirection() {
|
func ExampleDirection() {
|
||||||
gtx := new(layout.Context)
|
gtx := new(layout.Context)
|
||||||
// Rigid constraints with both minimum and maximum set.
|
// Rigid constraints with both minimum and maximum set.
|
||||||
gtx.Reset(nil, image.Point{X: 100, Y: 100})
|
gtx.Reset(nil, nil, image.Point{X: 100, Y: 100})
|
||||||
|
|
||||||
layout.Center.Layout(gtx, func() {
|
layout.Center.Layout(gtx, func() {
|
||||||
// Lay out a 50x50 sized widget.
|
// Lay out a 50x50 sized widget.
|
||||||
@@ -50,7 +50,7 @@ func ExampleDirection() {
|
|||||||
|
|
||||||
func ExampleFlex() {
|
func ExampleFlex() {
|
||||||
gtx := new(layout.Context)
|
gtx := new(layout.Context)
|
||||||
gtx.Reset(nil, image.Point{X: 100, Y: 100})
|
gtx.Reset(nil, nil, image.Point{X: 100, Y: 100})
|
||||||
|
|
||||||
layout.Flex{}.Layout(gtx,
|
layout.Flex{}.Layout(gtx,
|
||||||
// Rigid 10x10 widget.
|
// Rigid 10x10 widget.
|
||||||
@@ -72,7 +72,7 @@ func ExampleFlex() {
|
|||||||
|
|
||||||
func ExampleStack() {
|
func ExampleStack() {
|
||||||
gtx := new(layout.Context)
|
gtx := new(layout.Context)
|
||||||
gtx.Reset(nil, image.Point{X: 100, Y: 100})
|
gtx.Reset(nil, nil, image.Point{X: 100, Y: 100})
|
||||||
gtx.Constraints.Width.Min = 0
|
gtx.Constraints.Width.Min = 0
|
||||||
gtx.Constraints.Height.Min = 0
|
gtx.Constraints.Height.Min = 0
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ func ExampleStack() {
|
|||||||
|
|
||||||
func ExampleList() {
|
func ExampleList() {
|
||||||
gtx := new(layout.Context)
|
gtx := new(layout.Context)
|
||||||
gtx.Reset(nil, image.Point{X: 100, Y: 100})
|
gtx.Reset(nil, nil, image.Point{X: 100, Y: 100})
|
||||||
|
|
||||||
// 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
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
func TestStack(t *testing.T) {
|
func TestStack(t *testing.T) {
|
||||||
var gtx Context
|
var gtx Context
|
||||||
gtx.Reset(nil, image.Point{X: 100, Y: 100})
|
gtx.Reset(nil, nil, image.Point{X: 100, Y: 100})
|
||||||
gtx.Constraints.Width.Min = 0
|
gtx.Constraints.Width.Min = 0
|
||||||
gtx.Constraints.Height.Min = 0
|
gtx.Constraints.Height.Min = 0
|
||||||
exp := image.Point{X: 60, Y: 70}
|
exp := image.Point{X: 60, Y: 70}
|
||||||
|
|||||||
Reference in New Issue
Block a user