layout: take a size, not constraints in Context.Reset

Taking a constraint in Reset smells too much of a layout operation,
whereas a size is simpler and only serves to set the context constraints
to something sensible.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-10-02 15:31:52 +02:00
parent b0e7b165b6
commit e031308172
2 changed files with 11 additions and 15 deletions
+4 -3
View File
@@ -102,9 +102,10 @@ func (s *Context) Layout(cs Constraints, w Widget) Dimensions {
return s.Dimensions
}
// Reset the context.
func (c *Context) Reset(cfg Config, cs Constraints) {
c.Constraints = cs
// Reset the context. The constraints' minimum and maximum values are
// set to the size.
func (c *Context) Reset(cfg Config, size image.Point) {
c.Constraints = RigidConstraints(size)
c.Dimensions = Dimensions{}
c.Config = cfg
if c.Ops == nil {
+7 -12
View File
@@ -19,11 +19,10 @@ var cfg = new(config)
func ExampleInset() {
gtx := &layout.Context{Queue: q}
gtx.Reset(cfg, image.Point{X: 100, Y: 100})
// Loose constraints with no minimal size.
var cs layout.Constraints
cs.Width.Max = 100
cs.Height.Max = 100
gtx.Reset(cfg, cs)
gtx.Constraints.Width.Min = 0
gtx.Constraints.Height.Min = 0
// Inset all edges by 10.
inset := layout.UniformInset(unit.Dp(10))
@@ -43,8 +42,7 @@ func ExampleInset() {
func ExampleAlign() {
gtx := &layout.Context{Queue: q}
// Rigid constraints with both minimum and maximum set.
cs := layout.RigidConstraints(image.Point{X: 100, Y: 100})
gtx.Reset(cfg, cs)
gtx.Reset(cfg, image.Point{X: 100, Y: 100})
align := layout.Align(layout.Center)
align.Layout(gtx, func() {
@@ -62,8 +60,7 @@ func ExampleAlign() {
func ExampleFlex() {
gtx := &layout.Context{Queue: q}
cs := layout.RigidConstraints(image.Point{X: 100, Y: 100})
gtx.Reset(cfg, cs)
gtx.Reset(cfg, image.Point{X: 100, Y: 100})
flex := layout.Flex{}
flex.Init(gtx)
@@ -89,8 +86,7 @@ func ExampleFlex() {
func ExampleStack() {
gtx := &layout.Context{Queue: q}
cs := layout.RigidConstraints(image.Point{X: 100, Y: 100})
gtx.Reset(cfg, cs)
gtx.Reset(cfg, image.Point{X: 100, Y: 100})
stack := layout.Stack{}
stack.Init(gtx)
@@ -114,8 +110,7 @@ func ExampleStack() {
func ExampleList() {
gtx := &layout.Context{Queue: q}
cs := layout.RigidConstraints(image.Point{X: 100, Y: 100})
gtx.Reset(cfg, cs)
gtx.Reset(cfg, image.Point{X: 100, Y: 100})
// The list is 1e6 elements, but only 5 fit the constraints.
const listLen = 1e6