Skip to content

Commit

Permalink
fix: still existing error
Browse files Browse the repository at this point in the history
  • Loading branch information
muedsa committed Jan 15, 2024
1 parent e1ddae0 commit 44f9adb
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ open class RenderStack(
val childParentData: StackParentData = child.parentData as StackParentData
if (!childParentData.isPositioned) {
hasNonPositionedChildren = true
}
child.layout(nonPositionedConstraints)
val childSize: Size = child.definiteSize

width = max(width, childSize.width)
height = max(height, childSize.height)
child.layout(nonPositionedConstraints)
val childSize: Size = child.definiteSize

width = max(width, childSize.width)
height = max(height, childSize.height)
}
}

val size: Size
Expand All @@ -69,7 +70,7 @@ open class RenderStack(
}

override fun performLayout() {
var hasVisualOverflow = false
hasVisualOverflow = false
size = computeSize(definiteConstraints)

children?.forEach { child ->
Expand Down
13 changes: 10 additions & 3 deletions src/main/kotlin/com/muedsa/snapshot/widget/MultiChildWidget.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.muedsa.snapshot.widget

import com.muedsa.snapshot.rendering.box.RenderBox
import com.muedsa.snapshot.rendering.box.RenderContainerBox

abstract class MultiChildWidget(
val children: Array<out Widget>?,
Expand All @@ -17,9 +18,15 @@ abstract class MultiChildWidget(

final override fun createRenderBox(): RenderBox {
val renderTree = createRenderTree()
children?.forEach {
if (it is ParentDataWidget) {
it.applyChildParentDate(renderTree)
if (children != null) {
if (renderTree is RenderContainerBox
&& (renderTree.children?.size ?: 0) == children.size
) {
children.forEachIndexed { index, child ->
if (child is ParentDataWidget) {
child.applyParentData(renderTree.children!![index])
}
}
}
}
return renderTree
Expand Down
18 changes: 2 additions & 16 deletions src/main/kotlin/com/muedsa/snapshot/widget/ParentDataWidget.kt
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
package com.muedsa.snapshot.widget

import com.muedsa.snapshot.rendering.box.RenderBox
import com.muedsa.snapshot.rendering.box.RenderContainerBox
import com.muedsa.snapshot.rendering.box.RenderSingleChildBox

abstract class ParentDataWidget(
childBuilder: SingleWidgetBuilder,
) : SingleChildWidget(
childBuilder = childBuilder
) {
protected abstract fun applyParentData(renderBox: RenderBox)
abstract fun applyParentData(renderBox: RenderBox)

override fun createRenderTree(): RenderBox = child!!.createRenderBox()

fun applyChildParentDate(parent: RenderBox) {
if (parent is RenderSingleChildBox) {
parent.child?.let {
applyParentData(it)
}
} else if (parent is RenderContainerBox) {
parent.children?.forEach {
applyParentData(it)
}
}
}
final override fun createRenderTree(): RenderBox = child!!.createRenderBox()
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.muedsa.snapshot.widget

import com.muedsa.snapshot.rendering.box.RenderBox
import com.muedsa.snapshot.rendering.box.RenderSingleChildBox

abstract class SingleChildWidget(
val child: Widget?,
Expand All @@ -18,8 +19,8 @@ abstract class SingleChildWidget(

final override fun createRenderBox(): RenderBox {
val renderTree = createRenderTree()
if (child is ParentDataWidget) {
child.applyChildParentDate(renderTree)
if (child is ParentDataWidget && renderTree is RenderSingleChildBox) {
child.applyParentData(renderTree.child!!)
}
return renderTree
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/muedsa/snapshot/widget/SizedBox.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import com.muedsa.snapshot.rendering.box.RenderBox
import com.muedsa.snapshot.rendering.box.RenderConstrainedBox

class SizedBox(
val width: Float?,
val height: Float?,
val width: Float? = null,
val height: Float? = null,
childBuilder: SingleWidgetBuilder? = null,
) : SingleChildWidget(childBuilder = childBuilder) {

Expand Down
29 changes: 29 additions & 0 deletions src/test/kotlin/com/muedsa/snapshot/widget/FlexibleTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.muedsa.snapshot.widget

import com.muedsa.snapshot.paint.Axis
import com.muedsa.snapshot.rendering.flex.FlexParentData
import com.muedsa.snapshot.rendering.flex.RenderFlex
import kotlin.test.Test
import kotlin.test.expect

class FlexibleTest {

@Test
fun applyParentData_test() {
println("\n\n\nFlexibleTest.applyParentData_test()")
val flexArr = intArrayOf(1, 2, 3)
val children: Array<Widget> = Array(flexArr.size) {
Flexible(
flex = flexArr[it]
) {
Container()
}
}
val flex = Flex(direction = Axis.HORIZONTAL) { children }
val renderFlex = flex.createRenderBox() as RenderFlex
renderFlex.children!!.forEachIndexed { index, renderBox ->
val flexParentData: FlexParentData = renderBox.parentData as FlexParentData
expect(flexArr[index]) { flexParentData.flex }
}
}
}

0 comments on commit 44f9adb

Please sign in to comment.