Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Commit

Permalink
fix: validate widget extended when moved
Browse files Browse the repository at this point in the history
  • Loading branch information
rot1024 committed Sep 26, 2021
1 parent 94611f9 commit a7daf79
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
16 changes: 12 additions & 4 deletions internal/usecase/interactor/scene.go
Expand Up @@ -298,10 +298,18 @@ func (i *Scene) UpdateWidget(ctx context.Context, param interfaces.UpdateWidgetP
}

if param.Extended != nil {
if layout := extension.WidgetLayout(); layout != nil {
if layout.HorizontallyExtendable() && location.Horizontal() || layout.VerticallyExtendable() && location.Vertical() {
widget.SetExtended(*param.Extended)
}
widget.SetExtended(*param.Extended)
}

// check extendable
if layout := extension.WidgetLayout(); layout != nil {
extendable := layout.Extendable(plugin.WidgetLocation{
Zone: plugin.WidgetZoneType(location.Zone),
Section: plugin.WidgetSectionType(location.Section),
Area: plugin.WidgetAreaType(location.Area),
})
if extendable && widget.Extended() {
widget.SetExtended(*param.Extended)
}
}

Expand Down
12 changes: 12 additions & 0 deletions pkg/plugin/extension.go
Expand Up @@ -88,6 +88,10 @@ type WidgetLayout struct {
defaultLocation *WidgetLocation
}

func (l WidgetLayout) Extendable(loc WidgetLocation) bool {
return l.HorizontallyExtendable() && loc.Horizontal() || l.VerticallyExtendable() && loc.Vertical()
}

func NewWidgetLayout(horizontallyExtendable, verticallyExtendable, extended, floating bool, defaultLocation *WidgetLocation) WidgetLayout {
return WidgetLayout{
horizontallyExtendable: horizontallyExtendable,
Expand Down Expand Up @@ -131,6 +135,14 @@ type WidgetLocation struct {
Area WidgetAreaType
}

func (l WidgetLocation) Horizontal() bool {
return l.Section == WidgetSectionCenter
}

func (l WidgetLocation) Vertical() bool {
return l.Area == WidgetAreaMiddle
}

func (l *WidgetLocation) CopyRef() *WidgetLocation {
if l == nil {
return nil
Expand Down

0 comments on commit a7daf79

Please sign in to comment.