diff --git a/widget/entry.go b/widget/entry.go index b5ddcb6afe..ceda8beb1f 100644 --- a/widget/entry.go +++ b/widget/entry.go @@ -1668,7 +1668,6 @@ func (r *entryRenderer) Refresh() { content := r.entry.content focusedAppearance := r.entry.focused && !r.entry.disabled scroll := r.entry.Scroll - size := r.entry.size wrapping := r.entry.Wrapping r.entry.propertyLock.RUnlock() @@ -1679,7 +1678,7 @@ func (r *entryRenderer) Refresh() { r.entry.placeholder.Refresh() // correct our scroll wrappers if the wrap mode changed - entrySize := size.Subtract(fyne.NewSize(r.trailingInset(), theme.InputBorderSize()*2)) + entrySize := r.entry.Size().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 +1741,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()) r.entry.Validate() @@ -1774,7 +1773,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()) return r } diff --git a/widget/progressbarinfinite.go b/widget/progressbarinfinite.go index 85650de404..2d11989491 100644 --- a/widget/progressbarinfinite.go +++ b/widget/progressbarinfinite.go @@ -34,13 +34,14 @@ func (p *infProgressRenderer) MinSize() fyne.Size { } func (p *infProgressRenderer) updateBar(done float32) { - progressWidth := p.progress.size.Width + size := p.progress.Size() + progressWidth := size.Width spanWidth := progressWidth + (progressWidth * (maxProgressBarInfiniteWidthRatio / 2)) maxBarWidth := progressWidth * maxProgressBarInfiniteWidthRatio barCenterX := spanWidth*done - (spanWidth-progressWidth)/2 barPos := fyne.NewPos(barCenterX-maxBarWidth/2, 0) - barSize := fyne.NewSize(maxBarWidth, p.progress.size.Height) + barSize := fyne.NewSize(maxBarWidth, size.Height) if barPos.X < 0 { barSize.Width += barPos.X barPos.X = 0 diff --git a/widget/richtext.go b/widget/richtext.go index 6b14fb9f71..725e960ed8 100644 --- a/widget/richtext.go +++ b/widget/richtext.go @@ -107,17 +107,16 @@ func (t *RichText) Refresh() { // // Implements: fyne.Widget func (t *RichText) Resize(size fyne.Size) { + if size == t.Size() { + return + } + + t.size.Store(uint64fromTwoFloat32(size.Width, size.Height)) + t.propertyLock.RLock() - baseSize := t.size 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 baseSize == size { - return - } - t.propertyLock.Lock() - t.size = size - t.propertyLock.Unlock() if skipResize { if len(segments) < 2 { // we can simplify :) @@ -364,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().Width - 2*innerPadding + 2*t.inset.Width wrapWidth := maxWidth var currentBound *rowBoundary diff --git a/widget/select.go b/widget/select.go index d268eb266e..c56ddff570 100644 --- a/widget/select.go +++ b/widget/select.go @@ -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().Width, s.combo.popUp.MinSize().Height)) s.combo.popUp.Refresh() } s.background.Refresh() diff --git a/widget/slider.go b/widget/slider.go index 07c5685123..c9f7a11d16 100644 --- a/widget/slider.go +++ b/widget/slider.go @@ -243,23 +243,24 @@ func (s *Slider) getRatio(e *fyne.PointEvent) float64 { x := e.Position.X y := e.Position.Y + size := s.Size() switch s.Orientation { case Vertical: - if y > s.size.Height-pad { + if y > size.Height-pad { return 0.0 } else if y < pad { return 1.0 } else { - return 1 - float64(y-pad)/float64(s.size.Height-pad*2) + return 1 - float64(y-pad)/float64(size.Height-pad*2) } case Horizontal: - if x > s.size.Width-pad { + if x > size.Width-pad { return 1.0 } else if x < pad { return 0.0 } else { - return float64(x-pad) / float64(s.size.Width-pad*2) + return float64(x-pad) / float64(size.Width-pad*2) } } return 0.0 diff --git a/widget/table.go b/widget/table.go index d492487fa3..bcebcb2c2f 100644 --- a/widget/table.go +++ b/widget/table.go @@ -854,13 +854,14 @@ 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() if len(t.columnWidths) == 0 { paddedWidth := colWidth + padding offX = float32(math.Floor(float64(t.offset.X/paddedWidth))) * paddedWidth minCol = int(math.Floor(float64(offX / paddedWidth))) - maxCol = int(math.Ceil(float64((t.offset.X + t.size.Width) / paddedWidth))) + maxCol = int(math.Ceil(float64((t.offset.X + size.Width) / paddedWidth))) if minCol > cols-1 { minCol = cols - 1 @@ -896,7 +897,7 @@ func (t *Table) visibleColumnWidths(colWidth float32, cols int) (visible map[int offX = colOffset isVisible = true } - if colOffset < t.offset.X+t.size.Width { + if colOffset < t.offset.X+size.Width { maxCol = i + 1 } else { break @@ -954,13 +955,14 @@ 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() if len(t.rowHeights) == 0 { paddedHeight := rowHeight + padding offY = float32(math.Floor(float64(t.offset.Y/paddedHeight))) * paddedHeight minRow = int(math.Floor(float64(offY / paddedHeight))) - maxRow = int(math.Ceil(float64((t.offset.Y + t.size.Height) / paddedHeight))) + maxRow = int(math.Ceil(float64((t.offset.Y + size.Height) / paddedHeight))) if minRow > rows-1 { minRow = rows - 1 @@ -996,7 +998,7 @@ func (t *Table) visibleRowHeights(rowHeight float32, rows int) (visible map[int] offY = rowOffset isVisible = true } - if rowOffset < t.offset.Y+t.size.Height { + if rowOffset < t.offset.Y+size.Height { maxRow = i + 1 } else { break @@ -1448,7 +1450,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, r.cells.t.Size().Height)) r.dividers[divs].Move(fyne.NewPos(xPos, 0)) r.dividers[divs].Show() divs++ @@ -1459,7 +1461,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, r.cells.t.Size().Height)) r.dividers[divs].Move(fyne.NewPos(xPos, 0)) r.dividers[divs].Show() divs++ @@ -1471,7 +1473,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(r.cells.t.Size().Width, separatorThickness)) r.dividers[divs].Move(fyne.NewPos(0, yPos)) r.dividers[divs].Show() divs++ @@ -1482,7 +1484,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(r.cells.t.Size().Width, separatorThickness)) r.dividers[divs].Move(fyne.NewPos(0, yPos)) r.dividers[divs].Show() divs++ @@ -1543,7 +1545,8 @@ func (r *tableCellsRenderer) moveMarker(marker fyne.CanvasObject, row, col int, } y2 := y1 + heights[row] - if x2 < 0 || x1 > r.cells.t.size.Width || y2 < 0 || y1 > r.cells.t.size.Height { + size := r.cells.t.Size() + if x2 < 0 || x1 > size.Width || y2 < 0 || y1 > size.Height { marker.Hide() } else { left := x1 diff --git a/widget/textgrid.go b/widget/textgrid.go index 2856719f14..6b68a99707 100644 --- a/widget/textgrid.go +++ b/widget/textgrid.go @@ -537,7 +537,7 @@ func (t *textGridRenderer) Refresh() { t.updateCellSize() TextGridStyleWhitespace = &CustomTextGridStyle{FGColor: theme.DisabledColor()} - t.updateGridSize(t.text.size) + t.updateGridSize(t.text.Size()) t.refreshGrid() } diff --git a/widget/tree.go b/widget/tree.go index bd71c2efb7..f21ed8099a 100644 --- a/widget/tree.go +++ b/widget/tree.go @@ -233,17 +233,11 @@ func (t *Tree) OpenBranch(uid TreeNodeID) { // Resize sets a new size for a widget. func (t *Tree) Resize(size fyne.Size) { - t.propertyLock.RLock() - s := t.size - t.propertyLock.RUnlock() - - if s == size { + if size == t.Size() { return } - t.propertyLock.Lock() - t.size = size - t.propertyLock.Unlock() + t.size.Store(uint64fromTwoFloat32(size.Width, size.Height)) t.Refresh() // trigger a redraw } @@ -592,17 +586,11 @@ func (c *treeContent) CreateRenderer() fyne.WidgetRenderer { } func (c *treeContent) Resize(size fyne.Size) { - c.propertyLock.RLock() - s := c.size - c.propertyLock.RUnlock() - - if s == size { + if size == c.Size() { return } - c.propertyLock.Lock() - c.size = size - c.propertyLock.Unlock() + c.size.Store(uint64fromTwoFloat32(size.Width, size.Height)) c.Refresh() // trigger a redraw } @@ -976,7 +964,7 @@ func (r *treeNodeRenderer) partialRefresh() { r.background.Hide() } r.background.Refresh() - r.Layout(r.treeNode.size) + r.Layout(r.treeNode.Size()) canvas.Refresh(r.treeNode.super()) } diff --git a/widget/widget.go b/widget/widget.go index 4cffd2ef80..0fed691f21 100644 --- a/widget/widget.go +++ b/widget/widget.go @@ -14,7 +14,7 @@ import ( // BaseWidget provides a helper that handles basic widget behaviours. type BaseWidget struct { - size fyne.Size + size atomic.Uint64 position atomic.Uint64 Hidden bool @@ -34,25 +34,17 @@ func (w *BaseWidget) ExtendBaseWidget(wid fyne.Widget) { // Size gets the current size of this widget. func (w *BaseWidget) Size() fyne.Size { - w.propertyLock.RLock() - defer w.propertyLock.RUnlock() - - return w.size + return fyne.NewSize(twoFloat32FromUint64(w.size.Load())) } // Resize sets a new size for a widget. // Note this should not be used if the widget is being managed by a Layout within a Container. func (w *BaseWidget) Resize(size fyne.Size) { - w.propertyLock.RLock() - baseSize := w.size - w.propertyLock.RUnlock() - if baseSize == size { + if size == w.Size() { return } - w.propertyLock.Lock() - w.size = size - w.propertyLock.Unlock() + w.size.Store(uint64fromTwoFloat32(size.Width, size.Height)) impl := w.super() if impl == nil {