mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 18:05:35 +00:00
layout: replace Align with a Layout method on Direction
It's one less type (Align) and shorter: Before: layout.Align(layout.Center).Layout(...) After layout.Center.Layout(...) It is also safer: since `layout.Align(...)` was a casting operation, the Go compiler would not complain about an incompatible constant. For example, the widget/material package contained a wrong cast: layout.Align(layout.Start) which should have been layout.Align(layout.W) After this change, attempting `layout.Start.Layout(...)` result in a compile error. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+2
-5
@@ -95,9 +95,6 @@ type Inset struct {
|
||||
Top, Right, Bottom, Left unit.Value
|
||||
}
|
||||
|
||||
// Align aligns a widget in the available space.
|
||||
type Align Direction
|
||||
|
||||
// Layout a widget.
|
||||
func (in Inset) Layout(gtx *Context, w Widget) {
|
||||
top := gtx.Px(in.Top)
|
||||
@@ -140,8 +137,8 @@ func UniformInset(v unit.Value) Inset {
|
||||
return Inset{Top: v, Right: v, Bottom: v, Left: v}
|
||||
}
|
||||
|
||||
// Layout a widget.
|
||||
func (a Align) Layout(gtx *Context, w Widget) {
|
||||
// Layout a widget according to the direction.
|
||||
func (a Direction) Layout(gtx *Context, w Widget) {
|
||||
var macro op.MacroOp
|
||||
macro.Record(gtx.Ops)
|
||||
cs := gtx.Constraints
|
||||
|
||||
Reference in New Issue
Block a user