Skip to content

Commit

Permalink
Don't call public methods inside locks
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed Jan 6, 2024
1 parent 88f799a commit 6da8faf
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 44 deletions.
15 changes: 8 additions & 7 deletions internal/widget/scroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -326,15 +327,15 @@ 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))

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()
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion widget/button.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions widget/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down Expand Up @@ -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())
}
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions widget/check_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down Expand Up @@ -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()
}
}
14 changes: 7 additions & 7 deletions widget/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion widget/entry_password.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion widget/entry_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion widget/progressbarinfinite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions widget/radio_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down Expand Up @@ -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()
}
}
Expand Down
6 changes: 3 additions & 3 deletions widget/richtext.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -355,15 +355,15 @@ 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()
}
fitSize.Height -= (innerPadding + t.inset.Height) * 2

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
Expand Down
12 changes: 6 additions & 6 deletions widget/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -334,15 +334,15 @@ 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()
canvas.Refresh(s.combo.super())
}

func (s *selectRenderer) bgColor() color.Color {
if s.combo.Disabled() {
if s.combo.disabled.Load() {
return theme.DisabledButtonColor()
}
if s.combo.focused {
Expand All @@ -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()
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion widget/slider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 9 additions & 7 deletions widget/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1443,14 +1443,16 @@ func (r *tableCellsRenderer) moveIndicators() {
r.cells.t.dividerLayer.Content.Refresh()
}

size := r.cells.t.size.Load()

divs := 0
i := 0
if stickCols > 0 {
for x := r.cells.t.stuckXOff + visibleColWidths[i]; i < stickCols && divs < colDivs; x += visibleColWidths[i] + padding {
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++
Expand All @@ -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++
Expand All @@ -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++
Expand All @@ -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++
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions widget/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 6da8faf

Please sign in to comment.