From 48373567db24ef765928b283515b98269ce95a9f Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Mon, 16 Dec 2024 19:45:24 +0000 Subject: [PATCH] Remove internal property lock from base widget too --- widget/accordion.go | 30 --------- widget/button.go | 12 ---- widget/check.go | 14 +--- widget/check_group.go | 4 -- widget/entry.go | 122 +--------------------------------- widget/entry_password.go | 2 - widget/entry_validation.go | 2 - widget/fileicon.go | 9 --- widget/hyperlink.go | 17 ----- widget/icon.go | 4 -- widget/label.go | 5 -- widget/list.go | 7 -- widget/progressbarinfinite.go | 25 ------- widget/richtext.go | 20 +----- widget/select.go | 7 -- widget/table.go | 29 -------- widget/tree.go | 21 ------ widget/widget.go | 17 +---- 18 files changed, 5 insertions(+), 342 deletions(-) diff --git a/widget/accordion.go b/widget/accordion.go index a904ea55f8..9d617838cf 100644 --- a/widget/accordion.go +++ b/widget/accordion.go @@ -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() } @@ -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 } @@ -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:]...) @@ -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() } @@ -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 @@ -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 @@ -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) diff --git a/widget/button.go b/widget/button.go index c508bc0013..eea6fca21d 100644 --- a/widget/button.go +++ b/widget/button.go @@ -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) @@ -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() } @@ -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 @@ -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()) diff --git a/widget/check.go b/widget/check.go index ef57bd4d21..3466b71cfc 100644 --- a/widget/check.go +++ b/widget/check.go @@ -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) @@ -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 @@ -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() } @@ -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)) } @@ -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()) } diff --git a/widget/check_group.go b/widget/check_group.go index e2725b35ed..5c9c5764db 100644 --- a/widget/check_group.go +++ b/widget/check_group.go @@ -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)) @@ -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() } diff --git a/widget/entry.go b/widget/entry.go index 0f6b6198ba..ea732543dd 100644 --- a/widget/entry.go +++ b/widget/entry.go @@ -266,12 +266,10 @@ func (e *Entry) isTripleTap(nowMilli int64) bool { // // Implements: fyne.Draggable func (e *Entry) DragEnd() { - e.propertyLock.Lock() if e.CursorColumn == e.selectColumn && e.CursorRow == e.selectRow { e.selecting = false } shouldRefresh := !e.selecting - e.propertyLock.Unlock() if shouldRefresh { e.Refresh() } @@ -307,9 +305,7 @@ func (e *Entry) ExtendBaseWidget(wid fyne.Widget) { e.impl.Store(&wid) - e.propertyLock.Lock() e.registerShortcut() - e.propertyLock.Unlock() } // FocusGained is called when the Entry has been given focus. @@ -353,9 +349,6 @@ func (e *Entry) Hide() { // // Implements: mobile.Keyboardable func (e *Entry) Keyboard() mobile.KeyboardType { - e.propertyLock.RLock() - defer e.propertyLock.RUnlock() - if e.MultiLine { return mobile.DefaultKeyboard } else if e.Password { @@ -402,9 +395,7 @@ func (e *Entry) KeyUp(key *fyne.KeyEvent) { // // Implements: fyne.Widget func (e *Entry) MinSize() fyne.Size { - e.propertyLock.RLock() cached := e.minCache - e.propertyLock.RUnlock() if !cached.IsZero() { return cached } @@ -412,9 +403,7 @@ func (e *Entry) MinSize() fyne.Size { e.ExtendBaseWidget(e) min := e.BaseWidget.MinSize() - e.propertyLock.Lock() e.minCache = min - e.propertyLock.Unlock() return min } @@ -427,14 +416,12 @@ func (e *Entry) MouseDown(m *desktop.MouseEvent) { e.selectCurrentRow() return } - e.propertyLock.Lock() if e.selectKeyDown { e.selecting = true } if e.selecting && !e.selectKeyDown && m.Button == desktop.MouseButtonPrimary { e.selecting = false } - e.propertyLock.Unlock() e.updateMousePointer(m.Position, m.Button == desktop.MouseButtonSecondary) @@ -449,9 +436,6 @@ func (e *Entry) MouseDown(m *desktop.MouseEvent) { // // Implements: desktop.Mouseable func (e *Entry) MouseUp(m *desktop.MouseEvent) { - e.propertyLock.Lock() - defer e.propertyLock.Unlock() - start, _ := e.selection() if start == -1 && e.selecting && !e.selectKeyDown { e.selecting = false @@ -462,9 +446,7 @@ func (e *Entry) MouseUp(m *desktop.MouseEvent) { // // Since: 2.5 func (e *Entry) Redo() { - e.propertyLock.Lock() newText, action := e.undoStack.Redo(e.Text) - e.propertyLock.Unlock() modify, ok := action.(*entryModifyAction) if !ok { return @@ -473,17 +455,13 @@ func (e *Entry) Redo() { if !modify.Delete { pos += len(modify.Text) } - e.propertyLock.Lock() e.updateText(newText, false) e.CursorRow, e.CursorColumn = e.rowColFromTextPos(pos) - e.propertyLock.Unlock() e.Refresh() } func (e *Entry) Refresh() { - e.propertyLock.Lock() e.minCache = fyne.Size{} - e.propertyLock.Unlock() e.BaseWidget.Refresh() } @@ -491,9 +469,6 @@ func (e *Entry) Refresh() { // SelectedText returns the text currently selected in this Entry. // If there is no selection it will return the empty string. func (e *Entry) SelectedText() string { - e.propertyLock.RLock() - defer e.propertyLock.RUnlock() - if !e.selecting { return "" } @@ -521,9 +496,7 @@ func (e *Entry) SetMinRowsVisible(count int) { func (e *Entry) SetPlaceHolder(text string) { e.Theme() // setup theme cache before locking - e.propertyLock.Lock() e.PlaceHolder = text - e.propertyLock.Unlock() e.placeholderProvider().Segments[0].(*TextSegment).Text = text e.placeholder.updateRowBounds() @@ -541,23 +514,19 @@ func (e *Entry) setText(text string, fromBinding bool) { e.updateTextAndRefresh(text, fromBinding) e.updateCursorAndSelection() - e.propertyLock.Lock() e.undoStack.Clear() - e.propertyLock.Unlock() } // Append appends the text to the end of the entry. // // Since: 2.4 func (e *Entry) Append(text string) { - e.propertyLock.Lock() provider := e.textProvider() provider.insertAt(provider.len(), []rune(text)) content := provider.String() changed := e.updateText(content, false) cb := e.OnChanged e.undoStack.Clear() - e.propertyLock.Unlock() if changed { e.validate() @@ -616,9 +585,7 @@ func (e *Entry) TappedSecondary(pe *fyne.PointEvent) { menu = fyne.NewMenu("", pasteItem, selectAllItem) } else { var menuItems []*fyne.MenuItem - e.propertyLock.Lock() canUndo, canRedo := e.undoStack.CanUndo(), e.undoStack.CanRedo() - e.propertyLock.Unlock() if canUndo { menuItems = append(menuItems, undoItem) } @@ -680,10 +647,8 @@ func (e *Entry) TypedKey(key *fyne.KeyEvent) { if e.cursorAnim != nil { e.cursorAnim.interrupt() } - e.propertyLock.RLock() provider := e.textProvider() multiLine := e.MultiLine - e.propertyLock.RUnlock() if e.selectKeyDown || e.selecting { if e.selectingKeyHandler(key) { @@ -694,14 +659,11 @@ func (e *Entry) TypedKey(key *fyne.KeyEvent) { switch key.Name { case fyne.KeyBackspace: - e.propertyLock.RLock() isEmpty := provider.len() == 0 || (e.CursorColumn == 0 && e.CursorRow == 0) - e.propertyLock.RUnlock() if isEmpty { return } - e.propertyLock.Lock() pos := e.cursorTextPos() deletedText := provider.deleteFromTo(pos-1, pos) e.CursorRow, e.CursorColumn = e.rowColFromTextPos(pos - 1) @@ -710,21 +672,18 @@ func (e *Entry) TypedKey(key *fyne.KeyEvent) { Position: pos - 1, Text: deletedText, }) - e.propertyLock.Unlock() case fyne.KeyDelete: pos := e.cursorTextPos() if provider.len() == 0 || pos == provider.len() { return } - e.propertyLock.Lock() deletedText := provider.deleteFromTo(pos, pos+1) e.undoStack.MergeOrAdd(&entryModifyAction{ Delete: true, Position: pos, Text: deletedText, }) - e.propertyLock.Unlock() case fyne.KeyReturn, fyne.KeyEnter: e.typedKeyReturn(provider, multiLine) case fyne.KeyTab: @@ -742,33 +701,27 @@ func (e *Entry) TypedKey(key *fyne.KeyEvent) { case fyne.KeyHome: e.typedKeyHome() case fyne.KeyPageUp: - e.propertyLock.Lock() if e.MultiLine { e.CursorRow = 0 } e.CursorColumn = 0 - e.propertyLock.Unlock() case fyne.KeyPageDown: - e.propertyLock.Lock() if e.MultiLine { e.CursorRow = provider.rows() - 1 e.CursorColumn = provider.rowLength(e.CursorRow) } else { e.CursorColumn = provider.len() } - e.propertyLock.Unlock() default: return } - e.propertyLock.Lock() content := provider.String() changed := e.updateText(content, false) if e.CursorRow == e.selectRow && e.CursorColumn == e.selectColumn { e.selecting = false } cb := e.OnChanged - e.propertyLock.Unlock() if changed { e.validate() if cb != nil { @@ -782,9 +735,7 @@ func (e *Entry) TypedKey(key *fyne.KeyEvent) { // // Since: 2.5 func (e *Entry) Undo() { - e.propertyLock.Lock() newText, action := e.undoStack.Undo(e.Text) - e.propertyLock.Unlock() modify, ok := action.(*entryModifyAction) if !ok { return @@ -793,16 +744,12 @@ func (e *Entry) Undo() { if modify.Delete { pos += len(modify.Text) } - e.propertyLock.Lock() e.updateText(newText, false) e.CursorRow, e.CursorColumn = e.rowColFromTextPos(pos) - e.propertyLock.Unlock() e.Refresh() } func (e *Entry) typedKeyUp(provider *RichText) { - e.propertyLock.Lock() - if e.CursorRow > 0 { e.CursorRow-- } else { @@ -813,11 +760,9 @@ func (e *Entry) typedKeyUp(provider *RichText) { if e.CursorColumn > rowLength { e.CursorColumn = rowLength } - e.propertyLock.Unlock() } func (e *Entry) typedKeyDown(provider *RichText) { - e.propertyLock.Lock() rowLength := provider.rowLength(e.CursorRow) if e.CursorRow < provider.rows()-1 { @@ -830,22 +775,18 @@ func (e *Entry) typedKeyDown(provider *RichText) { if e.CursorColumn > rowLength { e.CursorColumn = rowLength } - e.propertyLock.Unlock() } func (e *Entry) typedKeyLeft(provider *RichText) { - e.propertyLock.Lock() if e.CursorColumn > 0 { e.CursorColumn-- } else if e.MultiLine && e.CursorRow > 0 { e.CursorRow-- e.CursorColumn = provider.rowLength(e.CursorRow) } - e.propertyLock.Unlock() } func (e *Entry) typedKeyRight(provider *RichText) { - e.propertyLock.Lock() if e.MultiLine { rowLength := provider.rowLength(e.CursorRow) if e.CursorColumn < rowLength { @@ -857,23 +798,18 @@ func (e *Entry) typedKeyRight(provider *RichText) { } else if e.CursorColumn < provider.len() { e.CursorColumn++ } - e.propertyLock.Unlock() } func (e *Entry) typedKeyHome() { - e.propertyLock.Lock() e.CursorColumn = 0 - e.propertyLock.Unlock() } func (e *Entry) typedKeyEnd(provider *RichText) { - e.propertyLock.Lock() if e.MultiLine { e.CursorColumn = provider.rowLength(e.CursorRow) } else { e.CursorColumn = provider.len() } - e.propertyLock.Unlock() } // handler for Ctrl+[backspace/delete] - delete the word @@ -924,7 +860,6 @@ func (e *Entry) TypedRune(r rune) { return } - e.propertyLock.Lock() if e.popUp != nil { e.popUp.Hide() } @@ -949,7 +884,6 @@ func (e *Entry) TypedRune(r rune) { Position: pos, Text: runes, }) - e.propertyLock.Unlock() e.validate() if cb != nil { @@ -1012,11 +946,9 @@ func (e *Entry) cutToClipboard(clipboard fyne.Clipboard) { } e.copyToClipboard(clipboard) - e.propertyLock.Lock() e.eraseSelectionAndUpdate() content := e.Text cb := e.OnChanged - e.propertyLock.Unlock() e.validate() if cb != nil { @@ -1063,8 +995,6 @@ func (e *Entry) eraseSelectionAndUpdate() { func (e *Entry) getRowCol(p fyne.Position) (int, int) { th := e.Theme() textSize := th.Size(theme.SizeNameText) - e.propertyLock.RLock() - defer e.propertyLock.RUnlock() rowHeight := e.textProvider().charMinSize(e.Password, e.TextStyle, textSize).Height row := int(math.Floor(float64(p.Y+e.scroll.Offset.Y-th.Size(theme.SizeNameLineSpacing)) / float64(rowHeight))) @@ -1086,9 +1016,7 @@ func (e *Entry) getRowCol(p fyne.Position) (int, int) { func (e *Entry) pasteFromClipboard(clipboard fyne.Clipboard) { text := clipboard.Content() if text == "" { - e.propertyLock.Lock() changed := e.selecting && e.eraseSelection() - e.propertyLock.Unlock() if changed { e.Refresh() @@ -1102,7 +1030,6 @@ func (e *Entry) pasteFromClipboard(clipboard fyne.Clipboard) { text = strings.Replace(text, "\n", " ", -1) } - e.propertyLock.Lock() if e.selecting { e.eraseSelection() } @@ -1120,7 +1047,6 @@ func (e *Entry) pasteFromClipboard(clipboard fyne.Clipboard) { e.updateText(content, false) e.CursorRow, e.CursorColumn = e.rowColFromTextPos(pos + len(runes)) cb := e.OnChanged - e.propertyLock.Unlock() e.validate() if cb != nil { @@ -1228,10 +1154,7 @@ func (e *Entry) registerShortcut() { if s.(*desktop.CustomShortcut).KeyName == fyne.KeyLeft { e.typedKeyHome() } else { - e.propertyLock.RLock() - provider := e.textProvider() - e.propertyLock.RUnlock() - e.typedKeyEnd(provider) + e.typedKeyEnd(e.textProvider()) } e.Refresh() } @@ -1322,11 +1245,9 @@ func (e *Entry) selectingKeyHandler(key *fyne.KeyEvent) bool { switch key.Name { case fyne.KeyBackspace, fyne.KeyDelete: // clears the selection -- return handled - e.propertyLock.Lock() e.eraseSelectionAndUpdate() content := e.Text cb := e.OnChanged - e.propertyLock.Unlock() e.validate() if cb != nil { @@ -1346,19 +1267,15 @@ func (e *Entry) selectingKeyHandler(key *fyne.KeyEvent) bool { switch key.Name { case fyne.KeyLeft: // seek to the start of the selection -- return handled - e.propertyLock.Lock() selectStart, _ := e.selection() e.CursorRow, e.CursorColumn = e.rowColFromTextPos(selectStart) e.selecting = false - e.propertyLock.Unlock() return true case fyne.KeyRight: // seek to the end of the selection -- return handled _, selectEnd := e.selection() - e.propertyLock.Lock() e.CursorRow, e.CursorColumn = e.rowColFromTextPos(selectEnd) e.selecting = false - e.propertyLock.Unlock() return true case fyne.KeyUp, fyne.KeyDown, fyne.KeyEnd, fyne.KeyHome, fyne.KeyPageUp, fyne.KeyPageDown: // cursor movement without left or right shift -- clear selection and return unhandled @@ -1470,8 +1387,6 @@ func (e *Entry) textWrap() fyne.TextWrap { } func (e *Entry) updateCursorAndSelection() { - e.propertyLock.Lock() - defer e.propertyLock.Unlock() e.CursorRow, e.CursorColumn = e.truncatePosition(e.CursorRow, e.CursorColumn) e.selectRow, e.selectColumn = e.truncatePosition(e.selectRow, e.selectColumn) } @@ -1512,7 +1427,6 @@ func (e *Entry) truncatePosition(row, col int) (int, int) { func (e *Entry) updateMousePointer(p fyne.Position, rightClick bool) { row, col := e.getRowCol(p) - e.propertyLock.Lock() if !rightClick || !e.selecting { e.CursorRow = row @@ -1523,7 +1437,6 @@ func (e *Entry) updateMousePointer(p fyne.Position, rightClick bool) { e.selectRow = row e.selectColumn = col } - e.propertyLock.Unlock() r := cache.Renderer(e.content) if r != nil { @@ -1558,13 +1471,11 @@ func (e *Entry) updateText(text string, fromBinding bool) bool { func (e *Entry) updateTextAndRefresh(text string, fromBinding bool) { var callback func(string) - e.propertyLock.Lock() changed := e.updateText(text, fromBinding) if changed { callback = e.OnChanged } - e.propertyLock.Unlock() e.validate() if callback != nil { @@ -1590,11 +1501,9 @@ func (e *Entry) writeData(data binding.DataItem) { } func (e *Entry) typedKeyReturn(provider *RichText, multiLine bool) { - e.propertyLock.RLock() onSubmitted := e.OnSubmitted selectDown := e.selectKeyDown text := e.Text - e.propertyLock.RUnlock() if !multiLine { // Single line doesn't support newline. @@ -1608,7 +1517,6 @@ func (e *Entry) typedKeyReturn(provider *RichText, multiLine bool) { onSubmitted(text) return } - e.propertyLock.Lock() s := []rune("\n") pos := e.cursorTextPos() provider.insertAt(pos, s) @@ -1618,14 +1526,12 @@ func (e *Entry) typedKeyReturn(provider *RichText, multiLine bool) { }) e.CursorColumn = 0 e.CursorRow++ - e.propertyLock.Unlock() } // Selects the row where the CursorColumn is currently positioned // Do not call while holding the proeprtyLock func (e *Entry) selectCurrentRow() { provider := e.textProvider() - e.propertyLock.Lock() e.selectRow = e.CursorRow e.selectColumn = 0 if e.MultiLine { @@ -1633,14 +1539,11 @@ func (e *Entry) selectCurrentRow() { } else { e.CursorColumn = provider.len() } - e.propertyLock.Unlock() e.Refresh() } func (e *Entry) setFieldsAndRefresh(f func()) { - e.propertyLock.Lock() f() - e.propertyLock.Unlock() impl := e.super() if impl == nil { @@ -1723,10 +1626,8 @@ func (r *entryRenderer) Layout(size fyne.Size) { entrySize := size.Subtract(fyne.NewSize(r.trailingInset(), inputBorder*2)) entryPos := fyne.NewPos(0, inputBorder) - r.entry.propertyLock.Lock() textPos := r.entry.textPosFromRowCol(r.entry.CursorRow, r.entry.CursorColumn) selectPos := r.entry.textPosFromRowCol(r.entry.selectRow, r.entry.selectColumn) - r.entry.propertyLock.Unlock() if r.entry.Wrapping == fyne.TextWrapOff && r.entry.Scroll == widget.ScrollNone { r.entry.content.Resize(entrySize) r.entry.content.Move(entryPos) @@ -1735,9 +1636,7 @@ func (r *entryRenderer) Layout(size fyne.Size) { r.scroll.Move(entryPos) } - r.entry.propertyLock.Lock() resizedTextPos := r.entry.textPosFromRowCol(r.entry.CursorRow, r.entry.CursorColumn) - r.entry.propertyLock.Unlock() if textPos != resizedTextPos { r.entry.setFieldsAndRefresh(func() { r.entry.CursorRow, r.entry.CursorColumn = r.entry.rowColFromTextPos(textPos) @@ -1792,19 +1691,14 @@ func (r *entryRenderer) MinSize() fyne.Size { } func (r *entryRenderer) Objects() []fyne.CanvasObject { - r.entry.propertyLock.RLock() - defer r.entry.propertyLock.RUnlock() - return r.objects } func (r *entryRenderer) Refresh() { - r.entry.propertyLock.RLock() content := r.entry.content focusedAppearance := r.entry.focused && !r.entry.disabled.Load() scroll := r.entry.Scroll wrapping := r.entry.Wrapping - r.entry.propertyLock.RUnlock() r.entry.syncSegments() r.entry.text.updateRowBounds() @@ -1899,8 +1793,6 @@ type entryContent struct { func (e *entryContent) CreateRenderer() fyne.WidgetRenderer { e.ExtendBaseWidget(e) - e.entry.propertyLock.Lock() - defer e.entry.propertyLock.Unlock() provider := e.entry.textProvider() placeholder := e.entry.placeholderProvider() if provider.len() != 0 { @@ -1965,8 +1857,6 @@ func (r *entryContentRenderer) MinSize() fyne.Size { } func (r *entryContentRenderer) Objects() []fyne.CanvasObject { - r.content.entry.propertyLock.RLock() - defer r.content.entry.propertyLock.RUnlock() // Objects are generated dynamically force selection rectangles to appear underneath the text if r.content.entry.selecting { objs := make([]fyne.CanvasObject, 0, len(r.selection)+len(r.objects)) @@ -1977,14 +1867,12 @@ func (r *entryContentRenderer) Objects() []fyne.CanvasObject { } func (r *entryContentRenderer) Refresh() { - r.content.entry.propertyLock.RLock() provider := r.content.entry.textProvider() placeholder := r.content.entry.placeholderProvider() focused := r.content.entry.focused focusedAppearance := focused && !r.content.entry.disabled.Load() selections := r.selection r.updateScrollDirections() - r.content.entry.propertyLock.RUnlock() if provider.len() == 0 { placeholder.Show() @@ -2029,14 +1917,12 @@ func (r *entryContentRenderer) buildSelection() { v := fyne.CurrentApp().Settings().ThemeVariant() textSize := th.Size(theme.SizeNameText) - r.content.entry.propertyLock.RLock() cursorRow, cursorCol := r.content.entry.CursorRow, r.content.entry.CursorColumn selectRow, selectCol := -1, -1 if r.content.entry.selecting { selectRow = r.content.entry.selectRow selectCol = r.content.entry.selectColumn } - r.content.entry.propertyLock.RUnlock() if selectRow == -1 || (cursorRow == selectRow && cursorCol == selectCol) { r.selection = r.selection[:0] @@ -2078,8 +1964,6 @@ func (r *entryContentRenderer) buildSelection() { r.selection = r.selection[:rowCount] } - r.content.entry.propertyLock.Lock() - defer r.content.entry.propertyLock.Unlock() // build a rectangle for each row and add it to r.selection for i := 0; i < rowCount; i++ { if len(r.selection) <= i { @@ -2151,22 +2035,18 @@ func (r *entryContentRenderer) moveCursor() { th := r.content.entry.Theme() textSize := th.Size(theme.SizeNameText) - r.content.entry.propertyLock.RLock() provider := r.content.entry.textProvider() innerPad := th.Size(theme.SizeNameInnerPadding) inputBorder := th.Size(theme.SizeNameInputBorder) size := provider.lineSizeToColumn(r.content.entry.CursorColumn, r.content.entry.CursorRow, textSize, innerPad) xPos := size.Width yPos := size.Height * float32(r.content.entry.CursorRow) - r.content.entry.propertyLock.RUnlock() - r.content.entry.propertyLock.Lock() lineHeight := r.content.entry.text.charMinSize(r.content.entry.Password, r.content.entry.TextStyle, textSize).Height r.cursor.Resize(fyne.NewSize(inputBorder, lineHeight)) r.cursor.Move(fyne.NewPos(xPos-(inputBorder/2), yPos+innerPad-inputBorder)) callback := r.content.entry.OnCursorChanged - r.content.entry.propertyLock.Unlock() r.ensureCursorVisible() if callback != nil { diff --git a/widget/entry_password.go b/widget/entry_password.go index 40573a0eef..de98912744 100644 --- a/widget/entry_password.go +++ b/widget/entry_password.go @@ -72,8 +72,6 @@ func (r *passwordRevealerRenderer) MinSize() fyne.Size { func (r *passwordRevealerRenderer) Refresh() { th := r.entry.Theme() - r.entry.propertyLock.RLock() - defer r.entry.propertyLock.RUnlock() if !r.entry.Password { r.icon.Resource = th.Icon(theme.IconNameVisibility) } else { diff --git a/widget/entry_validation.go b/widget/entry_validation.go index fb6eb2c477..5095cd25cd 100644 --- a/widget/entry_validation.go +++ b/widget/entry_validation.go @@ -116,8 +116,6 @@ func (r *validationStatusRenderer) MinSize() fyne.Size { func (r *validationStatusRenderer) Refresh() { th := r.entry.Theme() - r.entry.propertyLock.RLock() - defer r.entry.propertyLock.RUnlock() if r.entry.disabled.Load() { r.icon.Hide() return diff --git a/widget/fileicon.go b/widget/fileicon.go index b2249ca6f5..9cde75d9a6 100644 --- a/widget/fileicon.go +++ b/widget/fileicon.go @@ -67,12 +67,7 @@ func (i *FileIcon) CreateRenderer() fyne.WidgetRenderer { v := fyne.CurrentApp().Settings().ThemeVariant() i.ExtendBaseWidget(i) - i.propertyLock.Lock() i.setURI(i.URI) - i.propertyLock.Unlock() - - i.propertyLock.RLock() - defer i.propertyLock.RUnlock() // TODO remove background when `SetSelected` is gone. background := canvas.NewRectangle(th.Color(theme.ColorNameSelection, v)) @@ -180,9 +175,7 @@ func (s *fileIconRenderer) Refresh() { th := s.file.Theme() v := fyne.CurrentApp().Settings().ThemeVariant() - s.file.propertyLock.Lock() s.file.setURI(s.file.URI) - s.file.propertyLock.Unlock() if s.file.Selected { s.background.Show() @@ -198,7 +191,6 @@ func (s *fileIconRenderer) Refresh() { } } - s.file.propertyLock.RLock() if s.img.Resource != s.file.resource { s.img.Resource = s.file.resource s.img.Refresh() @@ -207,7 +199,6 @@ func (s *fileIconRenderer) Refresh() { s.ext.Text = s.file.extension s.ext.Refresh() } - s.file.propertyLock.RUnlock() canvas.Refresh(s.file.super()) } diff --git a/widget/hyperlink.go b/widget/hyperlink.go index ae1cb7bac6..9d5a3e031f 100644 --- a/widget/hyperlink.go +++ b/widget/hyperlink.go @@ -186,9 +186,7 @@ func (hl *Hyperlink) Resize(size fyne.Size) { // SetText sets the text of the hyperlink func (hl *Hyperlink) SetText(text string) { - hl.propertyLock.Lock() hl.Text = text - hl.propertyLock.Unlock() if len(hl.provider.Segments) == 0 { return // Not initialized yet. @@ -199,9 +197,6 @@ func (hl *Hyperlink) SetText(text string) { // SetURL sets the URL of the hyperlink, taking in a URL type func (hl *Hyperlink) SetURL(url *url.URL) { - hl.propertyLock.Lock() - defer hl.propertyLock.Unlock() - hl.URL = url } @@ -224,9 +219,7 @@ func (hl *Hyperlink) Tapped(e *fyne.PointEvent) { } func (hl *Hyperlink) invokeAction() { - hl.propertyLock.RLock() onTapped := hl.OnTapped - hl.propertyLock.RUnlock() if onTapped != nil { onTapped() @@ -247,9 +240,7 @@ func (hl *Hyperlink) TypedKey(ev *fyne.KeyEvent) { } func (hl *Hyperlink) openURL() { - hl.propertyLock.RLock() url := hl.URL - hl.propertyLock.RUnlock() if url != nil { err := fyne.CurrentApp().OpenURL(url) @@ -262,9 +253,6 @@ func (hl *Hyperlink) openURL() { func (hl *Hyperlink) syncSegments() { th := hl.Theme() - hl.propertyLock.RLock() - defer hl.propertyLock.RUnlock() - hl.provider.Wrapping = hl.Wrapping hl.provider.Truncation = hl.Truncation @@ -311,12 +299,10 @@ func (r *hyperlinkRenderer) Destroy() { func (r *hyperlinkRenderer) Layout(s fyne.Size) { th := r.hl.Theme() - r.hl.propertyLock.RLock() textSize := r.hl.textSize innerPad := th.Size(theme.SizeNameInnerPadding) w := r.hl.focusWidth() xposFocus := r.hl.focusXPos() - r.hl.propertyLock.RUnlock() xposUnderline := xposFocus + innerPad/2 lineCount := float32(len(r.hl.provider.rowBounds)) @@ -341,9 +327,6 @@ func (r *hyperlinkRenderer) Refresh() { th := r.hl.Theme() v := fyne.CurrentApp().Settings().ThemeVariant() - r.hl.propertyLock.RLock() - defer r.hl.propertyLock.RUnlock() - r.focus.StrokeColor = th.Color(theme.ColorNameFocus, v) r.focus.Hidden = !r.hl.focused r.focus.Refresh() diff --git a/widget/icon.go b/widget/icon.go index bd30e413ab..7ab35f18e8 100644 --- a/widget/icon.go +++ b/widget/icon.go @@ -31,14 +31,12 @@ func (i *iconRenderer) Refresh() { return } - i.image.propertyLock.RLock() i.raster.Resource = i.image.Resource i.image.cachedRes = i.image.Resource if i.image.Resource == nil { i.raster.Image = nil // reset the internal caching too... } - i.image.propertyLock.RUnlock() i.raster.Refresh() } @@ -66,8 +64,6 @@ func (i *Icon) MinSize() fyne.Size { // CreateRenderer is a private method to Fyne which links this widget to its renderer func (i *Icon) CreateRenderer() fyne.WidgetRenderer { i.ExtendBaseWidget(i) - i.propertyLock.RLock() - defer i.propertyLock.RUnlock() img := canvas.NewImageFromResource(i.Resource) img.FillMode = canvas.ImageFillContain diff --git a/widget/label.go b/widget/label.go index a587137d36..b0c34a0e17 100644 --- a/widget/label.go +++ b/widget/label.go @@ -105,9 +105,7 @@ func (l *Label) Resize(s fyne.Size) { // SetText sets the text of the label func (l *Label) SetText(text string) { - l.propertyLock.Lock() l.Text = text - l.propertyLock.Unlock() l.Refresh() } @@ -120,9 +118,6 @@ func (l *Label) Unbind() { } func (l *Label) syncSegments() { - l.propertyLock.RLock() - defer l.propertyLock.RUnlock() - var color fyne.ThemeColorName switch l.Importance { case LowImportance: diff --git a/widget/list.go b/widget/list.go index f51d6e3c65..872e8b4022 100644 --- a/widget/list.go +++ b/widget/list.go @@ -146,15 +146,12 @@ func (l *List) RefreshItem(id ListItemID) { // // Since: 2.3 func (l *List) SetItemHeight(id ListItemID, height float32) { - l.propertyLock.Lock() - if l.itemHeights == nil { l.itemHeights = make(map[ListItemID]float32) } refresh := l.itemHeights[id] != height l.itemHeights[id] = height - l.propertyLock.Unlock() if refresh { l.RefreshItem(id) @@ -361,8 +358,6 @@ func (l *List) UnselectAll() { func (l *List) contentMinSize() fyne.Size { separatorThickness := l.Theme().Size(theme.SizeNamePadding) - l.propertyLock.Lock() - defer l.propertyLock.Unlock() if l.Length == nil { return fyne.NewSize(0, 0) } @@ -709,9 +704,7 @@ func (l *listLayout) updateList(newOnly bool) { wasVisible := (*wasVisiblePtr)[:0] wasVisible = append(wasVisible, l.visible...) - l.list.propertyLock.Lock() offY, minRow := l.calculateVisibleRowHeights(l.list.itemMin.Height, length, th) - l.list.propertyLock.Unlock() if len(l.visibleRowHeights) == 0 && length > 0 { // we can't show anything until we have some dimensions l.renderLock.Unlock() // user code should not be locked return diff --git a/widget/progressbarinfinite.go b/widget/progressbarinfinite.go index c7d161a634..da2a3b565a 100644 --- a/widget/progressbarinfinite.go +++ b/widget/progressbarinfinite.go @@ -90,9 +90,6 @@ func (p *infProgressRenderer) Refresh() { // Start the infinite progress bar background thread to update it continuously func (p *infProgressRenderer) start() { - p.progress.propertyLock.Lock() - defer p.progress.propertyLock.Unlock() - p.animation.Duration = time.Second * 3 p.animation.Tick = p.updateBar p.animation.Curve = fyne.AnimationLinear @@ -104,17 +101,12 @@ func (p *infProgressRenderer) start() { // Stop the background thread from updating the infinite progress bar func (p *infProgressRenderer) stop() { - p.progress.propertyLock.Lock() - defer p.progress.propertyLock.Unlock() - p.wasRunning = false p.animation.Stop() } func (p *infProgressRenderer) Destroy() { - p.progress.propertyLock.Lock() p.progress.running = false - p.progress.propertyLock.Unlock() p.stop() } @@ -128,54 +120,40 @@ type ProgressBarInfinite struct { // Show this widget, if it was previously hidden func (p *ProgressBarInfinite) Show() { - p.propertyLock.Lock() p.running = true - p.propertyLock.Unlock() p.BaseWidget.Show() } // Hide this widget, if it was previously visible func (p *ProgressBarInfinite) Hide() { - p.propertyLock.Lock() p.running = false - p.propertyLock.Unlock() p.BaseWidget.Hide() } // Start the infinite progress bar animation func (p *ProgressBarInfinite) Start() { - p.propertyLock.Lock() if p.running { - p.propertyLock.Unlock() return } p.running = true - p.propertyLock.Unlock() - p.BaseWidget.Refresh() } // Stop the infinite progress bar animation func (p *ProgressBarInfinite) Stop() { - p.propertyLock.Lock() if !p.running { - p.propertyLock.Unlock() return } p.running = false - p.propertyLock.Unlock() - p.BaseWidget.Refresh() } // Running returns the current state of the infinite progress animation func (p *ProgressBarInfinite) Running() bool { - p.propertyLock.RLock() - defer p.propertyLock.RUnlock() return p.running } @@ -208,10 +186,7 @@ func (p *ProgressBarInfinite) CreateRenderer() fyne.WidgetRenderer { render.SetObjects([]fyne.CanvasObject{&render.background, &render.bar}) - p.propertyLock.Lock() p.running = true - p.propertyLock.Unlock() - return render } diff --git a/widget/richtext.go b/widget/richtext.go index 8faea43846..4d44203215 100644 --- a/widget/richtext.go +++ b/widget/richtext.go @@ -124,13 +124,10 @@ func (t *RichText) Resize(size fyne.Size) { t.size.Store(size) - t.propertyLock.RLock() - segments := t.Segments skipResize := !t.minCache.IsZero() && size.Width >= t.minCache.Width && size.Height >= t.minCache.Height && t.Wrapping == fyne.TextWrapOff && t.Truncation == fyne.TextTruncateOff - t.propertyLock.RUnlock() if skipResize { - if len(segments) < 2 { // we can simplify :) + if len(t.Segments) < 2 { // we can simplify :) cache.Renderer(t).Layout(size) return } @@ -369,8 +366,6 @@ func (t *RichText) row(row int) []rune { // RowBoundary returns the boundary of the row specified. // The row parameter should be between 0 and t.Rows()-1. func (t *RichText) rowBoundary(row int) *rowBoundary { - t.propertyLock.RLock() - defer t.propertyLock.RUnlock() if row < 0 || row >= t.rows() { return nil } @@ -400,7 +395,6 @@ func (t *RichText) updateRowBounds() { } fitSize.Height -= (innerPadding + t.inset.Height) * 2 - t.propertyLock.RLock() var bounds []rowBoundary maxWidth := t.size.Load().Width - 2*innerPadding + 2*t.inset.Width wrapWidth := maxWidth @@ -493,11 +487,7 @@ func (t *RichText) updateRowBounds() { } iterateSegments(t.Segments) - t.propertyLock.RUnlock() - - t.propertyLock.Lock() t.rowBounds = bounds - t.propertyLock.Unlock() } // RichTextBlock is an extension of a text segment that contains other segments @@ -515,14 +505,12 @@ type textRenderer struct { func (r *textRenderer) Layout(size fyne.Size) { th := r.obj.Theme() - r.obj.propertyLock.RLock() bounds := r.obj.rowBounds objs := r.Objects() if r.obj.scr != nil { r.obj.scr.Resize(size) objs = r.obj.scr.Content.(*fyne.Container).Objects[1].(*fyne.Container).Objects } - r.obj.propertyLock.RUnlock() // Accessing theme here is slow, so we cache the value innerPadding := th.Size(theme.SizeNameInnerPadding) @@ -589,7 +577,6 @@ func (r *textRenderer) Layout(size fyne.Size) { func (r *textRenderer) MinSize() fyne.Size { th := r.obj.Theme() textSize := th.Size(theme.SizeNameText) - r.obj.propertyLock.RLock() innerPad := th.Size(theme.SizeNameInnerPadding) bounds := r.obj.rowBounds @@ -600,7 +587,6 @@ func (r *textRenderer) MinSize() fyne.Size { if r.obj.scr != nil { objs = r.obj.scr.Content.(*fyne.Container).Objects[1].(*fyne.Container).Objects } - r.obj.propertyLock.RUnlock() charMinSize := r.obj.charMinSize(false, fyne.TextStyle{}, textSize) min := r.calculateMin(bounds, wrap, objs, charMinSize, th) @@ -693,10 +679,8 @@ func (r *textRenderer) calculateMin(bounds []rowBoundary, wrap fyne.TextWrap, ob } func (r *textRenderer) Refresh() { - r.obj.propertyLock.RLock() bounds := r.obj.rowBounds scroll := r.obj.Scroll - r.obj.propertyLock.RUnlock() var objs []fyne.CanvasObject for _, bound := range bounds { @@ -739,7 +723,6 @@ func (r *textRenderer) Refresh() { } } - r.obj.propertyLock.Lock() if r.obj.scr != nil { r.obj.scr.Content = &fyne.Container{Layout: layout.NewStackLayout(), Objects: []fyne.CanvasObject{ r.obj.prop, &fyne.Container{Objects: objs}}} @@ -749,7 +732,6 @@ func (r *textRenderer) Refresh() { } else { r.SetObjects(objs) } - r.obj.propertyLock.Unlock() r.Layout(r.obj.Size()) canvas.Refresh(r.obj.super()) diff --git a/widget/select.go b/widget/select.go index 3e776c05d3..b5f04473d4 100644 --- a/widget/select.go +++ b/widget/select.go @@ -88,7 +88,6 @@ func (s *Select) CreateRenderer() fyne.WidgetRenderer { th := s.Theme() v := fyne.CurrentApp().Settings().ThemeVariant() - s.propertyLock.RLock() icon := NewIcon(th.Icon(theme.IconNameArrowDropDown)) if s.PlaceHolder == "" { s.PlaceHolder = defaultPlaceHolder @@ -110,7 +109,6 @@ func (s *Select) CreateRenderer() fyne.WidgetRenderer { background.FillColor = r.bgColor(th, v) background.CornerRadius = th.Size(theme.SizeNameInputRadius) r.updateIcon(th) - s.propertyLock.RUnlock() // updateLabel and some text handling isn't quite right, resolve in text refactor for 2.0 r.updateLabel() return r } @@ -403,9 +401,6 @@ func (s *selectRenderer) MinSize() fyne.Size { th := s.combo.Theme() innerPad := th.Size(theme.SizeNameInnerPadding) - s.combo.propertyLock.RLock() - defer s.combo.propertyLock.RUnlock() - minPlaceholderWidth := fyne.MeasureText(s.combo.PlaceHolder, th.Size(theme.SizeNameText), fyne.TextStyle{}).Width min := s.label.MinSize() min.Width = minPlaceholderWidth @@ -417,12 +412,10 @@ func (s *selectRenderer) Refresh() { th := s.combo.Theme() v := fyne.CurrentApp().Settings().ThemeVariant() - s.combo.propertyLock.RLock() s.updateLabel() s.updateIcon(th) s.background.FillColor = s.bgColor(th, v) s.background.CornerRadius = s.combo.themeWithLock().Size(theme.SizeNameInputRadius) - s.combo.propertyLock.RUnlock() s.Layout(s.combo.Size()) if s.combo.popUp != nil { diff --git a/widget/table.go b/widget/table.go index 1eba170fcf..18c6af40ad 100644 --- a/widget/table.go +++ b/widget/table.go @@ -137,7 +137,6 @@ func NewTableWithHeaders(length func() (rows int, cols int), create func() fyne. func (t *Table) CreateRenderer() fyne.WidgetRenderer { t.ExtendBaseWidget(t) - t.propertyLock.Lock() t.headerSize = t.createHeader().MinSize() if t.columnWidths != nil { if v, ok := t.columnWidths[-1]; ok { @@ -156,7 +155,6 @@ func (t *Table) CreateRenderer() fyne.WidgetRenderer { t.left = newClip(t, &fyne.Container{}) t.corner = newClip(t, &fyne.Container{}) t.dividerLayer = newClip(t, &fyne.Container{}) - t.propertyLock.Unlock() t.dragCol = noCellMatch t.dragRow = noCellMatch @@ -182,13 +180,11 @@ func (t *Table) Cursor() desktop.Cursor { } func (t *Table) Dragged(e *fyne.DragEvent) { - t.propertyLock.Lock() min := t.cellSize col := t.dragCol row := t.dragRow startPos := t.dragStartPos startSize := t.dragStartSize - t.propertyLock.Unlock() if col != noCellMatch { newSize := startSize + (e.Position.X - startPos.X) @@ -296,10 +292,8 @@ func (t *Table) Select(id TableCellID) { // // Since: 1.4.1 func (t *Table) SetColumnWidth(id int, width float32) { - t.propertyLock.Lock() if id < 0 { if t.headerSize.Width == width { - t.propertyLock.Unlock() return } t.headerSize.Width = width @@ -310,12 +304,9 @@ func (t *Table) SetColumnWidth(id int, width float32) { } if set, ok := t.columnWidths[id]; ok && set == width { - t.propertyLock.Unlock() return } t.columnWidths[id] = width - t.propertyLock.Unlock() - t.Refresh() } @@ -325,10 +316,8 @@ func (t *Table) SetColumnWidth(id int, width float32) { // // Since: 2.3 func (t *Table) SetRowHeight(id int, height float32) { - t.propertyLock.Lock() if id < 0 { if t.headerSize.Height == height { - t.propertyLock.Unlock() return } t.headerSize.Height = height @@ -339,12 +328,9 @@ func (t *Table) SetRowHeight(id int, height float32) { } if set, ok := t.rowHeights[id]; ok && set == height { - t.propertyLock.Unlock() return } t.rowHeights[id] = height - t.propertyLock.Unlock() - t.Refresh() } @@ -1042,7 +1028,6 @@ type tableRenderer struct { func (t *tableRenderer) Layout(s fyne.Size) { th := t.t.Theme() - t.t.propertyLock.RLock() t.calculateHeaderSizes(th) off := fyne.NewPos(t.t.stuckWidth, t.t.stuckHeight) @@ -1052,7 +1037,6 @@ func (t *tableRenderer) Layout(s fyne.Size) { if t.t.ShowHeaderColumn { off.X += t.t.headerSize.Width } - t.t.propertyLock.RUnlock() t.t.content.Move(off) t.t.content.Resize(s.SubtractWidthHeight(off.X, off.Y)) @@ -1073,9 +1057,6 @@ func (t *tableRenderer) Layout(s fyne.Size) { func (t *tableRenderer) MinSize() fyne.Size { sep := t.t.Theme().Size(theme.SizeNamePadding) - t.t.propertyLock.RLock() - defer t.t.propertyLock.RUnlock() - min := t.t.content.MinSize().Max(t.t.cellSize) if t.t.ShowHeaderRow { min.Height += t.t.headerSize.Height + sep @@ -1108,7 +1089,6 @@ func (t *tableRenderer) MinSize() fyne.Size { func (t *tableRenderer) Refresh() { th := t.t.Theme() - t.t.propertyLock.Lock() t.t.headerSize = t.t.createHeader().MinSize() if t.t.columnWidths != nil { if v, ok := t.t.columnWidths[-1]; ok { @@ -1122,7 +1102,6 @@ func (t *tableRenderer) Refresh() { } t.t.cellSize = t.t.templateSize() t.calculateHeaderSizes(th) - t.t.propertyLock.Unlock() t.Layout(t.t.Size()) t.t.cells.Refresh() @@ -1208,14 +1187,10 @@ type tableCellsRenderer struct { } func (r *tableCellsRenderer) Layout(fyne.Size) { - r.cells.propertyLock.Lock() r.moveIndicators() - r.cells.propertyLock.Unlock() } func (r *tableCellsRenderer) MinSize() fyne.Size { - r.cells.propertyLock.RLock() - defer r.cells.propertyLock.RUnlock() rows, cols := 0, 0 if f := r.cells.t.Length; f != nil { rows, cols = r.cells.t.Length() @@ -1268,7 +1243,6 @@ func (r *tableCellsRenderer) refreshForID(toDraw TableCellID) { th := r.cells.t.Theme() v := fyne.CurrentApp().Settings().ThemeVariant() - r.cells.propertyLock.Lock() separatorThickness := th.Size(theme.SizeNamePadding) dataRows, dataCols := 0, 0 if f := r.cells.t.Length; f != nil { @@ -1276,12 +1250,10 @@ func (r *tableCellsRenderer) refreshForID(toDraw TableCellID) { } visibleColWidths, offX, minCol, maxCol := r.cells.t.visibleColumnWidths(r.cells.t.cellSize.Width, dataCols) if len(visibleColWidths) == 0 && dataCols > 0 { // we can't show anything until we have some dimensions - r.cells.propertyLock.Unlock() return } visibleRowHeights, offY, minRow, maxRow := r.cells.t.visibleRowHeights(r.cells.t.cellSize.Height, dataRows) if len(visibleRowHeights) == 0 && dataRows > 0 { // we can't show anything until we have some dimensions - r.cells.propertyLock.Unlock() return } @@ -1392,7 +1364,6 @@ func (r *tableCellsRenderer) refreshForID(toDraw TableCellID) { visible := r.visible headers := r.headers - r.cells.propertyLock.Unlock() r.SetObjects(cells) if updateCell != nil { diff --git a/widget/tree.go b/widget/tree.go index 34fa3ebcb6..de48c91339 100644 --- a/widget/tree.go +++ b/widget/tree.go @@ -119,18 +119,14 @@ func NewTreeWithStrings(data map[string][]string) (t *Tree) { // CloseAllBranches closes all branches in the tree. func (t *Tree) CloseAllBranches() { - t.propertyLock.Lock() t.open = make(map[TreeNodeID]bool) - t.propertyLock.Unlock() t.Refresh() } // CloseBranch closes the branch with the given TreeNodeID. func (t *Tree) CloseBranch(uid TreeNodeID) { t.ensureOpenMap() - t.propertyLock.Lock() t.open[uid] = false - t.propertyLock.Unlock() if f := t.OnBranchClosed; f != nil { f(uid) } @@ -161,8 +157,6 @@ func (t *Tree) IsBranchOpen(uid TreeNodeID) bool { return true // Root is always open } t.ensureOpenMap() - t.propertyLock.RLock() - defer t.propertyLock.RUnlock() return t.open[uid] } @@ -217,9 +211,7 @@ func (t *Tree) OpenAllBranches() { t.ensureOpenMap() t.walkAll(func(uid, parent TreeNodeID, branch bool, depth int) { if branch { - t.propertyLock.Lock() t.open[uid] = true - t.propertyLock.Unlock() } }) t.Refresh() @@ -228,9 +220,7 @@ func (t *Tree) OpenAllBranches() { // OpenBranch opens the branch with the given TreeNodeID. func (t *Tree) OpenBranch(uid TreeNodeID) { t.ensureOpenMap() - t.propertyLock.Lock() t.open[uid] = true - t.propertyLock.Unlock() if f := t.OnBranchOpened; f != nil { f(uid) } @@ -433,8 +423,6 @@ func (t *Tree) UnselectAll() { } func (t *Tree) ensureOpenMap() { - t.propertyLock.Lock() - defer t.propertyLock.Unlock() if t.open == nil { t.open = make(map[string]bool) } @@ -620,9 +608,6 @@ type treeContentRenderer struct { func (r *treeContentRenderer) Layout(size fyne.Size) { th := r.treeContent.Theme() - r.treeContent.propertyLock.Lock() - defer r.treeContent.propertyLock.Unlock() - r.objects = nil branches := make(map[string]*branch) leaves := make(map[string]*leaf) @@ -742,8 +727,6 @@ func (r *treeContentRenderer) Layout(size fyne.Size) { func (r *treeContentRenderer) MinSize() (min fyne.Size) { th := r.treeContent.Theme() - r.treeContent.propertyLock.Lock() - defer r.treeContent.propertyLock.Unlock() pad := th.Size(theme.SizeNamePadding) iconSize := th.Size(theme.SizeNameInlineIcon) @@ -788,7 +771,6 @@ func (r *treeContentRenderer) refreshForID(toDraw TreeNodeID) { } else { r.Layout(s) } - r.treeContent.propertyLock.RLock() for id, b := range r.branches { if toDraw != allTreeNodesID && id != toDraw { continue @@ -803,7 +785,6 @@ func (r *treeContentRenderer) refreshForID(toDraw TreeNodeID) { l.Refresh() } - r.treeContent.propertyLock.RUnlock() canvas.Refresh(r.treeContent.super()) } @@ -914,9 +895,7 @@ func (n *treeNode) partialRefresh() { func (n *treeNode) update(uid string, depth int) { n.uid = uid n.depth = depth - n.propertyLock.Lock() n.Hidden = false - n.propertyLock.Unlock() n.partialRefresh() } diff --git a/widget/widget.go b/widget/widget.go index 63b8555633..b899406e78 100644 --- a/widget/widget.go +++ b/widget/widget.go @@ -2,7 +2,6 @@ package widget // import "fyne.io/fyne/v2/widget" import ( - "sync" "sync/atomic" "fyne.io/fyne/v2" @@ -19,9 +18,8 @@ type BaseWidget struct { position async.Position Hidden bool - impl atomic.Pointer[fyne.Widget] - propertyLock sync.RWMutex - themeCache fyne.Theme + impl atomic.Pointer[fyne.Widget] + themeCache fyne.Theme } // ExtendBaseWidget is used by an extending widget to make use of BaseWidget functionality. @@ -82,9 +80,6 @@ func (w *BaseWidget) MinSize() fyne.Size { // Visible returns whether or not this widget should be visible. // Note that this may not mean it is currently visible if a parent has been hidden. func (w *BaseWidget) Visible() bool { - w.propertyLock.RLock() - defer w.propertyLock.RUnlock() - return !w.Hidden } @@ -94,9 +89,7 @@ func (w *BaseWidget) Show() { return } - w.propertyLock.Lock() w.Hidden = false - w.propertyLock.Unlock() impl := w.super() if impl == nil { @@ -111,9 +104,7 @@ func (w *BaseWidget) Hide() { return } - w.propertyLock.Lock() w.Hidden = true - w.propertyLock.Unlock() impl := w.super() if impl == nil { @@ -129,9 +120,7 @@ func (w *BaseWidget) Refresh() { return } - w.propertyLock.Lock() w.themeCache = nil - w.propertyLock.Unlock() render := cache.Renderer(impl) render.Refresh() @@ -142,8 +131,6 @@ func (w *BaseWidget) Refresh() { // // Since: 2.5 func (w *BaseWidget) Theme() fyne.Theme { - w.propertyLock.RLock() - defer w.propertyLock.RUnlock() return w.themeWithLock() }