2021-12-11 13:54:32 +00:00
|
|
|
package layouts
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fyne.io/fyne/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
type FloatingControlsLocationEnum uint32
|
|
|
|
|
|
|
|
const (
|
|
|
|
FloatingControlsTopLeft = iota
|
|
|
|
FloatingControlsTopRight
|
|
|
|
FloatingControlsBottomLeft
|
|
|
|
FloatingControlsBottomRight
|
|
|
|
FloatingControlsCenter
|
2021-12-11 14:22:55 +00:00
|
|
|
FloatingControlsTopMiddle
|
|
|
|
FloatingControlsRightMiddle
|
|
|
|
FloatingControlsBottomMiddle
|
|
|
|
FloatingControlsLeftMiddle
|
2021-12-11 13:54:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type floatingControlsLayout struct {
|
|
|
|
FloatingControlsLocation FloatingControlsLocationEnum
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewFloatingControlsLayout creates a new floatingControlsLayout instance
|
|
|
|
// This layout contains exactly TWO items, one background item (first) and one
|
|
|
|
// floating container that floats according to FloatingControlsLocation
|
|
|
|
func NewFloatingControlsLayout() floatingControlsLayout {
|
|
|
|
return floatingControlsLayout{FloatingControlsTopRight}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *floatingControlsLayout) MinSize(objects []fyne.CanvasObject) fyne.Size {
|
|
|
|
if len(objects) > 1 {
|
|
|
|
return objects[0].MinSize()
|
|
|
|
}
|
|
|
|
return fyne.NewSize(0, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *floatingControlsLayout) Layout(objects []fyne.CanvasObject, containerSize fyne.Size) {
|
|
|
|
if len(objects) == 2 {
|
|
|
|
o := objects[0]
|
|
|
|
size := containerSize
|
|
|
|
o.Resize(size)
|
|
|
|
o.Move(fyne.NewPos(0, 0))
|
|
|
|
|
|
|
|
o = objects[1]
|
|
|
|
size = o.MinSize()
|
|
|
|
o.Resize(size)
|
|
|
|
switch d.FloatingControlsLocation {
|
|
|
|
case FloatingControlsTopLeft:
|
|
|
|
o.Move(fyne.NewPos(0, 0))
|
2021-12-11 14:22:55 +00:00
|
|
|
case FloatingControlsTopMiddle:
|
|
|
|
o.Move(fyne.NewPos((containerSize.Width/2)-(size.Width/2), 0))
|
2021-12-11 13:54:32 +00:00
|
|
|
case FloatingControlsTopRight:
|
|
|
|
o.Move(fyne.NewPos(containerSize.Width-size.Width, 0))
|
|
|
|
case FloatingControlsBottomLeft:
|
|
|
|
o.Move(fyne.NewPos(0, containerSize.Height-size.Height))
|
|
|
|
case FloatingControlsBottomRight:
|
|
|
|
o.Move(fyne.NewPos(containerSize.Width-size.Width, containerSize.Height-size.Height))
|
2021-12-11 14:22:55 +00:00
|
|
|
case FloatingControlsBottomMiddle:
|
|
|
|
o.Move(fyne.NewPos((containerSize.Width/2)-(size.Width/2), containerSize.Height-size.Height))
|
2021-12-11 13:54:32 +00:00
|
|
|
case FloatingControlsCenter:
|
|
|
|
o.Move(fyne.NewPos((containerSize.Width/2)-(size.Width/2), (containerSize.Height/2)-(size.Height/2)))
|
2021-12-11 14:22:55 +00:00
|
|
|
case FloatingControlsLeftMiddle:
|
|
|
|
o.Move(fyne.NewPos(0, (containerSize.Height/2)-(size.Height/2)))
|
|
|
|
case FloatingControlsRightMiddle:
|
|
|
|
o.Move(fyne.NewPos(containerSize.Width-size.Width, (containerSize.Height/2)-(size.Height/2)))
|
2021-12-11 13:54:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|