Skip to content

Commit

Permalink
Only read pad once in each function
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Aug 11, 2023
1 parent 3cd4d07 commit 09ffd38
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions widget/accordion.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ type accordionRenderer struct {
}

func (r *accordionRenderer) Layout(size fyne.Size) {
dividerOff := (theme.Padding() + theme.SeparatorThicknessSize()) / 2
pad := theme.Padding()
dividerOff := (pad + theme.SeparatorThicknessSize()) / 2
x := float32(0)
y := float32(0)
hasOpen := 0
Expand All @@ -128,11 +129,11 @@ func (r *accordionRenderer) Layout(size fyne.Size) {
y += min

if ai.Open {
y += theme.Padding()
y += pad
hasOpen++
}
if i < len(r.container.Items)-1 {
y += theme.Padding()
y += pad
}
}

Expand Down Expand Up @@ -160,15 +161,16 @@ func (r *accordionRenderer) Layout(size fyne.Size) {
y += openSize
}
if i < len(r.container.Items)-1 {
y += theme.Padding()
y += pad
}
}
}

func (r *accordionRenderer) MinSize() (size fyne.Size) {
pad := theme.Padding()
for i, ai := range r.container.Items {
if i != 0 {
size.Height += theme.Padding()
size.Height += pad
}
min := r.headers[i].MinSize()
size.Width = fyne.Max(size.Width, min.Width)
Expand All @@ -177,7 +179,7 @@ func (r *accordionRenderer) MinSize() (size fyne.Size) {
size.Width = fyne.Max(size.Width, min.Width)
if ai.Open {
size.Height += min.Height
size.Height += theme.Padding()
size.Height += pad
}
}
return
Expand Down

0 comments on commit 09ffd38

Please sign in to comment.