From 6da8faf19e08f62b7a1b190265eb41c9fc9bfc1c Mon Sep 17 00:00:00 2001 From: Jacob Date: Sat, 6 Jan 2024 20:13:52 +0100 Subject: [PATCH] Don't call public methods inside locks --- internal/widget/scroller.go | 15 ++++++++------- widget/button.go | 2 +- widget/check.go | 6 +++--- widget/check_group.go | 4 ++-- widget/entry.go | 14 +++++++------- widget/entry_password.go | 2 +- widget/entry_validation.go | 2 +- widget/progressbarinfinite.go | 2 +- widget/radio_group.go | 4 ++-- widget/richtext.go | 6 +++--- widget/select.go | 12 ++++++------ widget/slider.go | 2 +- widget/table.go | 16 +++++++++------- widget/tree.go | 4 ++-- 14 files changed, 47 insertions(+), 44 deletions(-) diff --git a/internal/widget/scroller.go b/internal/widget/scroller.go index 9daa021dd3..f5620272d3 100644 --- a/internal/widget/scroller.go +++ b/internal/widget/scroller.go @@ -251,20 +251,21 @@ type scrollContainerRenderer struct { } func (r *scrollContainerRenderer) layoutBars(size fyne.Size) { + scrollerSize := r.scroll.size.Load() if r.scroll.Direction == ScrollVerticalOnly || r.scroll.Direction == ScrollBoth { r.vertArea.Resize(fyne.NewSize(r.vertArea.MinSize().Width, size.Height)) - r.vertArea.Move(fyne.NewPos(r.scroll.Size().Width-r.vertArea.Size().Width, 0)) + r.vertArea.Move(fyne.NewPos(scrollerSize.Width-r.vertArea.Size().Width, 0)) r.topShadow.Resize(fyne.NewSize(size.Width, 0)) r.bottomShadow.Resize(fyne.NewSize(size.Width, 0)) - r.bottomShadow.Move(fyne.NewPos(0, r.scroll.Size().Height)) + r.bottomShadow.Move(fyne.NewPos(0, scrollerSize.Height)) } if r.scroll.Direction == ScrollHorizontalOnly || r.scroll.Direction == ScrollBoth { r.horizArea.Resize(fyne.NewSize(size.Width, r.horizArea.MinSize().Height)) - r.horizArea.Move(fyne.NewPos(0, r.scroll.Size().Height-r.horizArea.Size().Height)) + r.horizArea.Move(fyne.NewPos(0, scrollerSize.Height-r.horizArea.Size().Height)) r.leftShadow.Resize(fyne.NewSize(0, size.Height)) r.rightShadow.Resize(fyne.NewSize(0, size.Height)) - r.rightShadow.Move(fyne.NewPos(r.scroll.Size().Width, 0)) + r.rightShadow.Move(fyne.NewPos(scrollerSize.Width, 0)) } r.updatePosition() @@ -326,7 +327,7 @@ func (r *scrollContainerRenderer) updatePosition() { if r.scroll.Content == nil { return } - scrollSize := r.scroll.Size() + scrollSize := r.scroll.size.Load() contentSize := r.scroll.Content.Size() r.scroll.Content.Move(fyne.NewPos(-r.scroll.Offset.X, -r.scroll.Offset.Y)) @@ -334,7 +335,7 @@ func (r *scrollContainerRenderer) updatePosition() { if r.scroll.Direction == ScrollVerticalOnly || r.scroll.Direction == ScrollBoth { r.handleAreaVisibility(contentSize.Height, scrollSize.Height, r.vertArea) r.handleShadowVisibility(r.scroll.Offset.Y, contentSize.Height, scrollSize.Height, r.topShadow, r.bottomShadow) - cache.Renderer(r.vertArea).Layout(r.scroll.Size()) + cache.Renderer(r.vertArea).Layout(scrollSize) } else { r.vertArea.Hide() r.topShadow.Hide() @@ -343,7 +344,7 @@ func (r *scrollContainerRenderer) updatePosition() { if r.scroll.Direction == ScrollHorizontalOnly || r.scroll.Direction == ScrollBoth { r.handleAreaVisibility(contentSize.Width, scrollSize.Width, r.horizArea) r.handleShadowVisibility(r.scroll.Offset.X, contentSize.Width, scrollSize.Width, r.leftShadow, r.rightShadow) - cache.Renderer(r.horizArea).Layout(r.scroll.Size()) + cache.Renderer(r.horizArea).Layout(scrollSize) } else { r.horizArea.Hide() r.leftShadow.Hide() diff --git a/widget/button.go b/widget/button.go index 7d79fa8fac..f98f47f534 100644 --- a/widget/button.go +++ b/widget/button.go @@ -358,7 +358,7 @@ func (r *buttonRenderer) applyTheme() { r.button.applyButtonTheme() r.label.Segments[0].(*TextSegment).Style.ColorName = theme.ColorNameForeground switch { - case r.button.Disabled(): + case r.button.disabled.Load(): r.label.Segments[0].(*TextSegment).Style.ColorName = theme.ColorNameDisabled case r.button.Importance == HighImportance || r.button.Importance == DangerImportance || r.button.Importance == WarningImportance || r.button.Importance == SuccessImportance: if r.button.focused { diff --git a/widget/check.go b/widget/check.go index f22124ea43..120a32f961 100644 --- a/widget/check.go +++ b/widget/check.go @@ -55,7 +55,7 @@ func (c *checkRenderer) Layout(size fyne.Size) { func (c *checkRenderer) applyTheme() { c.label.Color = theme.ForegroundColor() c.label.TextSize = theme.TextSize() - if c.check.Disabled() { + if c.check.disabled.Load() { c.label.Color = theme.DisabledColor() } } @@ -86,7 +86,7 @@ func (c *checkRenderer) updateResource() { res.ColorName = theme.ColorNamePrimary bgRes.ColorName = theme.ColorNameBackground } - if c.check.Disabled() { + if c.check.disabled.Load() { if c.check.Checked { res = theme.NewThemedResource(theme.CheckButtonCheckedIcon()) } @@ -98,7 +98,7 @@ func (c *checkRenderer) updateResource() { } func (c *checkRenderer) updateFocusIndicator() { - if c.check.Disabled() { + if c.check.disabled.Load() { c.focusIndicator.FillColor = color.Transparent } else if c.check.focused { c.focusIndicator.FillColor = theme.FocusColor() diff --git a/widget/check_group.go b/widget/check_group.go index 2b559a3694..78869b1ca0 100644 --- a/widget/check_group.go +++ b/widget/check_group.go @@ -168,7 +168,7 @@ func (r *CheckGroup) update() { item.Text = r.Options[i] item.Checked = contains - item.DisableableWidget.disabled.Store(r.Disabled()) + item.DisableableWidget.disabled.Store(r.disabled.Load()) item.Refresh() } } @@ -261,7 +261,7 @@ func (r *checkGroupRenderer) updateItems() { } item.Text = r.checks.Options[i] item.Checked = contains - item.disabled.Store(r.checks.Disabled()) + item.disabled.Store(r.checks.disabled.Load()) item.Refresh() } } diff --git a/widget/entry.go b/widget/entry.go index d7b7987b37..53f7c7d8cd 100644 --- a/widget/entry.go +++ b/widget/entry.go @@ -226,7 +226,7 @@ func (e *Entry) Disable() { // // Implements: fyne.Disableable func (e *Entry) Disabled() bool { - return e.DisableableWidget.Disabled() + return e.DisableableWidget.disabled.Load() } // DoubleTapped is called when this entry has been double tapped so we should select text below the pointer @@ -1305,7 +1305,7 @@ func (e *Entry) textPosFromRowCol(row, col int) int { func (e *Entry) syncSegments() { colName := theme.ColorNameForeground wrap := e.textWrap() - disabled := e.Disabled() + disabled := e.disabled.Load() if disabled { colName = theme.ColorNameDisabled } @@ -1667,7 +1667,7 @@ func (r *entryRenderer) Objects() []fyne.CanvasObject { func (r *entryRenderer) Refresh() { r.entry.propertyLock.RLock() content := r.entry.content - focusedAppearance := r.entry.focused && !r.entry.Disabled() + focusedAppearance := r.entry.focused && !r.entry.disabled.Load() scroll := r.entry.Scroll wrapping := r.entry.Wrapping r.entry.propertyLock.RUnlock() @@ -1679,7 +1679,7 @@ func (r *entryRenderer) Refresh() { r.entry.placeholder.Refresh() // correct our scroll wrappers if the wrap mode changed - entrySize := r.entry.Size().Subtract(fyne.NewSize(r.trailingInset(), theme.InputBorderSize()*2)) + entrySize := r.entry.size.Load().Subtract(fyne.NewSize(r.trailingInset(), theme.InputBorderSize()*2)) if wrapping == fyne.TextWrapOff && scroll == widget.ScrollNone && r.scroll.Content != nil { r.scroll.Hide() r.scroll.Content = nil @@ -1742,7 +1742,7 @@ func (r *entryRenderer) ensureValidationSetup() { if r.entry.validationStatus == nil { r.entry.validationStatus = newValidationStatus(r.entry) r.objects = append(r.objects, r.entry.validationStatus) - r.Layout(r.entry.Size()) + r.Layout(r.entry.size.Load()) r.entry.Validate() @@ -1774,7 +1774,7 @@ func (e *entryContent) CreateRenderer() fyne.WidgetRenderer { r := &entryContentRenderer{e.entry.cursorAnim.cursor, []fyne.CanvasObject{}, objects, provider, placeholder, e} r.updateScrollDirections() - r.Layout(e.Size()) + r.Layout(e.size.Load()) return r } @@ -1842,7 +1842,7 @@ func (r *entryContentRenderer) Refresh() { r.content.entry.propertyLock.RLock() provider := r.content.entry.textProvider() placeholder := r.content.entry.placeholderProvider() - focusedAppearance := r.content.entry.focused && !r.content.entry.Disabled() + focusedAppearance := r.content.entry.focused && !r.content.entry.disabled.Load() selections := r.selection r.updateScrollDirections() r.content.entry.propertyLock.RUnlock() diff --git a/widget/entry_password.go b/widget/entry_password.go index 5e9bae09ba..a6cd1d014b 100644 --- a/widget/entry_password.go +++ b/widget/entry_password.go @@ -76,7 +76,7 @@ func (r *passwordRevealerRenderer) Refresh() { r.icon.Resource = theme.VisibilityOffIcon() } - if r.entry.Disabled() { + if r.entry.disabled.Load() { r.icon.Resource = theme.NewDisabledResource(r.icon.Resource) } canvas.Refresh(r.icon) diff --git a/widget/entry_validation.go b/widget/entry_validation.go index 8aa14e76c6..deb46592a6 100644 --- a/widget/entry_validation.go +++ b/widget/entry_validation.go @@ -93,7 +93,7 @@ func (r *validationStatusRenderer) MinSize() fyne.Size { func (r *validationStatusRenderer) Refresh() { r.entry.propertyLock.RLock() defer r.entry.propertyLock.RUnlock() - if r.entry.Disabled() { + if r.entry.disabled.Load() { r.icon.Hide() return } diff --git a/widget/progressbarinfinite.go b/widget/progressbarinfinite.go index 2d11989491..abf0357284 100644 --- a/widget/progressbarinfinite.go +++ b/widget/progressbarinfinite.go @@ -34,7 +34,7 @@ func (p *infProgressRenderer) MinSize() fyne.Size { } func (p *infProgressRenderer) updateBar(done float32) { - size := p.progress.Size() + size := p.progress.size.Load() progressWidth := size.Width spanWidth := progressWidth + (progressWidth * (maxProgressBarInfiniteWidthRatio / 2)) maxBarWidth := progressWidth * maxProgressBarInfiniteWidthRatio diff --git a/widget/radio_group.go b/widget/radio_group.go index 8b3a31e43a..fb778e6857 100644 --- a/widget/radio_group.go +++ b/widget/radio_group.go @@ -124,7 +124,7 @@ func (r *RadioGroup) update() { for i, item := range r.items { item.Label = r.Options[i] item.Selected = item.Label == r.Selected - item.DisableableWidget.disabled.Store(r.Disabled()) + item.DisableableWidget.disabled.Store(r.disabled.Load()) item.Refresh() } } @@ -207,7 +207,7 @@ func (r *radioGroupRenderer) updateItems() { for i, item := range r.items { item.Label = r.radio.Options[i] item.Selected = item.Label == r.radio.Selected - item.disabled.Store(r.radio.Disabled()) + item.disabled.Store(r.radio.disabled.Load()) item.Refresh() } } diff --git a/widget/richtext.go b/widget/richtext.go index f58dcaa9fe..df31b618e6 100644 --- a/widget/richtext.go +++ b/widget/richtext.go @@ -107,7 +107,7 @@ func (t *RichText) Refresh() { // // Implements: fyne.Widget func (t *RichText) Resize(size fyne.Size) { - if size == t.Size() { + if size == t.size.Load() { return } @@ -355,7 +355,7 @@ func (t *RichText) rows() int { // updateRowBounds should be invoked every time a segment Text, widget Wrapping or size changes. func (t *RichText) updateRowBounds() { innerPadding := theme.InnerPadding() - fitSize := t.Size() + fitSize := t.size.Load() if t.scr != nil { fitSize = t.scr.Content.MinSize() } @@ -363,7 +363,7 @@ func (t *RichText) updateRowBounds() { t.propertyLock.RLock() var bounds []rowBoundary - maxWidth := t.Size().Width - 2*innerPadding + 2*t.inset.Width + maxWidth := t.size.Load().Width - 2*innerPadding + 2*t.inset.Width wrapWidth := maxWidth var currentBound *rowBoundary diff --git a/widget/select.go b/widget/select.go index 19a68091fd..f38c139152 100644 --- a/widget/select.go +++ b/widget/select.go @@ -63,10 +63,10 @@ func (s *Select) CreateRenderer() fyne.WidgetRenderer { s.PlaceHolder = defaultPlaceHolder } txtProv := NewRichTextWithText(s.Selected) - txtProv.inset = fyne.NewSize(theme.Padding(), theme.Padding()) + txtProv.inset = fyne.NewSquareSize(theme.Padding()) txtProv.ExtendBaseWidget(txtProv) txtProv.Truncation = fyne.TextTruncateEllipsis - if s.Disabled() { + if s.disabled.Load() { txtProv.Segments[0].(*TextSegment).Style.ColorName = theme.ColorNameDisabled } @@ -334,7 +334,7 @@ func (s *selectRenderer) Refresh() { if s.combo.popUp != nil { s.combo.popUp.alignment = s.combo.Alignment s.combo.popUp.Move(s.combo.popUpPos()) - s.combo.popUp.Resize(fyne.NewSize(s.combo.Size().Width, s.combo.popUp.MinSize().Height)) + s.combo.popUp.Resize(fyne.NewSize(s.combo.size.Load().Width, s.combo.popUp.MinSize().Height)) s.combo.popUp.Refresh() } s.background.Refresh() @@ -342,7 +342,7 @@ func (s *selectRenderer) Refresh() { } func (s *selectRenderer) bgColor() color.Color { - if s.combo.Disabled() { + if s.combo.disabled.Load() { return theme.DisabledButtonColor() } if s.combo.focused { @@ -355,7 +355,7 @@ func (s *selectRenderer) bgColor() color.Color { } func (s *selectRenderer) updateIcon() { - if s.combo.Disabled() { + if s.combo.disabled.Load() { s.icon.Resource = theme.NewDisabledResource(theme.MenuDropDownIcon()) } else { s.icon.Resource = theme.MenuDropDownIcon() @@ -369,7 +369,7 @@ func (s *selectRenderer) updateLabel() { } s.label.Segments[0].(*TextSegment).Style.Alignment = s.combo.Alignment - if s.combo.Disabled() { + if s.combo.disabled.Load() { s.label.Segments[0].(*TextSegment).Style.ColorName = theme.ColorNameDisabled } else { s.label.Segments[0].(*TextSegment).Style.ColorName = theme.ColorNameForeground diff --git a/widget/slider.go b/widget/slider.go index c9f7a11d16..e2eb40076e 100644 --- a/widget/slider.go +++ b/widget/slider.go @@ -243,7 +243,7 @@ func (s *Slider) getRatio(e *fyne.PointEvent) float64 { x := e.Position.X y := e.Position.Y - size := s.Size() + size := s.size.Load() switch s.Orientation { case Vertical: diff --git a/widget/table.go b/widget/table.go index bcebcb2c2f..e8e847d606 100644 --- a/widget/table.go +++ b/widget/table.go @@ -854,7 +854,7 @@ func (t *Table) visibleColumnWidths(colWidth float32, cols int) (visible map[int // theme.Padding is a slow call, so we cache it padding := theme.Padding() stick := t.StickyColumnCount - size := t.Size() + size := t.size.Load() if len(t.columnWidths) == 0 { paddedWidth := colWidth + padding @@ -955,7 +955,7 @@ func (t *Table) visibleRowHeights(rowHeight float32, rows int) (visible map[int] // theme.Padding is a slow call, so we cache it padding := theme.Padding() stick := t.StickyRowCount - size := t.Size() + size := t.size.Load() if len(t.rowHeights) == 0 { paddedHeight := rowHeight + padding @@ -1443,6 +1443,8 @@ func (r *tableCellsRenderer) moveIndicators() { r.cells.t.dividerLayer.Content.Refresh() } + size := r.cells.t.size.Load() + divs := 0 i := 0 if stickCols > 0 { @@ -1450,7 +1452,7 @@ func (r *tableCellsRenderer) moveIndicators() { i++ xPos := x + dividerOff - r.dividers[divs].Resize(fyne.NewSize(separatorThickness, r.cells.t.Size().Height)) + r.dividers[divs].Resize(fyne.NewSize(separatorThickness, size.Height)) r.dividers[divs].Move(fyne.NewPos(xPos, 0)) r.dividers[divs].Show() divs++ @@ -1461,7 +1463,7 @@ func (r *tableCellsRenderer) moveIndicators() { i++ xPos := x - r.cells.t.content.Offset.X + dividerOff - r.dividers[divs].Resize(fyne.NewSize(separatorThickness, r.cells.t.Size().Height)) + r.dividers[divs].Resize(fyne.NewSize(separatorThickness, size.Height)) r.dividers[divs].Move(fyne.NewPos(xPos, 0)) r.dividers[divs].Show() divs++ @@ -1473,7 +1475,7 @@ func (r *tableCellsRenderer) moveIndicators() { i++ yPos := y + dividerOff - r.dividers[divs].Resize(fyne.NewSize(r.cells.t.Size().Width, separatorThickness)) + r.dividers[divs].Resize(fyne.NewSize(size.Width, separatorThickness)) r.dividers[divs].Move(fyne.NewPos(0, yPos)) r.dividers[divs].Show() divs++ @@ -1484,7 +1486,7 @@ func (r *tableCellsRenderer) moveIndicators() { i++ yPos := y - r.cells.t.content.Offset.Y + dividerOff - r.dividers[divs].Resize(fyne.NewSize(r.cells.t.Size().Width, separatorThickness)) + r.dividers[divs].Resize(fyne.NewSize(size.Width, separatorThickness)) r.dividers[divs].Move(fyne.NewPos(0, yPos)) r.dividers[divs].Show() divs++ @@ -1545,7 +1547,7 @@ func (r *tableCellsRenderer) moveMarker(marker fyne.CanvasObject, row, col int, } y2 := y1 + heights[row] - size := r.cells.t.Size() + size := r.cells.t.size.Load() if x2 < 0 || x1 > size.Width || y2 < 0 || y1 > size.Height { marker.Hide() } else { diff --git a/widget/tree.go b/widget/tree.go index ac050c1d06..e81fb108e1 100644 --- a/widget/tree.go +++ b/widget/tree.go @@ -233,7 +233,7 @@ func (t *Tree) OpenBranch(uid TreeNodeID) { // Resize sets a new size for a widget. func (t *Tree) Resize(size fyne.Size) { - if size == t.Size() { + if size == t.size.Load() { return } @@ -586,7 +586,7 @@ func (c *treeContent) CreateRenderer() fyne.WidgetRenderer { } func (c *treeContent) Resize(size fyne.Size) { - if size == c.Size() { + if size == c.size.Load() { return }