Skip to content

Commit c8f1ec6

Browse files
committed
Merge remote-tracking branch 'upstream/main' into feature/serhii-hrabas
# Conflicts: # app/src/main/java/de/berlindroid/zepatch/patchable/Demo.kt
2 parents a1b280a + f4b9a28 commit c8f1ec6

13 files changed

Lines changed: 439 additions & 360 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ A patchable is simply a Composable function annotated with @Patch that ZePatch c
2626
- The build’s KSP processor discovers it and adds it to a registry.
2727
- The app can render it to a bitmap and the converter turns that into a stitch format (e.g., PES) for embroidery.
2828

29-
See [examples](app/src/main/java/de/berlindroid/zepatch/patchable/Demo.kt)
29+
See [examples](app/src/main/java/de/berlindroid/zepatch/patchable)
3030

3131
In its simplest form, a patchable looks like this:
3232
```kotlin

app/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @gdg-berlin-android/ZeTeam
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package de.berlindroid.zepatch.patchable
2+
3+
import androidx.compose.foundation.Image
4+
import androidx.compose.foundation.layout.size
5+
import androidx.compose.material3.ExperimentalMaterial3Api
6+
import androidx.compose.runtime.Composable
7+
import androidx.compose.ui.Modifier
8+
import androidx.compose.ui.graphics.ImageBitmap
9+
import androidx.compose.ui.res.painterResource
10+
import androidx.compose.ui.unit.dp
11+
import de.berlindroid.zepatch.R
12+
import de.berlindroid.zepatch.annotations.Patch
13+
import de.berlindroid.zepatch.ui.SafeArea
14+
15+
@OptIn(ExperimentalMaterial3Api::class)
16+
@Patch("Android")
17+
@Composable
18+
fun AndroidLogo(
19+
shouldCapture: Boolean = false,
20+
onBitmap: (ImageBitmap) -> Unit = {},
21+
) {
22+
SafeArea(
23+
shouldCapture = shouldCapture,
24+
onBitmap = onBitmap,
25+
) {
26+
Image(
27+
modifier = Modifier.size(200.dp),
28+
painter = painterResource(R.drawable.andriod),
29+
contentDescription = null
30+
)
31+
}
32+
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
package de.berlindroid.zepatch.patchable
2+
3+
import androidx.compose.foundation.background
4+
import androidx.compose.foundation.layout.Column
5+
import androidx.compose.foundation.layout.Spacer
6+
import androidx.compose.foundation.layout.fillMaxWidth
7+
import androidx.compose.foundation.layout.size
8+
import androidx.compose.foundation.shape.RoundedCornerShape
9+
import androidx.compose.material3.Text
10+
import androidx.compose.material3.TextField
11+
import androidx.compose.runtime.Composable
12+
import androidx.compose.runtime.getValue
13+
import androidx.compose.runtime.mutableStateOf
14+
import androidx.compose.runtime.remember
15+
import androidx.compose.runtime.setValue
16+
import androidx.compose.ui.Modifier
17+
import androidx.compose.ui.graphics.Brush
18+
import androidx.compose.ui.graphics.Color
19+
import androidx.compose.ui.graphics.ImageBitmap
20+
import androidx.compose.ui.graphics.Shadow
21+
import androidx.compose.ui.text.TextStyle
22+
import androidx.compose.ui.text.font.FontFamily
23+
import androidx.compose.ui.text.font.FontStyle
24+
import androidx.compose.ui.text.font.FontWeight
25+
import androidx.compose.ui.text.style.TextAlign
26+
import androidx.compose.ui.tooling.preview.Preview
27+
import androidx.compose.ui.unit.dp
28+
import androidx.compose.ui.unit.sp
29+
import de.berlindroid.zepatch.annotations.Patch
30+
import de.berlindroid.zepatch.ui.SafeArea
31+
32+
@Patch("AndyA")
33+
@Composable
34+
fun AndyA(
35+
shouldCapture: Boolean = false,
36+
onBitmap: (ImageBitmap) -> Unit = {},
37+
) {
38+
var name by remember { mutableStateOf("Andy") }
39+
Column {
40+
SafeArea(
41+
shouldCapture = shouldCapture,
42+
onBitmap = onBitmap,
43+
) {
44+
Column(
45+
modifier = Modifier
46+
.size(200.dp)
47+
.background(
48+
brush = Brush.linearGradient(
49+
colors = listOf(
50+
Color.Red,
51+
Color.Yellow,
52+
Color.Green,
53+
Color.Blue,
54+
Color.Cyan
55+
)
56+
),
57+
shape = RoundedCornerShape(
58+
topStartPercent = 50,
59+
topEndPercent = 50,
60+
bottomStartPercent = 50,
61+
bottomEndPercent = 0
62+
)
63+
),
64+
) {
65+
Spacer(modifier = Modifier.weight(1f))
66+
Text(
67+
modifier = Modifier.fillMaxWidth(),
68+
fontFamily = FontFamily.Cursive,
69+
textAlign = TextAlign.Center,
70+
fontStyle = FontStyle.Italic,
71+
fontWeight = FontWeight.ExtraBold,
72+
fontSize = 70.sp,
73+
text = name,
74+
)
75+
Spacer(modifier = Modifier.weight(1f))
76+
}
77+
}
78+
TextField(value = name, onValueChange = { name = it })
79+
}
80+
}
81+
82+
@Patch("AndyB")
83+
@Composable
84+
fun AndyB(
85+
shouldCapture: Boolean = false,
86+
onBitmap: (ImageBitmap) -> Unit = {},
87+
) {
88+
SafeArea(
89+
shouldCapture = shouldCapture,
90+
onBitmap = onBitmap,
91+
) {
92+
Column(
93+
modifier = Modifier
94+
.size(200.dp)
95+
.background(
96+
color = Color.White,
97+
shape = RoundedCornerShape(
98+
topStartPercent = 0,
99+
topEndPercent = 50,
100+
bottomStartPercent = 50,
101+
bottomEndPercent = 0
102+
)
103+
),
104+
) {
105+
Spacer(modifier = Modifier.weight(1f))
106+
Text(
107+
modifier = Modifier.fillMaxWidth(),
108+
fontFamily = FontFamily.Cursive,
109+
textAlign = TextAlign.Center,
110+
fontWeight = FontWeight.ExtraBold,
111+
fontSize = 64.sp,
112+
style = TextStyle.Default.copy(shadow = Shadow(blurRadius = 12f)),
113+
color = Color.Black,
114+
text = "AndyB",
115+
letterSpacing = (-1).sp
116+
)
117+
Spacer(modifier = Modifier.weight(1f))
118+
}
119+
}
120+
}
121+
122+
@Preview
123+
@Composable
124+
fun PreviewAndyA() {
125+
AndyA()
126+
}
127+
128+
@Preview
129+
@Composable
130+
fun PreviewAndyB() {
131+
AndyB()
132+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package de.berlindroid.zepatch.patchable
2+
3+
import androidx.compose.foundation.Image
4+
import androidx.compose.foundation.layout.size
5+
import androidx.compose.material3.ExperimentalMaterial3Api
6+
import androidx.compose.runtime.Composable
7+
import androidx.compose.ui.Modifier
8+
import androidx.compose.ui.graphics.ImageBitmap
9+
import androidx.compose.ui.res.painterResource
10+
import androidx.compose.ui.unit.dp
11+
import de.berlindroid.zepatch.R
12+
import de.berlindroid.zepatch.annotations.Patch
13+
import de.berlindroid.zepatch.ui.SafeArea
14+
15+
@OptIn(ExperimentalMaterial3Api::class)
16+
@Patch("AppLogo")
17+
@Composable
18+
fun AppLogo(
19+
shouldCapture: Boolean = false,
20+
onBitmap: (ImageBitmap) -> Unit = {},
21+
) {
22+
SafeArea(
23+
shouldCapture = shouldCapture,
24+
onBitmap = onBitmap,
25+
) {
26+
Image(
27+
modifier = Modifier.size(200.dp),
28+
painter = painterResource(R.drawable.ai_logo),
29+
contentDescription = null
30+
)
31+
}
32+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package de.berlindroid.zepatch.patchable
2+
3+
import androidx.compose.foundation.Image
4+
import androidx.compose.foundation.layout.size
5+
import androidx.compose.material3.ExperimentalMaterial3Api
6+
import androidx.compose.runtime.Composable
7+
import androidx.compose.ui.Modifier
8+
import androidx.compose.ui.graphics.ImageBitmap
9+
import androidx.compose.ui.res.painterResource
10+
import androidx.compose.ui.tooling.preview.Preview
11+
import androidx.compose.ui.unit.dp
12+
import de.berlindroid.zepatch.R
13+
import de.berlindroid.zepatch.annotations.Patch
14+
import de.berlindroid.zepatch.ui.SafeArea
15+
16+
@OptIn(ExperimentalMaterial3Api::class)
17+
@Patch("BerlindroidLogo")
18+
@Composable
19+
fun BerlindroidLogo(
20+
shouldCapture: Boolean = false,
21+
onBitmap: (ImageBitmap) -> Unit = {},
22+
) {
23+
SafeArea(
24+
shouldCapture = shouldCapture,
25+
onBitmap = onBitmap,
26+
) {
27+
Image(
28+
modifier = Modifier.size(200.dp),
29+
painter = painterResource(R.drawable.voltron_nosign),
30+
contentDescription = null
31+
)
32+
}
33+
}
34+
35+
@Preview
36+
@Composable
37+
fun PreviewBerlindroid() {
38+
BerlindroidLogo()
39+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package de.berlindroid.zepatch.patchable
2+
3+
import androidx.compose.foundation.layout.size
4+
import androidx.compose.runtime.Composable
5+
import androidx.compose.ui.Modifier
6+
import androidx.compose.ui.graphics.ImageBitmap
7+
import androidx.compose.ui.tooling.preview.Preview
8+
import androidx.compose.ui.unit.dp
9+
import de.berlindroid.zepatch.annotations.Patch
10+
import de.berlindroid.zepatch.ui.SafeArea
11+
import dev.nstv.composablesheep.library.ComposableSheep
12+
import dev.nstv.composablesheep.library.model.Sheep
13+
import dev.nstv.composablesheep.library.util.SheepColor
14+
15+
@Preview
16+
@Patch("Composable Sheep")
17+
@Composable
18+
fun ComposableSheepPatchable(
19+
shouldCapture: Boolean = false, // used to activate the convert to bitmap
20+
onBitmap: (ImageBitmap) -> Unit = {}, // used to return the bitmap from the SafeArea
21+
) {
22+
SafeArea(
23+
shouldCapture = shouldCapture,
24+
onBitmap = onBitmap,
25+
) {
26+
ComposableSheep(
27+
sheep = Sheep(fluffColor = SheepColor.Green),
28+
modifier = Modifier.size(300.dp),
29+
)
30+
}
31+
}

0 commit comments

Comments
 (0)