Added decorators for centering
This commit is contained in:
parent
8befd14d13
commit
0f3932b810
@ -7,6 +7,7 @@ import (
|
|||||||
"bitbucket.org/hevanto/ui/uiwidget"
|
"bitbucket.org/hevanto/ui/uiwidget"
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
"fyne.io/fyne/v2/container"
|
"fyne.io/fyne/v2/container"
|
||||||
|
"fyne.io/fyne/v2/layout"
|
||||||
)
|
)
|
||||||
|
|
||||||
// The constants for the Containers
|
// The constants for the Containers
|
||||||
@ -50,17 +51,17 @@ func (cnt Container) Build(
|
|||||||
e *Element,
|
e *Element,
|
||||||
s ScreenHandler,
|
s ScreenHandler,
|
||||||
) (
|
) (
|
||||||
container fyne.CanvasObject,
|
cont fyne.CanvasObject,
|
||||||
decorator fyne.CanvasObject,
|
decorator fyne.CanvasObject,
|
||||||
err error,
|
err error,
|
||||||
) {
|
) {
|
||||||
switch cnt {
|
switch cnt {
|
||||||
case HScroll:
|
case HScroll:
|
||||||
container, err = cnt.buildHScrollContainer(e, s)
|
cont, err = cnt.buildHScrollContainer(e, s)
|
||||||
case Scroll:
|
case Scroll:
|
||||||
container, err = cnt.buildScrollContainer(e, s)
|
cont, err = cnt.buildScrollContainer(e, s)
|
||||||
case VScroll:
|
case VScroll:
|
||||||
container, err = cnt.buildVScrollContainer(e, s)
|
cont, err = cnt.buildVScrollContainer(e, s)
|
||||||
default:
|
default:
|
||||||
err = errors.New("invalid container")
|
err = errors.New("invalid container")
|
||||||
}
|
}
|
||||||
@ -68,12 +69,22 @@ func (cnt Container) Build(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
decorator = container
|
decorator = cont
|
||||||
if e.Decorators != nil {
|
if e.Decorators != nil {
|
||||||
for _, dec := range e.Decorators {
|
for _, dec := range e.Decorators {
|
||||||
switch dec {
|
switch dec {
|
||||||
case "Border":
|
case "Border":
|
||||||
decorator = uiwidget.NewWidgetBorder(decorator)
|
decorator = uiwidget.NewWidgetBorder(decorator)
|
||||||
|
case "HCenter":
|
||||||
|
decorator = container.NewHBox(
|
||||||
|
layout.NewSpacer(),
|
||||||
|
decorator,
|
||||||
|
layout.NewSpacer())
|
||||||
|
case "VCenter":
|
||||||
|
decorator = container.NewVBox(
|
||||||
|
layout.NewSpacer(),
|
||||||
|
decorator,
|
||||||
|
layout.NewSpacer())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,25 +87,25 @@ func (l Layout) Build(
|
|||||||
e *Element,
|
e *Element,
|
||||||
s ScreenHandler,
|
s ScreenHandler,
|
||||||
) (
|
) (
|
||||||
layout fyne.CanvasObject,
|
lay fyne.CanvasObject,
|
||||||
decorator fyne.CanvasObject,
|
decorator fyne.CanvasObject,
|
||||||
err error,
|
err error,
|
||||||
) {
|
) {
|
||||||
switch l {
|
switch l {
|
||||||
case Border:
|
case Border:
|
||||||
layout, err = l.buildBorderLayout(e, s)
|
lay, err = l.buildBorderLayout(e, s)
|
||||||
case Form:
|
case Form:
|
||||||
layout, err = l.buildFormLayout(e, s)
|
lay, err = l.buildFormLayout(e, s)
|
||||||
case Grid:
|
case Grid:
|
||||||
layout, err = l.buildGridLayout(e, s)
|
lay, err = l.buildGridLayout(e, s)
|
||||||
case HBox:
|
case HBox:
|
||||||
layout, err = l.buildHBoxLayout(e, s)
|
lay, err = l.buildHBoxLayout(e, s)
|
||||||
case MinSize:
|
case MinSize:
|
||||||
layout, err = l.buildMinSizeLayout(e, s)
|
lay, err = l.buildMinSizeLayout(e, s)
|
||||||
case Stack:
|
case Stack:
|
||||||
layout, err = l.buildStackLayout(e, s)
|
lay, err = l.buildStackLayout(e, s)
|
||||||
case VBox:
|
case VBox:
|
||||||
layout, err = l.buildVBoxLayout(e, s)
|
lay, err = l.buildVBoxLayout(e, s)
|
||||||
default:
|
default:
|
||||||
err = errors.New("invalid layout")
|
err = errors.New("invalid layout")
|
||||||
}
|
}
|
||||||
@ -113,12 +113,22 @@ func (l Layout) Build(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
decorator = layout
|
decorator = lay
|
||||||
if e.Decorators != nil {
|
if e.Decorators != nil {
|
||||||
for _, dec := range e.Decorators {
|
for _, dec := range e.Decorators {
|
||||||
switch dec {
|
switch dec {
|
||||||
case "Border":
|
case "Border":
|
||||||
decorator = uiwidget.NewWidgetBorder(decorator)
|
decorator = uiwidget.NewWidgetBorder(decorator)
|
||||||
|
case "HCenter":
|
||||||
|
decorator = container.NewHBox(
|
||||||
|
layout.NewSpacer(),
|
||||||
|
decorator,
|
||||||
|
layout.NewSpacer())
|
||||||
|
case "VCenter":
|
||||||
|
decorator = container.NewVBox(
|
||||||
|
layout.NewSpacer(),
|
||||||
|
decorator,
|
||||||
|
layout.NewSpacer())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
|
|
||||||
"bitbucket.org/hevanto/ui/uiwidget"
|
"bitbucket.org/hevanto/ui/uiwidget"
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
|
"fyne.io/fyne/v2/container"
|
||||||
"fyne.io/fyne/v2/data/binding"
|
"fyne.io/fyne/v2/data/binding"
|
||||||
"fyne.io/fyne/v2/layout"
|
"fyne.io/fyne/v2/layout"
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
@ -167,6 +168,8 @@ const (
|
|||||||
// - onUnselect: The on unselect function for the list
|
// - onUnselect: The on unselect function for the list
|
||||||
List Widget = "List"
|
List Widget = "List"
|
||||||
|
|
||||||
|
RichText Widget = "RichText"
|
||||||
|
|
||||||
// Select Widget
|
// Select Widget
|
||||||
Select Widget = "Select"
|
Select Widget = "Select"
|
||||||
|
|
||||||
@ -227,6 +230,8 @@ func (w Widget) Build(
|
|||||||
widget, err = w.buildLabelWidget(e, s)
|
widget, err = w.buildLabelWidget(e, s)
|
||||||
case List:
|
case List:
|
||||||
widget, err = w.buildListWidget(e, s)
|
widget, err = w.buildListWidget(e, s)
|
||||||
|
case RichText:
|
||||||
|
widget, err = w.buildRichTextWidget(e, s)
|
||||||
case Select:
|
case Select:
|
||||||
widget, err = w.buildSelectWidget(e, s)
|
widget, err = w.buildSelectWidget(e, s)
|
||||||
case SelectEntry:
|
case SelectEntry:
|
||||||
@ -250,6 +255,16 @@ func (w Widget) Build(
|
|||||||
switch dec {
|
switch dec {
|
||||||
case "Border":
|
case "Border":
|
||||||
decorator = uiwidget.NewWidgetBorder(decorator)
|
decorator = uiwidget.NewWidgetBorder(decorator)
|
||||||
|
case "HCenter":
|
||||||
|
decorator = container.NewHBox(
|
||||||
|
layout.NewSpacer(),
|
||||||
|
decorator,
|
||||||
|
layout.NewSpacer())
|
||||||
|
case "VCenter":
|
||||||
|
decorator = container.NewVBox(
|
||||||
|
layout.NewSpacer(),
|
||||||
|
decorator,
|
||||||
|
layout.NewSpacer())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -483,6 +498,36 @@ func (w Widget) buildListWidget(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w Widget) buildRichTextWidget(
|
||||||
|
e *Element,
|
||||||
|
s ScreenHandler,
|
||||||
|
) (c fyne.CanvasObject, err error) {
|
||||||
|
var rt *widget.RichText
|
||||||
|
|
||||||
|
if e.Binding != "" {
|
||||||
|
data := s.GetBinding(e.Binding).(binding.String)
|
||||||
|
txt, _ := data.Get()
|
||||||
|
rt = widget.NewRichTextFromMarkdown(txt)
|
||||||
|
data.AddListener(binding.NewDataListener(func() {
|
||||||
|
txt, _ := data.Get()
|
||||||
|
rt.ParseMarkdown(txt)
|
||||||
|
}))
|
||||||
|
} else {
|
||||||
|
rt = widget.NewRichTextFromMarkdown(e.Text)
|
||||||
|
}
|
||||||
|
|
||||||
|
for opt, val := range e.Options {
|
||||||
|
switch opt {
|
||||||
|
case "wrapping":
|
||||||
|
rt.Wrapping = getTextWrap(val)
|
||||||
|
case "truncation":
|
||||||
|
rt.Truncation = getTruncation(val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c = rt
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (w Widget) buildSelectWidget(
|
func (w Widget) buildSelectWidget(
|
||||||
e *Element,
|
e *Element,
|
||||||
s ScreenHandler,
|
s ScreenHandler,
|
||||||
|
Loading…
Reference in New Issue
Block a user