Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix locking and random blanks with List #3488

Merged
merged 4 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 7 additions & 10 deletions widget/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,8 @@ func (l *listLayout) updateList(refresh bool) {
l.list.propertyLock.Lock()
visibleRowHeights, offY, minRow, maxRow := l.list.visibleItemHeights(l.list.itemMin.Height, length)
l.list.propertyLock.Unlock()
l.renderLock.Unlock() // user code should not be locked
if len(visibleRowHeights) == 0 && length > 0 { // we can't show anything until we have some dimensions
l.renderLock.Unlock() // user code should not be locked
return
}

Expand All @@ -589,24 +589,16 @@ func (l *listLayout) updateList(refresh bool) {
continue
}
c.Resize(size)
l.setupListItem(c, row)
}

c.Move(fyne.NewPos(0, y))
if refresh {
c.Resize(size)
if ok { // refresh visible
l.setupListItem(c, row)
}
}
c.Resize(size)

y += itemHeight + separatorThickness
visible[row] = c
cells = append(cells, c)
}

l.renderLock.Lock()
defer l.renderLock.Unlock()
l.visible = visible

for id, old := range wasVisible {
Expand All @@ -621,6 +613,11 @@ func (l *listLayout) updateList(refresh bool) {
objects := l.children
objects = append(objects, l.separators...)
l.list.scroller.Content.(*fyne.Container).Objects = objects
l.renderLock.Unlock() // user code should not be locked

for row, obj := range visible {
l.setupListItem(obj, row)
}
}

func (l *listLayout) updateSeparators() {
Expand Down
20 changes: 11 additions & 9 deletions widget/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type TableCellID struct {
}

// Table widget is a grid of items that can be scrolled and a cell selected.
// It's performance is provided by caching cell templates created with CreateCell and re-using them with UpdateCell.
// Its performance is provided by caching cell templates created with CreateCell and re-using them with UpdateCell.
// The size of the content rows/columns is returned by the Length callback.
//
// Since: 1.4
Expand Down Expand Up @@ -289,7 +289,6 @@ func (t *Table) findX(col int) (cellX float32, cellWidth float32) {

func (t *Table) findY(row int) (cellY float32, cellHeight float32) {
cellSize := t.templateSize()
cellY = float32(row) * (cellHeight + theme.Padding())
for i := 0; i <= row; i++ {
if cellHeight > 0 {
cellY += cellHeight + theme.Padding()
Expand Down Expand Up @@ -575,9 +574,6 @@ func (c *tableCells) MouseOut() {
}

func (c *tableCells) Resize(s fyne.Size) {
if s == c.BaseWidget.size {
return
}
c.BaseWidget.Resize(s)
c.Refresh() // trigger a redraw
}
Expand Down Expand Up @@ -727,7 +723,6 @@ func (r *tableCellsRenderer) MinSize() fyne.Size {

func (r *tableCellsRenderer) Refresh() {
r.cells.propertyLock.Lock()
defer r.cells.propertyLock.Unlock()
oldSize := r.cells.cellSize
r.cells.cellSize = r.cells.t.templateSize()
if oldSize != r.cells.cellSize { // theme changed probably
Expand All @@ -741,10 +736,12 @@ func (r *tableCellsRenderer) Refresh() {
}
visibleColWidths, offX, minCol, maxCol := r.cells.t.visibleColumnWidths(r.cells.cellSize.Width, dataCols)
if len(visibleColWidths) == 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.cellSize.Height, dataRows)
if len(visibleRowHeights) == 0 { // we can't show anything until we have some dimensions
r.cells.propertyLock.Unlock()
return
}

Expand Down Expand Up @@ -777,9 +774,6 @@ func (r *tableCellsRenderer) Refresh() {
c.Move(fyne.NewPos(cellXOffset, cellYOffset))
c.Resize(fyne.NewSize(colWidth, rowHeight))

if updateCell != nil {
updateCell(TableCellID{row, col}, c)
}
r.visible[id] = c
cells = append(cells, c)
cellXOffset += colWidth + separatorThickness
Expand All @@ -792,7 +786,15 @@ func (r *tableCellsRenderer) Refresh() {
r.pool.Release(old)
}
}
visible := r.visible
r.cells.propertyLock.Unlock()
r.SetObjects(cells)

if updateCell != nil {
for id, cell := range visible {
updateCell(TableCellID{id.Row, id.Col}, cell)
}
}
}

func (r *tableCellsRenderer) returnAllToPool() {
Expand Down