Skip to content

Commit

Permalink
Remove internal property lock from base widget too
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Dec 16, 2024
1 parent 3f051ca commit 4837356
Show file tree
Hide file tree
Showing 18 changed files with 5 additions and 342 deletions.
30 changes: 0 additions & 30 deletions widget/accordion.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,26 @@ func NewAccordion(items ...*AccordionItem) *Accordion {

// Append adds the given item to this Accordion.
func (a *Accordion) Append(item *AccordionItem) {
a.propertyLock.Lock()
a.Items = append(a.Items, item)
a.propertyLock.Unlock()

a.Refresh()
}

// Close collapses the item at the given index.
func (a *Accordion) Close(index int) {
a.propertyLock.Lock()
if index < 0 || index >= len(a.Items) {
a.propertyLock.Unlock()
return
}
a.Items[index].Open = false
a.propertyLock.Unlock()

a.Refresh()
}

// CloseAll collapses all items.
func (a *Accordion) CloseAll() {
a.propertyLock.Lock()
for _, i := range a.Items {
i.Open = false
}
a.propertyLock.Unlock()

a.Refresh()
}
Expand All @@ -75,10 +68,7 @@ func (a *Accordion) MinSize() fyne.Size {

// Open expands the item at the given index.
func (a *Accordion) Open(index int) {
a.propertyLock.Lock()

if index < 0 || index >= len(a.Items) {
a.propertyLock.Unlock()
return
}

Expand All @@ -89,35 +79,27 @@ func (a *Accordion) Open(index int) {
ai.Open = false
}
}
a.propertyLock.Unlock()

a.Refresh()
}

// OpenAll expands all items.
func (a *Accordion) OpenAll() {
a.propertyLock.RLock()
multiOpen := a.MultiOpen
a.propertyLock.RUnlock()

if !multiOpen {
return
}

a.propertyLock.Lock()
for _, i := range a.Items {
i.Open = true
}
a.propertyLock.Unlock()

a.Refresh()
}

// Remove deletes the given item from this Accordion.
func (a *Accordion) Remove(item *AccordionItem) {
a.propertyLock.Lock()
defer a.propertyLock.Unlock()

for i, ai := range a.Items {
if ai == item {
a.Items = append(a.Items[:i], a.Items[i+1:]...)
Expand All @@ -128,13 +110,10 @@ func (a *Accordion) Remove(item *AccordionItem) {

// RemoveIndex deletes the item at the given index from this Accordion.
func (a *Accordion) RemoveIndex(index int) {
a.propertyLock.Lock()
if index < 0 || index >= len(a.Items) {
a.propertyLock.Unlock()
return
}
a.Items = append(a.Items[:index], a.Items[index+1:]...)
a.propertyLock.Unlock()

a.Refresh()
}
Expand All @@ -155,9 +134,6 @@ func (r *accordionRenderer) Layout(size fyne.Size) {
y := float32(0)
hasOpen := 0

r.container.propertyLock.RLock()
defer r.container.propertyLock.RUnlock()

for i, ai := range r.container.Items {
h := r.headers[i]
min := h.MinSize().Height
Expand Down Expand Up @@ -206,9 +182,6 @@ func (r *accordionRenderer) MinSize() fyne.Size {
pad := th.Size(theme.SizeNamePadding)
size := fyne.Size{}

r.container.propertyLock.RLock()
defer r.container.propertyLock.RUnlock()

for i, ai := range r.container.Items {
if i != 0 {
size.Height += pad
Expand All @@ -234,9 +207,6 @@ func (r *accordionRenderer) Refresh() {
}

func (r *accordionRenderer) updateObjects() {
r.container.propertyLock.RLock()
defer r.container.propertyLock.RUnlock()

th := r.container.themeWithLock()
is := len(r.container.Items)
hs := len(r.headers)
Expand Down
12 changes: 0 additions & 12 deletions widget/button.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ func (b *Button) CreateRenderer() fyne.WidgetRenderer {
th := b.Theme()
v := fyne.CurrentApp().Settings().ThemeVariant()

b.propertyLock.RLock()
defer b.propertyLock.RUnlock()

seg := &TextSegment{Text: b.Text, Style: RichTextStyleStrong}
seg.Style.Alignment = fyne.TextAlignCenter
text := NewRichText(seg)
Expand Down Expand Up @@ -166,18 +163,14 @@ func (b *Button) MouseOut() {

// SetIcon updates the icon on a label - pass nil to hide an icon
func (b *Button) SetIcon(icon fyne.Resource) {
b.propertyLock.Lock()
b.Icon = icon
b.propertyLock.Unlock()

b.Refresh()
}

// SetText allows the button label to be changed
func (b *Button) SetText(text string) {
b.propertyLock.Lock()
b.Text = text
b.propertyLock.Unlock()

b.Refresh()
}
Expand Down Expand Up @@ -245,9 +238,6 @@ func (r *buttonRenderer) Layout(size fyne.Size) {
iconSize := fyne.NewSquareSize(th.Size(theme.SizeNameInlineIcon))
labelSize := r.label.MinSize()

r.button.propertyLock.RLock()
defer r.button.propertyLock.RUnlock()

if hasLabel {
if hasIcon {
// Both
Expand Down Expand Up @@ -303,11 +293,9 @@ func (r *buttonRenderer) Refresh() {
th := r.button.Theme()
r.label.inset = fyne.NewSquareSize(th.Size(theme.SizeNameInnerPadding))

r.button.propertyLock.RLock()
r.label.Segments[0].(*TextSegment).Text = r.button.Text
r.updateIconAndText()
r.applyTheme()
r.button.propertyLock.RUnlock()

r.background.Refresh()
r.Layout(r.button.Size())
Expand Down
14 changes: 1 addition & 13 deletions widget/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,13 @@ func (c *Check) Bind(data binding.Bool) {
// SetChecked sets the checked state and refreshes widget
// If the `Partial` state is set this will be turned off to respect the `checked` bool passed in here.
func (c *Check) SetChecked(checked bool) {
c.propertyLock.Lock()
if checked == c.Checked && !c.Partial {
c.propertyLock.Unlock()
return
}

c.Partial = false
c.Checked = checked
onChanged := c.OnChanged
c.propertyLock.Unlock()

if onChanged != nil {
onChanged(checked)
Expand Down Expand Up @@ -169,8 +166,6 @@ func (c *Check) CreateRenderer() fyne.WidgetRenderer {
bg := canvas.NewImageFromResource(th.Icon(theme.IconNameCheckButtonFill))
icon := canvas.NewImageFromResource(th.Icon(theme.IconNameCheckButton))

c.propertyLock.RLock()
defer c.propertyLock.RUnlock()
text := canvas.NewText(c.Text, th.Color(theme.ColorNameForeground, v))
text.Alignment = fyne.TextAlignLeading

Expand Down Expand Up @@ -224,9 +219,7 @@ func (c *Check) TypedKey(key *fyne.KeyEvent) {}
//
// Since: 2.4
func (c *Check) SetText(text string) {
c.propertyLock.Lock()
c.Text = text
c.propertyLock.Unlock()
c.Refresh()
}

Expand Down Expand Up @@ -291,10 +284,7 @@ func (c *checkRenderer) MinSize() fyne.Size {
pad4 := th.Size(theme.SizeNameInnerPadding) * 2
min := c.label.MinSize().Add(fyne.NewSize(th.Size(theme.SizeNameInlineIcon)+pad4, pad4))

c.check.propertyLock.RLock()
text := c.check.Text
c.check.propertyLock.RUnlock()
if text != "" {
if c.check.Text != "" {
min.Add(fyne.NewSize(th.Size(theme.SizeNamePadding), 0))
}

Expand Down Expand Up @@ -338,12 +328,10 @@ func (c *checkRenderer) Refresh() {
th := c.check.Theme()
v := fyne.CurrentApp().Settings().ThemeVariant()

c.check.propertyLock.RLock()
c.applyTheme(th, v)
c.updateLabel()
c.updateResource(th)
c.updateFocusIndicator(th, v)
c.check.propertyLock.RUnlock()
canvas.Refresh(c.check.super())
}

Expand Down
4 changes: 0 additions & 4 deletions widget/check_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ func (r *CheckGroup) Append(option string) {
// CreateRenderer is a private method to Fyne which links this widget to its renderer
func (r *CheckGroup) CreateRenderer() fyne.WidgetRenderer {
r.ExtendBaseWidget(r)
r.propertyLock.Lock()
defer r.propertyLock.Unlock()

r.update()
objects := make([]fyne.CanvasObject, len(r.items))
Expand All @@ -70,9 +68,7 @@ func (r *CheckGroup) MinSize() fyne.Size {
//
// Implements: fyne.CanvasObject
func (r *CheckGroup) Refresh() {
r.propertyLock.Lock()
r.update()
r.propertyLock.Unlock()
r.BaseWidget.Refresh()
}

Expand Down
Loading

0 comments on commit 4837356

Please sign in to comment.