Add padding and margin layouts
This commit is contained in:
@@ -43,7 +43,9 @@ func (c Canvas) Build(
|
||||
return
|
||||
}
|
||||
|
||||
decorator = applyDecorators(e, cnv)
|
||||
decorator = applyPadding(e, cnv)
|
||||
decorator = applyDecorators(e, decorator)
|
||||
decorator = applyMargins(e, decorator)
|
||||
|
||||
if e.Hidden {
|
||||
decorator.Hide()
|
||||
|
@@ -67,7 +67,9 @@ func (cnt Container) Build(
|
||||
return
|
||||
}
|
||||
|
||||
decorator = applyDecorators(e, cont)
|
||||
decorator = applyPadding(e, cont)
|
||||
decorator = applyDecorators(e, decorator)
|
||||
decorator = applyMargins(e, decorator)
|
||||
|
||||
if e.Hidden {
|
||||
decorator.Hide()
|
||||
|
@@ -25,6 +25,28 @@ type Color struct {
|
||||
Alpha uint8 `yaml:"alpha"`
|
||||
}
|
||||
|
||||
type Margins struct {
|
||||
Top float32 `yaml:"top"`
|
||||
Bottom float32 `yaml:"bottom"`
|
||||
Left float32 `yaml:"left"`
|
||||
Right float32 `yaml:"right"`
|
||||
}
|
||||
|
||||
func (m *Margins) HasMargins() bool {
|
||||
return m.Top > 0 || m.Bottom > 0 || m.Left > 0 || m.Right > 0
|
||||
}
|
||||
|
||||
type Padding struct {
|
||||
Top float32 `yaml:"top"`
|
||||
Bottom float32 `yaml:"bottom"`
|
||||
Left float32 `yaml:"left"`
|
||||
Right float32 `yaml:"right"`
|
||||
}
|
||||
|
||||
func (p *Padding) HasPadding() bool {
|
||||
return p.Top > 0 || p.Bottom > 0 || p.Left > 0 || p.Right > 0
|
||||
}
|
||||
|
||||
// Element represents the yaml description of a ui element
|
||||
type Element struct {
|
||||
ID string `yaml:"id"`
|
||||
@@ -34,6 +56,9 @@ type Element struct {
|
||||
Widget Widget `yaml:"widget"`
|
||||
Canvas Canvas `yaml:"canvas"`
|
||||
|
||||
Padding Padding `yaml:"padding"`
|
||||
Margins Margins `yaml:"margins"`
|
||||
|
||||
// Border Layout Elements
|
||||
Top *Element `yaml:"top"`
|
||||
Bottom *Element `yaml:"bottom"`
|
||||
|
@@ -112,7 +112,9 @@ func (l Layout) Build(
|
||||
return
|
||||
}
|
||||
|
||||
decorator = applyDecorators(e, lay)
|
||||
decorator = applyPadding(e, lay)
|
||||
decorator = applyDecorators(e, decorator)
|
||||
decorator = applyMargins(e, decorator)
|
||||
|
||||
if e.Hidden {
|
||||
decorator.Hide()
|
||||
|
25
screen/margin.go
Normal file
25
screen/margin.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package screen
|
||||
|
||||
import (
|
||||
"bitbucket.org/hevanto/ui/uilayout"
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
)
|
||||
|
||||
func applyMargins(
|
||||
e *Element,
|
||||
obj fyne.CanvasObject,
|
||||
) (
|
||||
margin fyne.CanvasObject,
|
||||
) {
|
||||
margin = obj
|
||||
if e.Margins.HasMargins() {
|
||||
margin = container.New(uilayout.NewMargin(
|
||||
e.Margins.Top,
|
||||
e.Margins.Bottom,
|
||||
e.Margins.Left,
|
||||
e.Margins.Right,
|
||||
), obj)
|
||||
}
|
||||
return
|
||||
}
|
25
screen/padding.go
Normal file
25
screen/padding.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package screen
|
||||
|
||||
import (
|
||||
"bitbucket.org/hevanto/ui/uilayout"
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
)
|
||||
|
||||
func applyPadding(
|
||||
e *Element,
|
||||
obj fyne.CanvasObject,
|
||||
) (
|
||||
padding fyne.CanvasObject,
|
||||
) {
|
||||
padding = obj
|
||||
if e.Padding.HasPadding() {
|
||||
padding = container.New(uilayout.NewPadding(
|
||||
e.Padding.Top,
|
||||
e.Padding.Bottom,
|
||||
e.Padding.Left,
|
||||
e.Padding.Right,
|
||||
), obj)
|
||||
}
|
||||
return
|
||||
}
|
@@ -255,7 +255,9 @@ func (w Widget) Build(
|
||||
return
|
||||
}
|
||||
|
||||
decorator = applyDecorators(e, widget)
|
||||
decorator = applyPadding(e, widget)
|
||||
decorator = applyDecorators(e, decorator)
|
||||
decorator = applyMargins(e, decorator)
|
||||
|
||||
if e.Hidden {
|
||||
decorator.Hide()
|
||||
|
Reference in New Issue
Block a user