mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-03 16:35:36 +00:00
ui/layout: add Align example
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+29
-10
@@ -13,28 +13,47 @@ type config struct{}
|
||||
|
||||
var cfg = new(config)
|
||||
|
||||
var cs = layout.Constraints{
|
||||
Width: layout.Constraint{
|
||||
Max: 100,
|
||||
},
|
||||
Height: layout.Constraint{
|
||||
Max: 100,
|
||||
},
|
||||
}
|
||||
|
||||
func ExampleInset() {
|
||||
ops := new(ui.Ops)
|
||||
|
||||
// Loose constraints with no minimal size.
|
||||
var cs layout.Constraints
|
||||
cs.Width.Max = 100
|
||||
cs.Height.Max = 100
|
||||
|
||||
// Inset all edges by 10.
|
||||
inset := layout.UniformInset(ui.Dp(10))
|
||||
cs = inset.Begin(cfg, ops, cs)
|
||||
// Lay out a 50x50 sized widget.
|
||||
dims := layoutWidget(50, 50, cs)
|
||||
fmt.Println(dims.Size)
|
||||
dims = inset.End(dims)
|
||||
|
||||
fmt.Println(dims.Size)
|
||||
|
||||
// Output: (70,70)
|
||||
// Output:
|
||||
// (50,50)
|
||||
// (70,70)
|
||||
}
|
||||
|
||||
func ExampleAlign() {
|
||||
ops := new(ui.Ops)
|
||||
|
||||
cs := layout.RigidConstraints(image.Point{X: 100, Y: 100})
|
||||
|
||||
align := layout.Align{Alignment: layout.Center}
|
||||
cs = align.Begin(ops, cs)
|
||||
// Lay out a 50x50 sized widget.
|
||||
dims := layoutWidget(50, 50, cs)
|
||||
fmt.Println(dims.Size)
|
||||
|
||||
dims = align.End(dims)
|
||||
|
||||
fmt.Println(dims.Size)
|
||||
|
||||
// Output:
|
||||
// (50,50)
|
||||
// (100,100)
|
||||
}
|
||||
|
||||
func layoutWidget(width, height int, cs layout.Constraints) layout.Dimens {
|
||||
|
||||
Reference in New Issue
Block a user