Skip to content

Commit

Permalink
Minor refactoring of canvas.Text logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed May 1, 2024
1 parent 670a45e commit 78bd85c
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions layout/formlayout.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func (f *formLayout) tableCellsSize(objects []fyne.CanvasObject, containerWidth
return 0, 0, heights
}

padding := theme.Padding()
innerPadding := theme.InnerPadding()
lowBound := 0
highBound := 2
Expand Down Expand Up @@ -69,7 +68,7 @@ func (f *formLayout) tableCellsSize(objects []fyne.CanvasObject, containerWidth
row++
}

contentCellMaxWidth = fyne.Max(contentCellMaxWidth, containerWidth-labelCellMaxWidth-padding)
contentCellMaxWidth = fyne.Max(contentCellMaxWidth, containerWidth-labelCellMaxWidth-theme.Padding())
return labelCellMaxWidth, contentCellMaxWidth, heights
}

Expand All @@ -90,22 +89,28 @@ func (f *formLayout) Layout(objects []fyne.CanvasObject, size fyne.Size) {
y += heights[row-1] + padding
}

pos := fyne.NewPos(0, y)
size := fyne.NewSize(labelWidth, heights[row])
if _, ok := objects[i].(*canvas.Text); ok {
objects[i].Move(fyne.NewPos(innerPadding, y+innerPadding))
objects[i].Resize(fyne.NewSize(labelWidth-innerPadding*2, objects[i].MinSize().Height))
} else {
objects[i].Move(fyne.NewPos(0, y))
objects[i].Resize(fyne.NewSize(labelWidth, heights[row]))
pos = pos.AddXY(innerPadding, innerPadding)
size.Width -= innerPadding * 2
size.Height = objects[i].MinSize().Height
}

objects[i].Move(pos)
objects[i].Resize(size)

if i+1 < len(objects) {
pos = fyne.NewPos(padding+labelWidth, y)
size = fyne.NewSize(contentWidth, heights[row])
if _, ok := objects[i+1].(*canvas.Text); ok {
objects[i+1].Move(fyne.NewPos(padding+labelWidth+innerPadding, y+innerPadding))
objects[i+1].Resize(fyne.NewSize(contentWidth-innerPadding*2, objects[i+1].MinSize().Height))
} else {
objects[i+1].Move(fyne.NewPos(padding+labelWidth, y))
objects[i+1].Resize(fyne.NewSize(contentWidth, heights[row]))
pos = pos.AddXY(innerPadding, innerPadding)
size.Width -= innerPadding * 2
size.Height = objects[i+1].MinSize().Height
}

objects[i+1].Move(pos)
objects[i+1].Resize(size)
}
row++
}
Expand Down

0 comments on commit 78bd85c

Please sign in to comment.