-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
layouts.go
41 lines (35 loc) · 1014 Bytes
/
layouts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package gui
import (
"fyne.io/fyne/v2"
)
func (d *mainButtonsLayout) MinSize(objects []fyne.CanvasObject) fyne.Size {
w, h := float32(0), float32(0)
for _, o := range objects {
childSize := o.MinSize()
w += childSize.Width
h = childSize.Height * d.buttonHeight
}
return fyne.NewSize(w, h)
}
func (d *mainButtonsLayout) Layout(objects []fyne.CanvasObject, containerSize fyne.Size) {
pos := fyne.NewPos(0, 0)
bigButtonSize := containerSize.Width
for q, o := range objects {
if q != 0 && q != len(objects)-1 {
bigButtonSize = bigButtonSize - o.MinSize().Width - d.buttonPadding
}
}
bigButtonSize = (bigButtonSize - d.buttonPadding) / 2
for q, o := range objects {
var size fyne.Size
switch q {
case 0, len(objects) - 1:
size = fyne.NewSize(bigButtonSize, o.MinSize().Height*d.buttonHeight)
default:
size = fyne.NewSize(o.MinSize().Width, o.MinSize().Height*d.buttonHeight)
}
o.Resize(size)
o.Move(pos)
pos = pos.Add(fyne.NewPos(size.Width+d.buttonPadding, 0))
}
}