Added decorators for centering
This commit is contained in:
parent
8befd14d13
commit
0f3932b810
@ -7,6 +7,7 @@ import (
|
||||
"bitbucket.org/hevanto/ui/uiwidget"
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/layout"
|
||||
)
|
||||
|
||||
// The constants for the Containers
|
||||
@ -50,17 +51,17 @@ func (cnt Container) Build(
|
||||
e *Element,
|
||||
s ScreenHandler,
|
||||
) (
|
||||
container fyne.CanvasObject,
|
||||
cont fyne.CanvasObject,
|
||||
decorator fyne.CanvasObject,
|
||||
err error,
|
||||
) {
|
||||
switch cnt {
|
||||
case HScroll:
|
||||
container, err = cnt.buildHScrollContainer(e, s)
|
||||
cont, err = cnt.buildHScrollContainer(e, s)
|
||||
case Scroll:
|
||||
container, err = cnt.buildScrollContainer(e, s)
|
||||
cont, err = cnt.buildScrollContainer(e, s)
|
||||
case VScroll:
|
||||
container, err = cnt.buildVScrollContainer(e, s)
|
||||
cont, err = cnt.buildVScrollContainer(e, s)
|
||||
default:
|
||||
err = errors.New("invalid container")
|
||||
}
|
||||
@ -68,12 +69,22 @@ func (cnt Container) Build(
|
||||
return
|
||||
}
|
||||
|
||||
decorator = container
|
||||
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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -87,25 +87,25 @@ func (l Layout) Build(
|
||||
e *Element,
|
||||
s ScreenHandler,
|
||||
) (
|
||||
layout fyne.CanvasObject,
|
||||
lay fyne.CanvasObject,
|
||||
decorator fyne.CanvasObject,
|
||||
err error,
|
||||
) {
|
||||
switch l {
|
||||
case Border:
|
||||
layout, err = l.buildBorderLayout(e, s)
|
||||
lay, err = l.buildBorderLayout(e, s)
|
||||
case Form:
|
||||
layout, err = l.buildFormLayout(e, s)
|
||||
lay, err = l.buildFormLayout(e, s)
|
||||
case Grid:
|
||||
layout, err = l.buildGridLayout(e, s)
|
||||
lay, err = l.buildGridLayout(e, s)
|
||||
case HBox:
|
||||
layout, err = l.buildHBoxLayout(e, s)
|
||||
lay, err = l.buildHBoxLayout(e, s)
|
||||
case MinSize:
|
||||
layout, err = l.buildMinSizeLayout(e, s)
|
||||
lay, err = l.buildMinSizeLayout(e, s)
|
||||
case Stack:
|
||||
layout, err = l.buildStackLayout(e, s)
|
||||
lay, err = l.buildStackLayout(e, s)
|
||||
case VBox:
|
||||
layout, err = l.buildVBoxLayout(e, s)
|
||||
lay, err = l.buildVBoxLayout(e, s)
|
||||
default:
|
||||
err = errors.New("invalid layout")
|
||||
}
|
||||
@ -113,12 +113,22 @@ func (l Layout) Build(
|
||||
return
|
||||
}
|
||||
|
||||
decorator = layout
|
||||
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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ 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"
|
||||
@ -167,6 +168,8 @@ const (
|
||||
// - onUnselect: The on unselect function for the list
|
||||
List Widget = "List"
|
||||
|
||||
RichText Widget = "RichText"
|
||||
|
||||
// Select Widget
|
||||
Select Widget = "Select"
|
||||
|
||||
@ -227,6 +230,8 @@ func (w Widget) Build(
|
||||
widget, err = w.buildLabelWidget(e, s)
|
||||
case List:
|
||||
widget, err = w.buildListWidget(e, s)
|
||||
case RichText:
|
||||
widget, err = w.buildRichTextWidget(e, s)
|
||||
case Select:
|
||||
widget, err = w.buildSelectWidget(e, s)
|
||||
case SelectEntry:
|
||||
@ -250,6 +255,16 @@ func (w Widget) Build(
|
||||
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())
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -483,6 +498,36 @@ func (w Widget) buildListWidget(
|
||||
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(
|
||||
e *Element,
|
||||
s ScreenHandler,
|
||||
|
Loading…
Reference in New Issue
Block a user