-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
53 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 2 additions & 16 deletions
18
src/main/kotlin/com/muedsa/snapshot/widget/ParentDataWidget.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/test/kotlin/com/muedsa/snapshot/widget/FlexibleTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
} | ||
} | ||
} |