mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 09:55:40 +00:00
ui/layout: make Align a Direction
Removes the stutter by simplifying
layout.Align{Alignment: layout.NE}
to
layout.Align(layout.NE)
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+1
-1
@@ -38,7 +38,7 @@ This example both aligns and insets a child:
|
|||||||
|
|
||||||
inset := layout.Inset{...}
|
inset := layout.Inset{...}
|
||||||
inset.Layout(..., ctx, func() {
|
inset.Layout(..., ctx, func() {
|
||||||
align := layout.Align{...}
|
align := layout.Align(...)
|
||||||
align.Layout(..., ctx, func() {
|
align.Layout(..., ctx, func() {
|
||||||
widget.Layout(..., ctx)
|
widget.Layout(..., ctx)
|
||||||
})
|
})
|
||||||
|
|||||||
+3
-5
@@ -113,9 +113,7 @@ type Inset struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Align aligns a widget in the available space.
|
// Align aligns a widget in the available space.
|
||||||
type Align struct {
|
type Align Direction
|
||||||
Alignment Direction
|
|
||||||
}
|
|
||||||
|
|
||||||
// Layout a widget.
|
// Layout a widget.
|
||||||
func (in Inset) Layout(c ui.Config, ops *ui.Ops, ctx *Context, w Widget) {
|
func (in Inset) Layout(c ui.Config, ops *ui.Ops, ctx *Context, w Widget) {
|
||||||
@@ -175,13 +173,13 @@ func (a Align) Layout(ops *ui.Ops, st *Context, w Widget) {
|
|||||||
sz.Y = cs.Height.Min
|
sz.Y = cs.Height.Min
|
||||||
}
|
}
|
||||||
var p image.Point
|
var p image.Point
|
||||||
switch a.Alignment {
|
switch Direction(a) {
|
||||||
case N, S, Center:
|
case N, S, Center:
|
||||||
p.X = (sz.X - dims.Size.X) / 2
|
p.X = (sz.X - dims.Size.X) / 2
|
||||||
case NE, SE, E:
|
case NE, SE, E:
|
||||||
p.X = sz.X - dims.Size.X
|
p.X = sz.X - dims.Size.X
|
||||||
}
|
}
|
||||||
switch a.Alignment {
|
switch Direction(a) {
|
||||||
case W, Center, E:
|
case W, Center, E:
|
||||||
p.Y = (sz.Y - dims.Size.Y) / 2
|
p.Y = (sz.Y - dims.Size.Y) / 2
|
||||||
case SW, S, SE:
|
case SW, S, SE:
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ func ExampleAlign() {
|
|||||||
// Rigid constraints with both minimum and maximum set.
|
// Rigid constraints with both minimum and maximum set.
|
||||||
ctx.Constraints = layout.RigidConstraints(image.Point{X: 100, Y: 100})
|
ctx.Constraints = layout.RigidConstraints(image.Point{X: 100, Y: 100})
|
||||||
|
|
||||||
align := layout.Align{Alignment: layout.Center}
|
align := layout.Align(layout.Center)
|
||||||
align.Layout(ops, ctx, func() {
|
align.Layout(ops, ctx, func() {
|
||||||
// Lay out a 50x50 sized widget.
|
// Lay out a 50x50 sized widget.
|
||||||
layoutWidget(ctx, 50, 50)
|
layoutWidget(ctx, 50, 50)
|
||||||
|
|||||||
Reference in New Issue
Block a user