direct-draw #6

Merged
sashakoshka merged 10 commits from direct-draw into main 2023-02-01 04:05:26 +00:00
3 changed files with 13 additions and 32 deletions
Showing only changes of commit 9cb0d064ff - Show all commits

View File

@ -18,8 +18,6 @@ type Dialog struct {
Pad bool Pad bool
} }
// FIXME
// Arrange arranges a list of entries into a dialog. // Arrange arranges a list of entries into a dialog.
func (layout Dialog) Arrange (entries []tomo.LayoutEntry, bounds image.Rectangle) { func (layout Dialog) Arrange (entries []tomo.LayoutEntry, bounds image.Rectangle) {
if layout.Pad { bounds = bounds.Inset(theme.Margin()) } if layout.Pad { bounds = bounds.Inset(theme.Margin()) }
@ -31,20 +29,14 @@ func (layout Dialog) Arrange (entries []tomo.LayoutEntry, bounds image.Rectangle
} }
if len(entries) > 0 { if len(entries) > 0 {
entries[0].Bounds.Min = image.Point { } main := entries[0]
if layout.Pad { main.Bounds.Min = bounds.Min
entries[0].Bounds.Min.X += theme.Margin()
entries[0].Bounds.Min.Y += theme.Margin()
}
mainHeight := bounds.Dy() - controlRowHeight mainHeight := bounds.Dy() - controlRowHeight
if layout.Gap { if layout.Gap {
mainHeight -= theme.Margin() mainHeight -= theme.Margin()
} }
mainBounds := entries[0].Bounds main.Bounds.Max = main.Bounds.Min.Add(image.Pt(bounds.Dx(), mainHeight))
if mainBounds.Dy() != mainHeight || mainBounds.Dx() != bounds.Dx() { entries[0] = main
entries[0].Bounds.Max =
mainBounds.Min.Add(image.Pt(bounds.Dx(), mainHeight))
}
} }
if len(entries) > 1 { if len(entries) > 1 {
@ -70,34 +62,30 @@ func (layout Dialog) Arrange (entries []tomo.LayoutEntry, bounds image.Rectangle
} }
// determine starting position and dimensions for control row // determine starting position and dimensions for control row
x, y := 0, bounds.Dy() - controlRowHeight dot := image.Pt(bounds.Min.X, bounds.Max.Y - controlRowHeight)
if expandingElements == 0 { if expandingElements == 0 {
x = bounds.Dx() - controlRowWidth dot.X = bounds.Max.X - controlRowWidth
} }
if layout.Pad {
x += theme.Margin()
y += theme.Margin()
}
bounds.Max.Y -= controlRowHeight
// set the size and position of each element in the control row // set the size and position of each element in the control row
for index, entry := range entries[1:] { for index, entry := range entries[1:] {
if index > 0 && layout.Gap { x += theme.Margin() } if index > 0 && layout.Gap { dot.X += theme.Margin() }
entries[index + 1].Bounds.Min = image.Pt(x, y) entry.Bounds.Min = dot
entryWidth := 0 entryWidth := 0
if entry.Expand { if entry.Expand {
entryWidth = expandingElementWidth entryWidth = expandingElementWidth
} else { } else {
entryWidth, _ = entry.MinimumSize() entryWidth, _ = entry.MinimumSize()
} }
x += entryWidth dot.X += entryWidth
entryBounds := entry.Bounds entryBounds := entry.Bounds
if entryBounds.Dy() != controlRowHeight || if entryBounds.Dy() != controlRowHeight ||
entryBounds.Dx() != entryWidth { entryBounds.Dx() != entryWidth {
entries[index].Bounds.Max = entryBounds.Min.Add ( entry.Bounds.Max = entryBounds.Min.Add (
image.Pt(entryWidth, controlRowHeight)) image.Pt(entryWidth, controlRowHeight))
} }
entries[index + 1] = entry
} }
} }

View File

@ -36,11 +36,7 @@ func (layout Horizontal) Arrange (entries []tomo.LayoutEntry, bounds image.Recta
entryWidth, _ = entry.MinimumSize() entryWidth, _ = entry.MinimumSize()
} }
dot.X += entryWidth dot.X += entryWidth
entryBounds := entry.Bounds entry.Bounds.Max = entry.Bounds.Min.Add(image.Pt(entryWidth, bounds.Dy()))
if entryBounds.Dy() != bounds.Dy() || entryBounds.Dx() != entryWidth {
entry.Bounds.Max = entryBounds.Min.Add (
image.Pt(entryWidth, bounds.Dy()))
}
entries[index] = entry entries[index] = entry
} }

View File

@ -64,10 +64,7 @@ func (layout Vertical) Arrange (entries []tomo.LayoutEntry, bounds image.Rectang
} }
dot.Y += entryHeight dot.Y += entryHeight
entryBounds := entry.Bounds entryBounds := entry.Bounds
if entryBounds.Dx() != bounds.Dx() || entryBounds.Dy() != entryHeight { entry.Bounds.Max = entryBounds.Min.Add(image.Pt(bounds.Dx(), entryHeight))
entry.Bounds.Max = entryBounds.Min.Add (
image.Pt(bounds.Dx(), entryHeight))
}
entries[index] = entry entries[index] = entry
} }
} }