mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 18:05:35 +00:00
all: rename layout.Dimens to layout.Dimensions
Dimens is only 4 characters shorter and not worth the abbreviation. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+2
-2
@@ -8,8 +8,8 @@ Constraints and dimensions
|
|||||||
Constraints and dimensions form the the interface between
|
Constraints and dimensions form the the interface between
|
||||||
layouts and interface child elements. Every layout operation
|
layouts and interface child elements. Every layout operation
|
||||||
start with a set of constraints for acceptable widths and heights
|
start with a set of constraints for acceptable widths and heights
|
||||||
of a child. The operation ends by the child computing and returning
|
of a child. The operation ends with the child computing and returning
|
||||||
its chosen size in the form of a Dimens.
|
its size and baseline (if any).
|
||||||
|
|
||||||
For example, to add space above a widget:
|
For example, to add space above a widget:
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -33,7 +33,7 @@ type Flex struct {
|
|||||||
// FlexChild is the layout result of a call End.
|
// FlexChild is the layout result of a call End.
|
||||||
type FlexChild struct {
|
type FlexChild struct {
|
||||||
macro ui.MacroOp
|
macro ui.MacroOp
|
||||||
dims Dimens
|
dims Dimensions
|
||||||
}
|
}
|
||||||
|
|
||||||
// Spacing determine the spacing mode for a Flex.
|
// Spacing determine the spacing mode for a Flex.
|
||||||
@@ -124,7 +124,7 @@ func (f *Flex) Flexible(weight float32) Constraints {
|
|||||||
|
|
||||||
// End a child by specifying its dimensions. Pass the returned layout result
|
// End a child by specifying its dimensions. Pass the returned layout result
|
||||||
// to Layout.
|
// to Layout.
|
||||||
func (f *Flex) End(dims Dimens) FlexChild {
|
func (f *Flex) End(dims Dimensions) FlexChild {
|
||||||
if f.mode <= modeBegun {
|
if f.mode <= modeBegun {
|
||||||
panic("End called without an active child")
|
panic("End called without an active child")
|
||||||
}
|
}
|
||||||
@@ -146,7 +146,7 @@ func (f *Flex) End(dims Dimens) FlexChild {
|
|||||||
|
|
||||||
// Layout a list of children. The order of the children determines their laid
|
// Layout a list of children. The order of the children determines their laid
|
||||||
// out order.
|
// out order.
|
||||||
func (f *Flex) Layout(children ...FlexChild) Dimens {
|
func (f *Flex) Layout(children ...FlexChild) Dimensions {
|
||||||
mainc := axisMainConstraint(f.Axis, f.cs)
|
mainc := axisMainConstraint(f.Axis, f.cs)
|
||||||
crossSize := axisCrossConstraint(f.Axis, f.cs).Constrain(f.maxCross)
|
crossSize := axisCrossConstraint(f.Axis, f.cs).Constrain(f.maxCross)
|
||||||
var space int
|
var space int
|
||||||
@@ -213,7 +213,7 @@ func (f *Flex) Layout(children ...FlexChild) Dimens {
|
|||||||
if baseline == 0 {
|
if baseline == 0 {
|
||||||
baseline = sz.Y
|
baseline = sz.Y
|
||||||
}
|
}
|
||||||
return Dimens{Size: sz, Baseline: baseline}
|
return Dimensions{Size: sz, Baseline: baseline}
|
||||||
}
|
}
|
||||||
|
|
||||||
func axisPoint(a Axis, main, cross int) image.Point {
|
func axisPoint(a Axis, main, cross int) image.Point {
|
||||||
|
|||||||
+6
-6
@@ -21,9 +21,9 @@ type Constraint struct {
|
|||||||
Min, Max int
|
Min, Max int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dimens are the resolved size and baseline for a user
|
// Dimensions are the resolved size and baseline for a user
|
||||||
// interface element.
|
// interface element.
|
||||||
type Dimens struct {
|
type Dimensions struct {
|
||||||
Size image.Point
|
Size image.Point
|
||||||
Baseline int
|
Baseline int
|
||||||
}
|
}
|
||||||
@@ -143,13 +143,13 @@ func (in *Inset) Begin(c ui.Config, ops *ui.Ops, cs Constraints) Constraints {
|
|||||||
|
|
||||||
// End the inset operation and return the dimensions for the
|
// End the inset operation and return the dimensions for the
|
||||||
// inset child.
|
// inset child.
|
||||||
func (in *Inset) End(dims Dimens) Dimens {
|
func (in *Inset) End(dims Dimensions) Dimensions {
|
||||||
if !in.begun {
|
if !in.begun {
|
||||||
panic("must Begin before End")
|
panic("must Begin before End")
|
||||||
}
|
}
|
||||||
in.begun = false
|
in.begun = false
|
||||||
in.stack.Pop()
|
in.stack.Pop()
|
||||||
return Dimens{
|
return Dimensions{
|
||||||
Size: in.cs.Constrain(dims.Size.Add(image.Point{X: in.right + in.left, Y: in.top + in.bottom})),
|
Size: in.cs.Constrain(dims.Size.Add(image.Point{X: in.right + in.left, Y: in.top + in.bottom})),
|
||||||
Baseline: dims.Baseline + in.top,
|
Baseline: dims.Baseline + in.top,
|
||||||
}
|
}
|
||||||
@@ -177,7 +177,7 @@ func (a *Align) Begin(ops *ui.Ops, cs Constraints) Constraints {
|
|||||||
|
|
||||||
// End the align operation and return the dimensions for the
|
// End the align operation and return the dimensions for the
|
||||||
// aligned child.
|
// aligned child.
|
||||||
func (a *Align) End(dims Dimens) Dimens {
|
func (a *Align) End(dims Dimensions) Dimensions {
|
||||||
if !a.begun {
|
if !a.begun {
|
||||||
panic("must Begin before End")
|
panic("must Begin before End")
|
||||||
}
|
}
|
||||||
@@ -209,7 +209,7 @@ func (a *Align) End(dims Dimens) Dimens {
|
|||||||
ui.TransformOp{}.Offset(toPointF(p)).Add(ops)
|
ui.TransformOp{}.Offset(toPointF(p)).Add(ops)
|
||||||
a.macro.Add(ops)
|
a.macro.Add(ops)
|
||||||
stack.Pop()
|
stack.Pop()
|
||||||
return Dimens{
|
return Dimensions{
|
||||||
Size: sz,
|
Size: sz,
|
||||||
Baseline: dims.Baseline,
|
Baseline: dims.Baseline,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,8 +140,8 @@ func ExampleList() {
|
|||||||
// 5
|
// 5
|
||||||
}
|
}
|
||||||
|
|
||||||
func layoutWidget(width, height int, cs layout.Constraints) layout.Dimens {
|
func layoutWidget(width, height int, cs layout.Constraints) layout.Dimensions {
|
||||||
return layout.Dimens{
|
return layout.Dimensions{
|
||||||
Size: image.Point{
|
Size: image.Point{
|
||||||
X: width,
|
X: width,
|
||||||
Y: height,
|
Y: height,
|
||||||
|
|||||||
+3
-3
@@ -158,7 +158,7 @@ func (l *List) next() (int, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// End the current child by specifying its dimensions.
|
// End the current child by specifying its dimensions.
|
||||||
func (l *List) End(dims Dimens) {
|
func (l *List) End(dims Dimensions) {
|
||||||
l.child.Stop()
|
l.child.Stop()
|
||||||
child := scrollChild{dims.Size, l.child}
|
child := scrollChild{dims.Size, l.child}
|
||||||
switch l.dir {
|
switch l.dir {
|
||||||
@@ -179,7 +179,7 @@ func (l *List) End(dims Dimens) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Layout the List and return its dimensions.
|
// Layout the List and return its dimensions.
|
||||||
func (l *List) Layout() Dimens {
|
func (l *List) Layout() Dimensions {
|
||||||
if l.more {
|
if l.more {
|
||||||
panic("unfinished child")
|
panic("unfinished child")
|
||||||
}
|
}
|
||||||
@@ -254,5 +254,5 @@ func (l *List) Layout() Dimens {
|
|||||||
pointer.RectAreaOp{Rect: image.Rectangle{Max: dims}}.Add(ops)
|
pointer.RectAreaOp{Rect: image.Rectangle{Max: dims}}.Add(ops)
|
||||||
l.scroll.Add(ops)
|
l.scroll.Add(ops)
|
||||||
l.macro.Add(ops)
|
l.macro.Add(ops)
|
||||||
return Dimens{Size: dims}
|
return Dimensions{Size: dims}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -27,7 +27,7 @@ type Stack struct {
|
|||||||
// StackChild is the layout result of a call to End.
|
// StackChild is the layout result of a call to End.
|
||||||
type StackChild struct {
|
type StackChild struct {
|
||||||
macro ui.MacroOp
|
macro ui.MacroOp
|
||||||
dims Dimens
|
dims Dimensions
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init a stack before calling Rigid or Expand.
|
// Init a stack before calling Rigid or Expand.
|
||||||
@@ -69,7 +69,7 @@ func (s *Stack) Expand() Constraints {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// End a child by specifying its dimensions.
|
// End a child by specifying its dimensions.
|
||||||
func (s *Stack) End(dims Dimens) StackChild {
|
func (s *Stack) End(dims Dimensions) StackChild {
|
||||||
s.macro.Stop()
|
s.macro.Stop()
|
||||||
s.begun = false
|
s.begun = false
|
||||||
if w := dims.Size.X; w > s.maxSZ.X {
|
if w := dims.Size.X; w > s.maxSZ.X {
|
||||||
@@ -88,7 +88,7 @@ func (s *Stack) End(dims Dimens) StackChild {
|
|||||||
|
|
||||||
// Layout a list of children. The order of the children determines their laid
|
// Layout a list of children. The order of the children determines their laid
|
||||||
// out order.
|
// out order.
|
||||||
func (s *Stack) Layout(children ...StackChild) Dimens {
|
func (s *Stack) Layout(children ...StackChild) Dimensions {
|
||||||
for _, ch := range children {
|
for _, ch := range children {
|
||||||
sz := ch.dims.Size
|
sz := ch.dims.Size
|
||||||
var p image.Point
|
var p image.Point
|
||||||
@@ -114,7 +114,7 @@ func (s *Stack) Layout(children ...StackChild) Dimens {
|
|||||||
if b == 0 {
|
if b == 0 {
|
||||||
b = s.maxSZ.Y
|
b = s.maxSZ.Y
|
||||||
}
|
}
|
||||||
return Dimens{
|
return Dimensions{
|
||||||
Size: s.maxSZ,
|
Size: s.maxSZ,
|
||||||
Baseline: b,
|
Baseline: b,
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -48,7 +48,7 @@ type Editor struct {
|
|||||||
viewSize image.Point
|
viewSize image.Point
|
||||||
valid bool
|
valid bool
|
||||||
lines []Line
|
lines []Line
|
||||||
dims layout.Dimens
|
dims layout.Dimensions
|
||||||
padTop, padBottom int
|
padTop, padBottom int
|
||||||
padLeft, padRight int
|
padLeft, padRight int
|
||||||
requestFocus bool
|
requestFocus bool
|
||||||
@@ -165,7 +165,7 @@ func (e *Editor) Focus() {
|
|||||||
e.requestFocus = true
|
e.requestFocus = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Editor) Layout(cfg ui.Config, queue input.Queue, ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
func (e *Editor) Layout(cfg ui.Config, queue input.Queue, ops *ui.Ops, cs layout.Constraints) layout.Dimensions {
|
||||||
for _, ok := e.Next(cfg, queue); ok; _, ok = e.Next(cfg, queue) {
|
for _, ok := e.Next(cfg, queue); ok; _, ok = e.Next(cfg, queue) {
|
||||||
}
|
}
|
||||||
twoDp := cfg.Px(ui.Dp(2))
|
twoDp := cfg.Px(ui.Dp(2))
|
||||||
@@ -270,7 +270,7 @@ func (e *Editor) Layout(cfg ui.Config, queue input.Queue, ops *ui.Ops, cs layout
|
|||||||
pointer.RectAreaOp{Rect: r}.Add(ops)
|
pointer.RectAreaOp{Rect: r}.Add(ops)
|
||||||
e.scroller.Add(ops)
|
e.scroller.Add(ops)
|
||||||
e.clicker.Add(ops)
|
e.clicker.Add(ops)
|
||||||
return layout.Dimens{Size: e.viewSize, Baseline: baseline}
|
return layout.Dimensions{Size: e.viewSize, Baseline: baseline}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Text returns the contents of the editor.
|
// Text returns the contents of the editor.
|
||||||
|
|||||||
+1
-1
@@ -92,7 +92,7 @@ func (l *lineIterator) Next() (String, f32.Point, bool) {
|
|||||||
return String{}, f32.Point{}, false
|
return String{}, f32.Point{}, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l Label) Layout(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
func (l Label) Layout(ops *ui.Ops, cs layout.Constraints) layout.Dimensions {
|
||||||
textLayout := l.Face.Layout(l.Text, LayoutOptions{MaxWidth: cs.Width.Max})
|
textLayout := l.Face.Layout(l.Text, LayoutOptions{MaxWidth: cs.Width.Max})
|
||||||
lines := textLayout.Lines
|
lines := textLayout.Lines
|
||||||
if max := l.MaxLines; max > 0 && len(lines) > max {
|
if max := l.MaxLines; max > 0 && len(lines) > max {
|
||||||
|
|||||||
+2
-2
@@ -61,7 +61,7 @@ const (
|
|||||||
Middle
|
Middle
|
||||||
)
|
)
|
||||||
|
|
||||||
func linesDimens(lines []Line) layout.Dimens {
|
func linesDimens(lines []Line) layout.Dimensions {
|
||||||
var width fixed.Int26_6
|
var width fixed.Int26_6
|
||||||
var h int
|
var h int
|
||||||
var baseline int
|
var baseline int
|
||||||
@@ -78,7 +78,7 @@ func linesDimens(lines []Line) layout.Dimens {
|
|||||||
h += lines[len(lines)-1].Descent.Ceil()
|
h += lines[len(lines)-1].Descent.Ceil()
|
||||||
}
|
}
|
||||||
w := width.Ceil()
|
w := width.Ceil()
|
||||||
return layout.Dimens{
|
return layout.Dimensions{
|
||||||
Size: image.Point{
|
Size: image.Point{
|
||||||
X: w,
|
X: w,
|
||||||
Y: h,
|
Y: h,
|
||||||
|
|||||||
+2
-2
@@ -25,7 +25,7 @@ type Image struct {
|
|||||||
Scale float32
|
Scale float32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (im Image) Layout(c ui.Config, ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
func (im Image) Layout(c ui.Config, ops *ui.Ops, cs layout.Constraints) layout.Dimensions {
|
||||||
size := im.Src.Bounds()
|
size := im.Src.Bounds()
|
||||||
wf, hf := float32(size.Dx()), float32(size.Dy())
|
wf, hf := float32(size.Dx()), float32(size.Dy())
|
||||||
var w, h int
|
var w, h int
|
||||||
@@ -49,5 +49,5 @@ func (im Image) Layout(c ui.Config, ops *ui.Ops, cs layout.Constraints) layout.D
|
|||||||
}
|
}
|
||||||
paint.ImageOp{Src: im.Src, Rect: im.Rect}.Add(ops)
|
paint.ImageOp{Src: im.Src, Rect: im.Rect}.Add(ops)
|
||||||
paint.PaintOp{Rect: dr}.Add(ops)
|
paint.PaintOp{Rect: dr}.Add(ops)
|
||||||
return layout.Dimens{Size: d, Baseline: d.Y}
|
return layout.Dimensions{Size: d, Baseline: d.Y}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user