Skip to content

Commit

Permalink
widget: Clean up locks within the BaseWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed Jan 11, 2025
1 parent 09446f7 commit 1aeb76d
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 75 deletions.
6 changes: 3 additions & 3 deletions widget/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func (c *checkRenderer) Layout(size fyne.Size) {
func (c *checkRenderer) applyTheme(th fyne.Theme, v fyne.ThemeVariant) {
c.label.Color = th.Color(theme.ColorNameForeground, v)
c.label.TextSize = th.Size(theme.SizeNameText)
if c.check.disabled.Load() {
if c.check.Disabled() {
c.label.Color = th.Color(theme.ColorNameDisabled, v)
}
}
Expand Down Expand Up @@ -359,7 +359,7 @@ func (c *checkRenderer) updateResource(th fyne.Theme) {
res.ColorName = theme.ColorNamePrimary
bgRes.ColorName = theme.ColorNameBackground
}
if c.check.disabled.Load() {
if c.check.Disabled() {
if c.check.Checked {
res = theme.NewThemedResource(theme.CheckButtonCheckedIcon())
}
Expand All @@ -374,7 +374,7 @@ func (c *checkRenderer) updateResource(th fyne.Theme) {

// must be called while holding c.check.propertyLock for reading
func (c *checkRenderer) updateFocusIndicator(th fyne.Theme, v fyne.ThemeVariant) {
if c.check.disabled.Load() {
if c.check.Disabled() {
c.focusIndicator.FillColor = color.Transparent
} else if c.check.focused {
c.focusIndicator.FillColor = th.Color(theme.ColorNameFocus, v)
Expand Down
4 changes: 2 additions & 2 deletions widget/check_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (r *CheckGroup) update() {

item.Text = r.Options[i]
item.Checked = contains
item.DisableableWidget.disabled.Store(r.disabled.Load())
item.DisableableWidget.disabled = r.Disabled()
item.Refresh()
}
}
Expand Down Expand Up @@ -257,7 +257,7 @@ func (r *checkGroupRenderer) updateItems() {
}
item.Text = r.checks.Options[i]
item.Checked = contains
item.disabled.Store(r.checks.disabled.Load())
item.disabled = r.checks.Disabled()
item.Refresh()
}
}
Expand Down
22 changes: 8 additions & 14 deletions widget/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func (e *Entry) Disable() {
//
// Implements: fyne.Disableable
func (e *Entry) Disabled() bool {
return e.DisableableWidget.disabled.Load()
return e.DisableableWidget.Disabled()
}

// DoubleTapped is called when this entry has been double tapped so we should select text below the pointer
Expand Down Expand Up @@ -298,13 +298,7 @@ func (e *Entry) Enable() {

// ExtendBaseWidget is used by an extending widget to make use of BaseWidget functionality.
func (e *Entry) ExtendBaseWidget(wid fyne.Widget) {
impl := e.super()
if impl != nil {
return
}

e.impl.Store(&wid)

e.BaseWidget.ExtendBaseWidget(wid)
e.registerShortcut()
}

Expand Down Expand Up @@ -1328,7 +1322,7 @@ func (e *Entry) textPosFromRowCol(row, col int) int {
func (e *Entry) syncSegments() {
colName := theme.ColorNameForeground
wrap := e.textWrap()
disabled := e.disabled.Load()
disabled := e.Disabled()
if disabled {
colName = theme.ColorNameDisabled
}
Expand Down Expand Up @@ -1696,7 +1690,7 @@ func (r *entryRenderer) Objects() []fyne.CanvasObject {

func (r *entryRenderer) Refresh() {
content := r.entry.content
focusedAppearance := r.entry.focused && !r.entry.disabled.Load()
focusedAppearance := r.entry.focused && !r.entry.Disabled()
scroll := r.entry.Scroll
wrapping := r.entry.Wrapping

Expand All @@ -1711,7 +1705,7 @@ func (r *entryRenderer) Refresh() {
inputBorder := th.Size(theme.SizeNameInputBorder)

// correct our scroll wrappers if the wrap mode changed
entrySize := r.entry.size.Load().Subtract(fyne.NewSize(r.trailingInset(), inputBorder*2))
entrySize := r.entry.Size().Subtract(fyne.NewSize(r.trailingInset(), inputBorder*2))
if wrapping == fyne.TextWrapOff && scroll == widget.ScrollNone && r.scroll.Content != nil {
r.scroll.Hide()
r.scroll.Content = nil
Expand Down Expand Up @@ -1774,7 +1768,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.Load())
r.Layout(r.entry.Size())

r.entry.validate()
r.Refresh()
Expand Down Expand Up @@ -1803,7 +1797,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.Load())
r.Layout(e.Size())
return r
}

Expand Down Expand Up @@ -1870,7 +1864,7 @@ func (r *entryContentRenderer) Refresh() {
provider := r.content.entry.textProvider()
placeholder := r.content.entry.placeholderProvider()
focused := r.content.entry.focused
focusedAppearance := focused && !r.content.entry.disabled.Load()
focusedAppearance := focused && !r.content.entry.Disabled()
selections := r.selection
r.updateScrollDirections()

Expand Down
2 changes: 1 addition & 1 deletion widget/entry_password.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (r *passwordRevealerRenderer) Refresh() {
r.icon.Resource = th.Icon(theme.IconNameVisibilityOff)
}

if r.entry.disabled.Load() {
if r.entry.Disabled() {
r.icon.Resource = theme.NewDisabledResource(r.icon.Resource)
}
r.icon.Refresh()
Expand Down
2 changes: 1 addition & 1 deletion widget/entry_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (r *validationStatusRenderer) MinSize() fyne.Size {

func (r *validationStatusRenderer) Refresh() {
th := r.entry.Theme()
if r.entry.disabled.Load() {
if r.entry.Disabled() {
r.icon.Hide()
return
}
Expand Down
6 changes: 3 additions & 3 deletions widget/hyperlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (hl *Hyperlink) focusWidth() float32 {
th := hl.Theme()

innerPad := th.Size(theme.SizeNameInnerPadding)
return fyne.Min(hl.size.Load().Width, hl.textSize.Width+innerPad+th.Size(theme.SizeNamePadding)*2) - innerPad
return fyne.Min(hl.Size().Width, hl.textSize.Width+innerPad+th.Size(theme.SizeNamePadding)*2) - innerPad
}

func (hl *Hyperlink) focusXPos() float32 {
Expand All @@ -135,9 +135,9 @@ func (hl *Hyperlink) focusXPos() float32 {
case fyne.TextAlignLeading:
return innerPad / 2
case fyne.TextAlignCenter:
return (hl.size.Load().Width - hl.focusWidth()) / 2
return (hl.Size().Width - hl.focusWidth()) / 2
case fyne.TextAlignTrailing:
return (hl.size.Load().Width - hl.focusWidth()) - innerPad/2
return (hl.Size().Width - hl.focusWidth()) - innerPad/2
default:
return 0 // unreached
}
Expand Down
2 changes: 1 addition & 1 deletion widget/progressbarinfinite.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (p *infProgressRenderer) MinSize() fyne.Size {
}

func (p *infProgressRenderer) updateBar(done float32) {
size := p.progress.size.Load()
size := p.progress.Size()
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 @@ -236,8 +236,8 @@ func (r *radioGroupRenderer) updateItems(refresh bool) {
item.Selected = sel
changed = true
}
if d := r.radio.disabled.Load(); d != item.disabled.Load() {
item.disabled.Store(d)
if d := r.radio.Disabled(); d != item.Disabled() {
item.disabled = d
changed = true
}

Expand Down
8 changes: 4 additions & 4 deletions widget/richtext.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ func (t *RichText) Refresh() {
//
// Implements: fyne.Widget
func (t *RichText) Resize(size fyne.Size) {
if size == t.size.Load() {
if size == t.Size() {
return
}

t.size.Store(size)
t.size = size

skipResize := !t.minCache.IsZero() && size.Width >= t.minCache.Width && size.Height >= t.minCache.Height && t.Wrapping == fyne.TextWrapOff && t.Truncation == fyne.TextTruncateOff

Expand Down Expand Up @@ -389,14 +389,14 @@ func (t *RichText) rows() int {
func (t *RichText) updateRowBounds() {
th := t.Theme()
innerPadding := th.Size(theme.SizeNameInnerPadding)
fitSize := t.size.Load()
fitSize := t.Size()
if t.scr != nil {
fitSize = t.scr.Content.MinSize()
}
fitSize.Height -= (innerPadding + t.inset.Height) * 2

var bounds []rowBoundary
maxWidth := t.size.Load().Width - 2*innerPadding + 2*t.inset.Width
maxWidth := t.Size().Width - 2*innerPadding + 2*t.inset.Width
wrapWidth := maxWidth

var currentBound *rowBoundary
Expand Down
21 changes: 11 additions & 10 deletions widget/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (s *Select) CreateRenderer() fyne.WidgetRenderer {
txtProv.inset = fyne.NewSquareSize(th.Size(theme.SizeNamePadding))
txtProv.ExtendBaseWidget(txtProv)
txtProv.Truncation = fyne.TextTruncateEllipsis
if s.disabled.Load() {
if s.Disabled() {
txtProv.Segments[0].(*TextSegment).Style.ColorName = theme.ColorNameDisabled
}

Expand Down Expand Up @@ -421,15 +421,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.Load().Width, s.combo.popUp.MinSize().Height))
s.combo.popUp.Resize(fyne.NewSize(s.combo.Size().Width, s.combo.popUp.MinSize().Height))
s.combo.popUp.Refresh()
}
s.background.Refresh()
canvas.Refresh(s.combo.super())
}

func (s *selectRenderer) bgColor(th fyne.Theme, v fyne.ThemeVariant) color.Color {
if s.combo.disabled.Load() {
if s.combo.Disabled() {
return th.Color(theme.ColorNameDisabledButton, v)
}
if s.combo.focused {
Expand All @@ -443,7 +443,7 @@ func (s *selectRenderer) bgColor(th fyne.Theme, v fyne.ThemeVariant) color.Color

func (s *selectRenderer) updateIcon(th fyne.Theme) {
icon := th.Icon(theme.IconNameArrowDropDown)
if s.combo.disabled.Load() {
if s.combo.Disabled() {
s.icon.Resource = theme.NewDisabledResource(icon)
} else {
s.icon.Resource = icon
Expand All @@ -456,16 +456,17 @@ func (s *selectRenderer) updateLabel() {
s.combo.PlaceHolder = defaultPlaceHolder
}

s.label.Segments[0].(*TextSegment).Style.Alignment = s.combo.Alignment
if s.combo.disabled.Load() {
s.label.Segments[0].(*TextSegment).Style.ColorName = theme.ColorNameDisabled
segment := s.label.Segments[0].(*TextSegment)
segment.Style.Alignment = s.combo.Alignment
if s.combo.Disabled() {
segment.Style.ColorName = theme.ColorNameDisabled
} else {
s.label.Segments[0].(*TextSegment).Style.ColorName = theme.ColorNameForeground
segment.Style.ColorName = theme.ColorNameForeground
}
if s.combo.Selected == "" {
s.label.Segments[0].(*TextSegment).Text = s.combo.PlaceHolder
segment.Text = s.combo.PlaceHolder
} else {
s.label.Segments[0].(*TextSegment).Text = s.combo.Selected
segment.Text = s.combo.Selected
}
s.label.Refresh()
}
2 changes: 1 addition & 1 deletion widget/slider.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (s *Slider) getRatio(e *fyne.PointEvent) float64 {

x := e.Position.X
y := e.Position.Y
size := s.size.Load()
size := s.Size()

switch s.Orientation {
case Vertical:
Expand Down
8 changes: 4 additions & 4 deletions widget/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ func (t *Table) visibleColumnWidths(colWidth float32, cols int) (visible map[int

padding := t.Theme().Size(theme.SizeNamePadding)
stick := t.StickyColumnCount
size := t.size.Load()
size := t.Size()

if len(t.columnWidths) == 0 {
paddedWidth := colWidth + padding
Expand Down Expand Up @@ -961,7 +961,7 @@ func (t *Table) visibleRowHeights(rowHeight float32, rows int) (visible map[int]

padding := t.Theme().Size(theme.SizeNamePadding)
stick := t.StickyRowCount
size := t.size.Load()
size := t.Size()

if len(t.rowHeights) == 0 {
paddedHeight := rowHeight + padding
Expand Down Expand Up @@ -1448,7 +1448,7 @@ func (r *tableCellsRenderer) moveIndicators() {
r.cells.t.dividerLayer.Content.Refresh()
}

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

divs := 0
i := 0
Expand Down Expand Up @@ -1552,7 +1552,7 @@ func (r *tableCellsRenderer) moveMarker(marker fyne.CanvasObject, row, col int,
}
y2 := y1 + heights[row]

size := r.cells.t.size.Load()
size := r.cells.t.Size()
if x2 < 0 || x1 > size.Width || y2 < 0 || y1 > size.Height {
marker.Hide()
} else {
Expand Down
8 changes: 4 additions & 4 deletions widget/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,11 @@ 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.Load() {
if size == t.Size() {
return
}

t.size.Store(size)
t.size = size

t.Refresh() // trigger a redraw
}
Expand Down Expand Up @@ -584,11 +584,11 @@ func (c *treeContent) CreateRenderer() fyne.WidgetRenderer {
}

func (c *treeContent) Resize(size fyne.Size) {
if size == c.size.Load() {
if size == c.Size() {
return
}

c.size.Store(size)
c.size = size

c.Refresh() // trigger a redraw
}
Expand Down
Loading

0 comments on commit 1aeb76d

Please sign in to comment.