Skip to content

Commit d93663f

Browse files
committed
Add Column and Row and update :demo
1 parent 44bee3a commit d93663f

File tree

10 files changed

+122
-21
lines changed

10 files changed

+122
-21
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.huanshankeji.compose.layout
2+
3+
import androidx.compose.runtime.Composable
4+
import com.huanshankeji.compose.ui.Element
5+
import com.huanshankeji.compose.ui.ModifierOrAttrs
6+
7+
expect abstract class ColumnElement : Element
8+
expect interface ColumnScope
9+
10+
@Composable
11+
expect fun Column(modifierOrAttrs: ModifierOrAttrs<ColumnElement> = null, content: @Composable ColumnScope.() -> Unit)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.huanshankeji.compose.layout
2+
3+
import androidx.compose.runtime.Composable
4+
import com.huanshankeji.compose.ui.Element
5+
import com.huanshankeji.compose.ui.ModifierOrAttrs
6+
7+
expect abstract class RowElement : Element
8+
expect interface RowScope
9+
10+
@Composable
11+
expect fun Row(modifierOrAttrs: ModifierOrAttrs<RowElement> = null, content: @Composable RowScope.() -> Unit)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.huanshankeji.compose.layout
2+
3+
import androidx.compose.runtime.Composable
4+
import com.huanshankeji.compose.ui.ModifierOrAttrs
5+
import org.jetbrains.compose.web.dom.ElementScope
6+
import org.w3c.dom.HTMLDivElement
7+
8+
actual typealias ColumnElement = HTMLDivElement
9+
10+
actual interface ColumnScope {
11+
val elementScope: ElementScope<HTMLDivElement>
12+
13+
class Impl(override val elementScope: ElementScope<HTMLDivElement>) : ColumnScope
14+
}
15+
16+
@Composable
17+
actual fun Column(modifierOrAttrs: ModifierOrAttrs<ColumnElement>, content: @Composable ColumnScope.() -> Unit) =
18+
// TODO: `modifierOrAttrs` not used yet
19+
com.huanshankeji.compose.web.Column {
20+
ColumnScope.Impl(this).content()
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.huanshankeji.compose.layout
2+
3+
import androidx.compose.runtime.Composable
4+
import com.huanshankeji.compose.ui.ModifierOrAttrs
5+
import org.jetbrains.compose.web.dom.ElementScope
6+
import org.w3c.dom.HTMLDivElement
7+
8+
actual typealias RowElement = HTMLDivElement
9+
10+
actual interface RowScope {
11+
val elementScope: ElementScope<HTMLDivElement>
12+
13+
class Impl(override val elementScope: ElementScope<HTMLDivElement>) : RowScope
14+
}
15+
16+
@Composable
17+
actual fun Row(modifierOrAttrs: ModifierOrAttrs<RowElement>, content: @Composable RowScope.() -> Unit) =
18+
// TODO: `modifierOrAttrs` not used yet
19+
com.huanshankeji.compose.web.Row {
20+
RowScope.Impl(this).content()
21+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.huanshankeji.compose.layout
2+
3+
import androidx.compose.runtime.Composable
4+
import com.huanshankeji.compose.ui.Element
5+
import com.huanshankeji.compose.ui.ModifierOrAttrs
6+
import com.huanshankeji.compose.ui.toModifier
7+
8+
9+
actual abstract class ColumnElement : Element()
10+
actual typealias ColumnScope = androidx.compose.foundation.layout.ColumnScope
11+
12+
@Composable
13+
actual fun Column(modifierOrAttrs: ModifierOrAttrs<ColumnElement>, content: @Composable ColumnScope.() -> Unit) =
14+
androidx.compose.foundation.layout.Column(modifierOrAttrs.toModifier(), content = content)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.huanshankeji.compose.layout
2+
3+
import androidx.compose.runtime.Composable
4+
import com.huanshankeji.compose.ui.Element
5+
import com.huanshankeji.compose.ui.ModifierOrAttrs
6+
import com.huanshankeji.compose.ui.toModifier
7+
8+
actual abstract class RowElement : Element()
9+
actual typealias RowScope = androidx.compose.foundation.layout.RowScope
10+
11+
@Composable
12+
actual fun Row(modifierOrAttrs: ModifierOrAttrs<RowElement>, content: @Composable RowScope.() -> Unit) =
13+
androidx.compose.foundation.layout.Row(modifierOrAttrs.toModifier(), content = content)

demo/src/commonMain/kotlin/com/huanshankeji/compose/material/demo/Composables.kt

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package com.huanshankeji.compose.material.demo
33
import androidx.compose.runtime.*
44
import com.huanshankeji.compose.BasicText
55
import com.huanshankeji.compose.layout.Box
6+
import com.huanshankeji.compose.layout.Column
7+
import com.huanshankeji.compose.layout.Row
68
import com.huanshankeji.compose.material.*
79
import com.huanshankeji.compose.material.icon.MaterialIcons
810
import com.huanshankeji.compose.ui.unit.dpOrPx
@@ -16,38 +18,46 @@ fun App() {
1618
}, {
1719
MaterialIconActionButton({}, MaterialIcons.Search, "search")
1820
}) {
19-
Card {
20-
Box({
21-
style {
22-
padding(16.dpOrPx)
23-
}
24-
}) {
21+
Card({
22+
style {
23+
padding(16.dpOrPx)
24+
}
25+
}) {
26+
Column {
2527
BasicText("basic text")
2628
Text("Material text")
2729

2830
var count by remember { mutableStateOf(0) }
2931
val onClick: () -> Unit = { count++ }
30-
Button(onClick) {
31-
Label(count.toString())
32-
}
33-
34-
IconButton(onClick, materialIcon = MaterialIcons.Search, contentDescription = "increment count")
3532

36-
List {
37-
item {
38-
Text("Ungrouped item")
33+
Row {
34+
Button(onClick) {
35+
Label(count.toString())
3936
}
40-
items(count) {
41-
Text("Ungrouped item $it/$count")
37+
IconButton(onClick, materialIcon = MaterialIcons.Search, contentDescription = "increment count")
38+
}
39+
40+
Box({
41+
style {
42+
padding(16.dpOrPx)
4243
}
43-
group(headerContent = {
44-
Text("Group title")
45-
}) {
44+
}) {
45+
List {
4646
item {
47-
Text("Grouped item")
47+
Text("Ungrouped item")
4848
}
4949
items(count) {
50-
Text("Grouped item $it/$count")
50+
Text("Ungrouped item $it/$count")
51+
}
52+
group(headerContent = {
53+
Text("Group title")
54+
}) {
55+
item {
56+
Text("Grouped item")
57+
}
58+
items(count) {
59+
Text("Grouped item $it/$count")
60+
}
5161
}
5262
}
5363
}

0 commit comments

Comments
 (0)