update
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
package line
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
// Component -
|
||||
type Component struct {
|
||||
Type string `json:"type"`
|
||||
@@ -16,6 +20,49 @@ type BoxComponent struct {
|
||||
Margin NullString `json:"margin,omitempty"`
|
||||
}
|
||||
|
||||
// SetLayout -
|
||||
func (p *BoxComponent) SetLayout(layout string) {
|
||||
switch layout {
|
||||
case "horizontal":
|
||||
case "vertical":
|
||||
case "baseline":
|
||||
p.Layout = layout
|
||||
default:
|
||||
p.Layout = "horizontal"
|
||||
}
|
||||
}
|
||||
|
||||
// SetContent -
|
||||
func (p *BoxComponent) SetContent(content interface{}) (err error) {
|
||||
if p.Layout == "horizontal" || p.Layout == "vertical" {
|
||||
switch content.(type) {
|
||||
case *BoxComponent:
|
||||
case *ButtonComponent:
|
||||
case *FillerComponent:
|
||||
case *ImageComponent:
|
||||
case *SeparatorComponent:
|
||||
case *SpacerComponent:
|
||||
case *TextComponent:
|
||||
p.Contents = append(p.Contents, content)
|
||||
default:
|
||||
return errors.New("content type not allow")
|
||||
}
|
||||
} else if p.Layout == "baseline" {
|
||||
switch content.(type) {
|
||||
case *FillerComponent:
|
||||
case *IconComponent:
|
||||
case *SpacerComponent:
|
||||
case *TextComponent:
|
||||
p.Contents = append(p.Contents, content)
|
||||
default:
|
||||
return errors.New("content type not allow")
|
||||
}
|
||||
} else {
|
||||
return errors.New("layout type not valid")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ButtonComponent -
|
||||
type ButtonComponent struct {
|
||||
Component
|
||||
@@ -94,13 +141,32 @@ func NewBoxComponent(layout string) (box *BoxComponent) {
|
||||
return
|
||||
}
|
||||
|
||||
// SetLayout -
|
||||
func (p *BoxComponent) SetLayout(layout string) {
|
||||
switch layout {
|
||||
case "horizontal":
|
||||
case "vertical":
|
||||
p.Layout = layout
|
||||
default:
|
||||
p.Layout = "horizontal"
|
||||
}
|
||||
// NewButtonComponent -
|
||||
func NewButtonComponent() (btn *ButtonComponent) {
|
||||
btn = &ButtonComponent{}
|
||||
btn.Type = "button"
|
||||
return
|
||||
}
|
||||
|
||||
// NewFillerComponent -
|
||||
func NewFillerComponent() (filler *FillerComponent) {
|
||||
filler = &FillerComponent{}
|
||||
filler.Type = "filler"
|
||||
return
|
||||
}
|
||||
|
||||
// NewIconComponent -
|
||||
func NewIconComponent(imgUrl string) (icon *IconComponent) {
|
||||
icon = &IconComponent{}
|
||||
icon.Type = "icon"
|
||||
icon.URL = imgUrl
|
||||
return
|
||||
}
|
||||
|
||||
// NewImageComponent -
|
||||
func NewImageComponent(imgUrl string) (image *ImageComponent) {
|
||||
image = &ImageComponent{}
|
||||
image.Type = "image"
|
||||
image.URL = imgUrl
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user