Skip to content

Commit

Permalink
Now we have standard padded widgets we don't need padding in collections
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed May 14, 2021
1 parent f96350f commit 6b7d4bf
Show file tree
Hide file tree
Showing 44 changed files with 703 additions and 576 deletions.
7 changes: 3 additions & 4 deletions widget/list.go
Expand Up @@ -317,17 +317,16 @@ type listItemRenderer struct {
// This is based on the size of the status indicator and the size of the child object.
func (li *listItemRenderer) MinSize() (size fyne.Size) {
itemSize := li.item.child.MinSize()
size = fyne.NewSize(itemSize.Width+theme.Padding()*3,
itemSize.Height+theme.Padding()*2)
size = fyne.NewSize(itemSize.Width+theme.Padding(), itemSize.Height)
return
}

// Layout the components of the listItem widget.
func (li *listItemRenderer) Layout(size fyne.Size) {
li.item.background.Resize(size)

li.item.child.Move(fyne.NewPos(theme.Padding()*2, theme.Padding()))
li.item.child.Resize(fyne.NewSize(size.Width-theme.Padding()*3, size.Height-theme.Padding()*2))
li.item.child.Move(fyne.NewPos(theme.Padding(), 0))
li.item.child.Resize(fyne.NewSize(size.Width-theme.Padding(), size.Height))
}

func (li *listItemRenderer) Refresh() {
Expand Down
20 changes: 10 additions & 10 deletions widget/list_test.go
Expand Up @@ -38,7 +38,7 @@ func TestList_MinSize(t *testing.T) {
},
"large": {
fyne.NewSize(100, 100),
fyne.NewSize(100+3*theme.Padding(), 100+2*theme.Padding()),
fyne.NewSize(100+theme.Padding(), 100),
},
} {
t.Run(name, func(t *testing.T) {
Expand Down Expand Up @@ -108,17 +108,17 @@ func TestList_ScrollTo(t *testing.T) {
assert.Equal(t, offset, list.offsetY)
assert.Equal(t, offset, list.scroller.Offset.Y)

offset = float32(8245)
offset = float32(6637)
list.ScrollTo(200)
assert.Equal(t, offset, list.offsetY)
assert.Equal(t, offset, list.scroller.Offset.Y)

offset = float32(44999)
offset = float32(36999)
list.ScrollTo(999)
assert.Equal(t, offset, list.offsetY)
assert.Equal(t, offset, list.scroller.Offset.Y)

offset = float32(23000)
offset = float32(19000)
list.ScrollTo(500)
assert.Equal(t, offset, list.offsetY)
assert.Equal(t, offset, list.scroller.Offset.Y)
Expand All @@ -127,7 +127,7 @@ func TestList_ScrollTo(t *testing.T) {
assert.Equal(t, offset, list.offsetY)
assert.Equal(t, offset, list.scroller.Offset.Y)

offset = float32(46)
offset = float32(38)
list.ScrollTo(1)
assert.Equal(t, offset, list.offsetY)
assert.Equal(t, offset, list.scroller.Offset.Y)
Expand All @@ -136,7 +136,7 @@ func TestList_ScrollTo(t *testing.T) {
func TestList_ScrollToBottom(t *testing.T) {
list := createList(1000)

offset := float32(44999)
offset := float32(36999)
list.ScrollToBottom()
assert.Equal(t, offset, list.offsetY)
assert.Equal(t, offset, list.scroller.Offset.Y)
Expand Down Expand Up @@ -187,19 +187,19 @@ func TestList_Select(t *testing.T) {

assert.Equal(t, float32(0), list.offsetY)
list.Select(50)
assert.Equal(t, float32(1345), list.offsetY)
assert.Equal(t, float32(937), list.offsetY)
visible := list.scroller.Content.(*fyne.Container).Layout.(*listLayout).visible
assert.Equal(t, visible[50].background.FillColor, theme.FocusColor())
assert.True(t, visible[50].background.Visible())

list.Select(5)
assert.Equal(t, float32(230), list.offsetY)
assert.Equal(t, float32(190), list.offsetY)
visible = list.scroller.Content.(*fyne.Container).Layout.(*listLayout).visible
assert.Equal(t, visible[5].background.FillColor, theme.FocusColor())
assert.True(t, visible[5].background.Visible())

list.Select(6)
assert.Equal(t, float32(230), list.offsetY)
assert.Equal(t, float32(190), list.offsetY)
visible = list.scroller.Content.(*fyne.Container).Layout.(*listLayout).visible
assert.False(t, visible[5].background.Visible())
assert.Equal(t, visible[6].background.FillColor, theme.FocusColor())
Expand Down Expand Up @@ -369,7 +369,7 @@ func TestList_ScrollThenShrink(t *testing.T) {

visibles := list.scroller.Content.(*fyne.Container).Layout.(*listLayout).children
visibleCount := len(visibles)
assert.Equal(t, visibleCount, 8)
assert.Equal(t, visibleCount, 9)

list.scroller.ScrollToBottom()
visibles = list.scroller.Content.(*fyne.Container).Layout.(*listLayout).children
Expand Down
27 changes: 13 additions & 14 deletions widget/table.go
Expand Up @@ -63,7 +63,7 @@ func (t *Table) CreateRenderer() fyne.WidgetRenderer {
colHover := canvas.NewRectangle(theme.HoverColor())
rowHover := canvas.NewRectangle(theme.HoverColor())

cellSize := t.templateSize().Add(fyne.NewSize(theme.Padding()*2, theme.Padding()*2))
cellSize := t.templateSize()
t.cells = newTableCells(t, cellSize)
t.scroll = widget.NewScroll(t.cells)

Expand Down Expand Up @@ -104,14 +104,14 @@ func (t *Table) Select(id TableCellID) {

// SetColumnWidth supports changing the width of the specified column. Columns normally take the width of the template
// cell returned from the CreateCell callback. The width parameter uses the same units as a fyne.Size type and refers
// to the internal content width not including any standard padding or divider size.
// to the internal content width not including the divider size.
//
// Since: 1.4.1
func (t *Table) SetColumnWidth(id int, width float32) {
if t.columnWidths == nil {
t.columnWidths = make(map[int]float32)
}
t.columnWidths[id] = width + 2*theme.Padding() // The API uses content size so it's consistent with templates
t.columnWidths[id] = width
t.Refresh()
}

Expand Down Expand Up @@ -157,16 +157,15 @@ func (t *Table) scrollTo(id TableCellID) {
}
scrollPos := t.offset

minSize := t.templateSize()
cellPadded := minSize.Add(fyne.NewSize(theme.Padding()*2, theme.Padding()*2))
cellSize := t.templateSize()
cellX := float32(0)
cellWidth := float32(0)
for i := 0; i <= id.Col; i++ {
if cellWidth > 0 {
cellX += cellWidth + theme.SeparatorThicknessSize()
}

width := cellPadded.Width
width := cellSize.Width
if w, ok := t.columnWidths[i]; ok {
width = w
}
Expand All @@ -179,11 +178,11 @@ func (t *Table) scrollTo(id TableCellID) {
scrollPos.X = cellX + cellWidth - t.scroll.Size().Width
}

cellY := float32(id.Row) * (cellPadded.Height + theme.SeparatorThicknessSize())
cellY := float32(id.Row) * (cellSize.Height + theme.SeparatorThicknessSize())
if cellY < scrollPos.Y {
scrollPos.Y = cellY
} else if cellY+cellPadded.Height > scrollPos.Y+t.scroll.Size().Height {
scrollPos.Y = cellY + cellPadded.Height - t.scroll.Size().Height
} else if cellY+cellSize.Height > scrollPos.Y+t.scroll.Size().Height {
scrollPos.Y = cellY + cellSize.Height - t.scroll.Size().Height
}
t.scroll.Offset = scrollPos
t.offset = scrollPos
Expand Down Expand Up @@ -268,7 +267,7 @@ func (t *tableRenderer) MinSize() fyne.Size {
}

func (t *tableRenderer) Refresh() {
t.cellSize = t.t.templateSize().Add(fyne.NewSize(theme.Padding()*2, theme.Padding()*2))
t.cellSize = t.t.templateSize()
t.moveIndicators()

t.colMarker.FillColor = theme.PrimaryColor()
Expand Down Expand Up @@ -548,7 +547,7 @@ func (r *tableCellsRenderer) Refresh() {
r.cells.propertyLock.Lock()
defer r.cells.propertyLock.Unlock()
oldSize := r.cells.cellSize
r.cells.cellSize = r.cells.t.templateSize().Add(fyne.NewSize(theme.Padding()*2, theme.Padding()*2))
r.cells.cellSize = r.cells.t.templateSize()
if oldSize != r.cells.cellSize { // theme changed probably
r.returnAllToPool()
}
Expand Down Expand Up @@ -591,9 +590,9 @@ func (r *tableCellsRenderer) Refresh() {
}
}

c.Move(fyne.NewPos(theme.Padding()+cellOffset,
theme.Padding()+float32(row)*(r.cells.cellSize.Height+separatorThickness)))
c.Resize(fyne.NewSize(colWidth-theme.Padding()*2, r.cells.cellSize.Height-theme.Padding()*2))
c.Move(fyne.NewPos(cellOffset,
float32(row)*(r.cells.cellSize.Height+separatorThickness)))
c.Resize(fyne.NewSize(colWidth, r.cells.cellSize.Height))

if updateCell != nil {
updateCell(TableCellID{row, col}, c)
Expand Down
8 changes: 4 additions & 4 deletions widget/table_test.go
Expand Up @@ -112,7 +112,7 @@ func TestTable_MinSize(t *testing.T) {
},
"large": {
fyne.NewSize(100, 100),
fyne.NewSize(100+3*theme.Padding(), 100+3*theme.Padding()),
fyne.NewSize(100+theme.Padding(), 100+theme.Padding()),
},
} {
t.Run(name, func(t *testing.T) {
Expand Down Expand Up @@ -284,9 +284,9 @@ func TestTable_SetColumnWidth(t *testing.T) {
renderer := test.WidgetRenderer(table).(*tableRenderer)
cellRenderer := test.WidgetRenderer(renderer.scroll.Content.(*tableCells))
cellRenderer.Refresh()
assert.Equal(t, 8, len(cellRenderer.Objects()))
assert.Equal(t, 10, len(cellRenderer.Objects()))
assert.Equal(t, float32(32), cellRenderer.(*tableCellsRenderer).Objects()[0].Size().Width)
cell1Offset := theme.SeparatorThicknessSize() + theme.Padding()*3
cell1Offset := theme.SeparatorThicknessSize()
assert.Equal(t, float32(32)+cell1Offset, cellRenderer.(*tableCellsRenderer).Objects()[1].Position().X)

table.SetColumnWidth(0, 16)
Expand All @@ -311,7 +311,7 @@ func TestTable_ShowVisible(t *testing.T) {
renderer := test.WidgetRenderer(table).(*tableRenderer)
cellRenderer := test.WidgetRenderer(renderer.scroll.Content.(*tableCells))
cellRenderer.Refresh()
assert.Equal(t, 8, len(cellRenderer.Objects()))
assert.Equal(t, 10, len(cellRenderer.Objects()))
}

func TestTable_SeparatorThicknessZero_NotPanics(t *testing.T) {
Expand Down

0 comments on commit 6b7d4bf

Please sign in to comment.