mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
layout,widget: transpose Constraints to use image.Points for limits
Instead of
type Contraints struct {
Width, Height Constraint
}
use
type Constraints struct {
Min, Max image.Point
}
which leads to simpler use. For example, the Min method is trivally replaced by
the field, and the RigidConstraints constructor is no longer a net win.
API Change. Rewrites:
gofmt -r 'gtx.Constraints.Min() -> gtx.Constraints.Min'
gofmt -r 'gtx.Constraints.Width.Min -> gtx.Constraints.Min.X'
gofmt -r 'gtx.Constraints.Height.Min -> gtx.Constraints.Min.Y'
gofmt -r 'gtx.Constraints.Height.Max -> gtx.Constraints.Max.Y'
gofmt -r 'gtx.Constraints.Width.Max -> gtx.Constraints.Max.X'
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -12,8 +12,7 @@ func ExampleInset() {
|
||||
gtx := new(layout.Context)
|
||||
gtx.Reset(nil, nil, image.Point{X: 100, Y: 100})
|
||||
// Loose constraints with no minimal size.
|
||||
gtx.Constraints.Width.Min = 0
|
||||
gtx.Constraints.Height.Min = 0
|
||||
gtx.Constraints.Min = image.Point{}
|
||||
|
||||
// Inset all edges by 10.
|
||||
inset := layout.UniformInset(unit.Dp(10))
|
||||
@@ -55,26 +54,25 @@ func ExampleFlex() {
|
||||
layout.Flex{}.Layout(gtx,
|
||||
// Rigid 10x10 widget.
|
||||
layout.Rigid(func() {
|
||||
fmt.Printf("Rigid: %v\n", gtx.Constraints.Width)
|
||||
fmt.Printf("Rigid: %v\n", gtx.Constraints)
|
||||
layoutWidget(gtx, 10, 10)
|
||||
}),
|
||||
// Child with 50% space allowance.
|
||||
layout.Flexed(0.5, func() {
|
||||
fmt.Printf("50%%: %v\n", gtx.Constraints.Width)
|
||||
fmt.Printf("50%%: %v\n", gtx.Constraints)
|
||||
layoutWidget(gtx, 10, 10)
|
||||
}),
|
||||
)
|
||||
|
||||
// Output:
|
||||
// Rigid: {0 100}
|
||||
// 50%: {45 45}
|
||||
// Rigid: {(0,100) (100,100)}
|
||||
// 50%: {(45,100) (45,100)}
|
||||
}
|
||||
|
||||
func ExampleStack() {
|
||||
gtx := new(layout.Context)
|
||||
gtx.Reset(nil, nil, image.Point{X: 100, Y: 100})
|
||||
gtx.Constraints.Width.Min = 0
|
||||
gtx.Constraints.Height.Min = 0
|
||||
gtx.Constraints.Min = image.Point{}
|
||||
|
||||
layout.Stack{}.Layout(gtx,
|
||||
// Force widget to the same size as the second.
|
||||
@@ -89,7 +87,7 @@ func ExampleStack() {
|
||||
)
|
||||
|
||||
// Output:
|
||||
// Expand: {{50 100} {50 100}}
|
||||
// Expand: {(50,50) (100,100)}
|
||||
}
|
||||
|
||||
func ExampleList() {
|
||||
|
||||
Reference in New Issue
Block a user