add container set method

This commit is contained in:
Jay
2019-01-24 11:44:34 +08:00
parent b2a6f95229
commit 9aadc7c1d0
4 changed files with 38 additions and 2 deletions
+19
View File
@@ -85,3 +85,22 @@ type TextComponent struct {
Color NullString `json:"color,omitempty"`
Action interface{} `json:"action,omitempty"`
}
// NewBoxComponent -
func NewBoxComponent(layout string) (box *BoxComponent) {
box = &BoxComponent{}
box.Type = "box"
box.SetLayout(layout)
return
}
// SetLayout -
func (p *BoxComponent) SetLayout(layout string) {
switch layout {
case "horizontal":
case "vertical":
p.Layout = layout
default:
p.Layout = "horizontal"
}
}
+16 -2
View File
@@ -44,9 +44,23 @@ func NewCarouselContainer() *CarouselContainer {
}
// AddContent -
func (p *CarouselContainer) AddContent(obj ...*BubbleContainer) (err error) {
if len(obj) == 0 {
func (p *CarouselContainer) AddContent(items ...*BubbleContainer) (err error) {
if len(items) == 0 {
return errors.New("no item")
}
if len(items) > 10 {
return errors.New("too many items")
}
if len(items)+len(p.Contents) > 10 {
return errors.New("too many items")
}
for _, v := range items {
if v == nil {
continue
}
p.Contents = append(p.Contents, v)
}
return
}