add container set method
This commit is contained in:
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user