Skip to content

Commit

Permalink
fix flex layout calculation (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
yohamta authored Apr 28, 2023
1 parent 63d0cba commit bafd685
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
13 changes: 12 additions & 1 deletion flex.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ func (f *flexEmbed) layout(width, height int, container *containerEmbed) {
line := &lines[l]
for _, child := range line.child {
if f.AlignItems == AlignItemStretch &&
f.crossSize(child.node.item.Width, child.node.item.Height) == 0 &&
!f.isCrossSizeFixed(child.node.item) &&
child.crossSize < line.crossSize {
crossMargin := child.crossMargin[0] + child.crossMargin[1]
child.crossSize = line.crossSize - crossMargin
Expand Down Expand Up @@ -743,6 +743,17 @@ func (f *flexEmbed) setMainSize(v int) {
}
}

func (f *flexEmbed) isCrossSizeFixed(v *View) bool {
switch f.Direction {
case Row:
return v.isHeightFixed()
case Column:
return v.isWidthFixed()
default:
panic(fmt.Sprint("flex: bad direction ", f.Direction))
}
}

func (f *flexEmbed) crossSize(x, y int) int {
switch f.Direction {
case Row:
Expand Down
8 changes: 8 additions & 0 deletions view.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,21 @@ func (v *View) addChild(cv *View) *View {
return v
}

func (v *View) isWidthFixed() bool {
return v.Width != 0 || v.WidthInPct != 0
}

func (v *View) width() int {
if v.Width == 0 {
return v.calculatedWidth
}
return v.Width
}

func (v *View) isHeightFixed() bool {
return v.Height != 0 || v.HeightInPct != 0
}

func (v *View) height() int {
if v.Height == 0 {
return v.calculatedHeight
Expand Down

0 comments on commit bafd685

Please sign in to comment.