mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 18:35:34 +00:00
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:
+4
-3
@@ -102,9 +102,10 @@ func (s *Context) Layout(cs Constraints, w Widget) Dimensions {
|
|||||||
return s.Dimensions
|
return s.Dimensions
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset the context.
|
// Reset the context. The constraints' minimum and maximum values are
|
||||||
func (c *Context) Reset(cfg Config, cs Constraints) {
|
// set to the size.
|
||||||
c.Constraints = cs
|
func (c *Context) Reset(cfg Config, size image.Point) {
|
||||||
|
c.Constraints = RigidConstraints(size)
|
||||||
c.Dimensions = Dimensions{}
|
c.Dimensions = Dimensions{}
|
||||||
c.Config = cfg
|
c.Config = cfg
|
||||||
if c.Ops == nil {
|
if c.Ops == nil {
|
||||||
|
|||||||
+7
-12
@@ -19,11 +19,10 @@ var cfg = new(config)
|
|||||||
|
|
||||||
func ExampleInset() {
|
func ExampleInset() {
|
||||||
gtx := &layout.Context{Queue: q}
|
gtx := &layout.Context{Queue: q}
|
||||||
|
gtx.Reset(cfg, image.Point{X: 100, Y: 100})
|
||||||
// Loose constraints with no minimal size.
|
// Loose constraints with no minimal size.
|
||||||
var cs layout.Constraints
|
gtx.Constraints.Width.Min = 0
|
||||||
cs.Width.Max = 100
|
gtx.Constraints.Height.Min = 0
|
||||||
cs.Height.Max = 100
|
|
||||||
gtx.Reset(cfg, cs)
|
|
||||||
|
|
||||||
// Inset all edges by 10.
|
// Inset all edges by 10.
|
||||||
inset := layout.UniformInset(unit.Dp(10))
|
inset := layout.UniformInset(unit.Dp(10))
|
||||||
@@ -43,8 +42,7 @@ func ExampleInset() {
|
|||||||
func ExampleAlign() {
|
func ExampleAlign() {
|
||||||
gtx := &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})
|
gtx.Reset(cfg, image.Point{X: 100, Y: 100})
|
||||||
gtx.Reset(cfg, cs)
|
|
||||||
|
|
||||||
align := layout.Align(layout.Center)
|
align := layout.Align(layout.Center)
|
||||||
align.Layout(gtx, func() {
|
align.Layout(gtx, func() {
|
||||||
@@ -62,8 +60,7 @@ func ExampleAlign() {
|
|||||||
|
|
||||||
func ExampleFlex() {
|
func ExampleFlex() {
|
||||||
gtx := &layout.Context{Queue: q}
|
gtx := &layout.Context{Queue: q}
|
||||||
cs := layout.RigidConstraints(image.Point{X: 100, Y: 100})
|
gtx.Reset(cfg, image.Point{X: 100, Y: 100})
|
||||||
gtx.Reset(cfg, cs)
|
|
||||||
|
|
||||||
flex := layout.Flex{}
|
flex := layout.Flex{}
|
||||||
flex.Init(gtx)
|
flex.Init(gtx)
|
||||||
@@ -89,8 +86,7 @@ func ExampleFlex() {
|
|||||||
|
|
||||||
func ExampleStack() {
|
func ExampleStack() {
|
||||||
gtx := &layout.Context{Queue: q}
|
gtx := &layout.Context{Queue: q}
|
||||||
cs := layout.RigidConstraints(image.Point{X: 100, Y: 100})
|
gtx.Reset(cfg, image.Point{X: 100, Y: 100})
|
||||||
gtx.Reset(cfg, cs)
|
|
||||||
|
|
||||||
stack := layout.Stack{}
|
stack := layout.Stack{}
|
||||||
stack.Init(gtx)
|
stack.Init(gtx)
|
||||||
@@ -114,8 +110,7 @@ func ExampleStack() {
|
|||||||
|
|
||||||
func ExampleList() {
|
func ExampleList() {
|
||||||
gtx := &layout.Context{Queue: q}
|
gtx := &layout.Context{Queue: q}
|
||||||
cs := layout.RigidConstraints(image.Point{X: 100, Y: 100})
|
gtx.Reset(cfg, image.Point{X: 100, Y: 100})
|
||||||
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
|
||||||
|
|||||||
Reference in New Issue
Block a user