Added canvas elements
This commit is contained in:
parent
cb9515375a
commit
486b98ce11
@ -5,12 +5,9 @@ import (
|
||||
"fmt"
|
||||
"image/color"
|
||||
|
||||
"bitbucket.org/hevanto/ui/uiwidget"
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/data/binding"
|
||||
"fyne.io/fyne/v2/layout"
|
||||
)
|
||||
|
||||
type Canvas string
|
||||
@ -46,25 +43,7 @@ func (c Canvas) Build(
|
||||
return
|
||||
}
|
||||
|
||||
decorator = cnv
|
||||
if e.Decorators != nil {
|
||||
for _, dec := range e.Decorators {
|
||||
switch dec {
|
||||
case "Border":
|
||||
decorator = uiwidget.NewWidgetBorder(decorator)
|
||||
case "HCenter":
|
||||
decorator = container.NewHBox(
|
||||
layout.NewSpacer(),
|
||||
decorator,
|
||||
layout.NewSpacer())
|
||||
case "VCenter":
|
||||
decorator = container.NewVBox(
|
||||
layout.NewSpacer(),
|
||||
decorator,
|
||||
layout.NewSpacer())
|
||||
}
|
||||
}
|
||||
}
|
||||
decorator = applyDecorators(e, cnv)
|
||||
|
||||
if e.Hidden {
|
||||
decorator.Hide()
|
||||
@ -76,10 +55,16 @@ func (c *Canvas) BuildImageCanvas(
|
||||
e *Element,
|
||||
s ScreenHandler,
|
||||
) (obj fyne.CanvasObject, err error) {
|
||||
img, err := AssetToImage(s, e.ImageName)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to load image: %w", err)
|
||||
return
|
||||
var img *canvas.Image
|
||||
|
||||
if e.ImageName != "" {
|
||||
img, err = AssetToImage(s, e.ImageName)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to load image: %w", err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
img = &canvas.Image{}
|
||||
}
|
||||
if e.Translucency != nil {
|
||||
img.Translucency = *e.Translucency
|
||||
|
@ -4,10 +4,8 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"bitbucket.org/hevanto/ui/uiwidget"
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/layout"
|
||||
)
|
||||
|
||||
// The constants for the Containers
|
||||
@ -69,25 +67,7 @@ func (cnt Container) Build(
|
||||
return
|
||||
}
|
||||
|
||||
decorator = cont
|
||||
if e.Decorators != nil {
|
||||
for _, dec := range e.Decorators {
|
||||
switch dec {
|
||||
case "Border":
|
||||
decorator = uiwidget.NewWidgetBorder(decorator)
|
||||
case "HCenter":
|
||||
decorator = container.NewHBox(
|
||||
layout.NewSpacer(),
|
||||
decorator,
|
||||
layout.NewSpacer())
|
||||
case "VCenter":
|
||||
decorator = container.NewVBox(
|
||||
layout.NewSpacer(),
|
||||
decorator,
|
||||
layout.NewSpacer())
|
||||
}
|
||||
}
|
||||
}
|
||||
decorator = applyDecorators(e, cont)
|
||||
|
||||
if e.Hidden {
|
||||
decorator.Hide()
|
||||
|
53
screen/decorators.go
Normal file
53
screen/decorators.go
Normal file
@ -0,0 +1,53 @@
|
||||
package screen
|
||||
|
||||
import (
|
||||
"bitbucket.org/hevanto/ui/uiwidget"
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/layout"
|
||||
)
|
||||
|
||||
func applyDecorators(
|
||||
e *Element,
|
||||
obj fyne.CanvasObject,
|
||||
) (
|
||||
decorator fyne.CanvasObject,
|
||||
) {
|
||||
decorator = obj
|
||||
if e.Decorators != nil {
|
||||
for _, dec := range e.Decorators {
|
||||
switch dec {
|
||||
case "Border":
|
||||
decorator = uiwidget.NewWidgetBorder(decorator)
|
||||
case "HCenter":
|
||||
decorator = container.NewHBox(
|
||||
layout.NewSpacer(),
|
||||
decorator,
|
||||
layout.NewSpacer())
|
||||
case "HLeading":
|
||||
decorator = container.NewHBox(
|
||||
decorator,
|
||||
layout.NewSpacer())
|
||||
case "HTrailing":
|
||||
decorator = container.NewHBox(
|
||||
layout.NewSpacer(),
|
||||
decorator)
|
||||
case "VCenter":
|
||||
decorator = container.NewVBox(
|
||||
layout.NewSpacer(),
|
||||
decorator,
|
||||
layout.NewSpacer())
|
||||
case "VLeading":
|
||||
decorator = container.NewVBox(
|
||||
decorator,
|
||||
layout.NewSpacer())
|
||||
case "VTrailing":
|
||||
decorator = container.NewVBox(
|
||||
layout.NewSpacer(),
|
||||
decorator)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
@ -5,7 +5,6 @@ import (
|
||||
"fmt"
|
||||
|
||||
"bitbucket.org/hevanto/ui/uilayout"
|
||||
"bitbucket.org/hevanto/ui/uiwidget"
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/layout"
|
||||
@ -113,25 +112,7 @@ func (l Layout) Build(
|
||||
return
|
||||
}
|
||||
|
||||
decorator = lay
|
||||
if e.Decorators != nil {
|
||||
for _, dec := range e.Decorators {
|
||||
switch dec {
|
||||
case "Border":
|
||||
decorator = uiwidget.NewWidgetBorder(decorator)
|
||||
case "HCenter":
|
||||
decorator = container.NewHBox(
|
||||
layout.NewSpacer(),
|
||||
decorator,
|
||||
layout.NewSpacer())
|
||||
case "VCenter":
|
||||
decorator = container.NewVBox(
|
||||
layout.NewSpacer(),
|
||||
decorator,
|
||||
layout.NewSpacer())
|
||||
}
|
||||
}
|
||||
}
|
||||
decorator = applyDecorators(e, lay)
|
||||
|
||||
if e.Hidden {
|
||||
decorator.Hide()
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
|
||||
"bitbucket.org/hevanto/ui/uiwidget"
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/data/binding"
|
||||
"fyne.io/fyne/v2/layout"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
@ -256,25 +255,7 @@ func (w Widget) Build(
|
||||
return
|
||||
}
|
||||
|
||||
decorator = widget
|
||||
if e.Decorators != nil {
|
||||
for _, dec := range e.Decorators {
|
||||
switch dec {
|
||||
case "Border":
|
||||
decorator = uiwidget.NewWidgetBorder(decorator)
|
||||
case "HCenter":
|
||||
decorator = container.NewHBox(
|
||||
layout.NewSpacer(),
|
||||
decorator,
|
||||
layout.NewSpacer())
|
||||
case "VCenter":
|
||||
decorator = container.NewVBox(
|
||||
layout.NewSpacer(),
|
||||
decorator,
|
||||
layout.NewSpacer())
|
||||
}
|
||||
}
|
||||
}
|
||||
decorator = applyDecorators(e, widget)
|
||||
|
||||
if e.Hidden {
|
||||
decorator.Hide()
|
||||
@ -322,7 +303,7 @@ func (w Widget) buildCalendarWidget(
|
||||
if e.TimeFormat != nil {
|
||||
timeFormat = parseTimeFormat(*e.TimeFormat)
|
||||
}
|
||||
if t, err = time.Parse(timeFormat, *e.Time); err != nil {
|
||||
if t, err = time.ParseInLocation(timeFormat, *e.Time, time.Local); err != nil {
|
||||
err = fmt.Errorf("CalendarWidget: failed to parse time: %w", err)
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user