Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ A patchable is simply a Composable function annotated with @Patch that ZePatch c
- The build’s KSP processor discovers it and adds it to a registry.
- The app can render it to a bitmap and the converter turns that into a stitch format (e.g., PES) for embroidery.

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

In its simplest form, a patchable looks like this:
```kotlin
Expand Down
32 changes: 32 additions & 0 deletions app/src/main/java/de/berlindroid/zepatch/patchable/AndroidLogo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package de.berlindroid.zepatch.patchable

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.size
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import de.berlindroid.zepatch.R
import de.berlindroid.zepatch.annotations.Patch
import de.berlindroid.zepatch.ui.SafeArea

@OptIn(ExperimentalMaterial3Api::class)
@Patch("Android")
@Composable
fun AndroidLogo(
shouldCapture: Boolean = false,
onBitmap: (ImageBitmap) -> Unit = {},
) {
SafeArea(
shouldCapture = shouldCapture,
onBitmap = onBitmap,
) {
Image(
modifier = Modifier.size(200.dp),
painter = painterResource(R.drawable.andriod),
contentDescription = null
)
}
}
132 changes: 132 additions & 0 deletions app/src/main/java/de/berlindroid/zepatch/patchable/Andy.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package de.berlindroid.zepatch.patchable

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.Shadow
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import de.berlindroid.zepatch.annotations.Patch
import de.berlindroid.zepatch.ui.SafeArea

@Patch("AndyA")
@Composable
fun AndyA(
shouldCapture: Boolean = false,
onBitmap: (ImageBitmap) -> Unit = {},
) {
var name by remember { mutableStateOf("Andy") }
Column {
SafeArea(
shouldCapture = shouldCapture,
onBitmap = onBitmap,
) {
Column(
modifier = Modifier
.size(200.dp)
.background(
brush = Brush.linearGradient(
colors = listOf(
Color.Red,
Color.Yellow,
Color.Green,
Color.Blue,
Color.Cyan
)
),
shape = RoundedCornerShape(
topStartPercent = 50,
topEndPercent = 50,
bottomStartPercent = 50,
bottomEndPercent = 0
)
),
) {
Spacer(modifier = Modifier.weight(1f))
Text(
modifier = Modifier.fillMaxWidth(),
fontFamily = FontFamily.Cursive,
textAlign = TextAlign.Center,
fontStyle = FontStyle.Italic,
fontWeight = FontWeight.ExtraBold,
fontSize = 70.sp,
text = name,
)
Spacer(modifier = Modifier.weight(1f))
}
}
TextField(value = name, onValueChange = { name = it })
}
}

@Patch("AndyB")
@Composable
fun AndyB(
shouldCapture: Boolean = false,
onBitmap: (ImageBitmap) -> Unit = {},
) {
SafeArea(
shouldCapture = shouldCapture,
onBitmap = onBitmap,
) {
Column(
modifier = Modifier
.size(200.dp)
.background(
color = Color.White,
shape = RoundedCornerShape(
topStartPercent = 0,
topEndPercent = 50,
bottomStartPercent = 50,
bottomEndPercent = 0
)
),
) {
Spacer(modifier = Modifier.weight(1f))
Text(
modifier = Modifier.fillMaxWidth(),
fontFamily = FontFamily.Cursive,
textAlign = TextAlign.Center,
fontWeight = FontWeight.ExtraBold,
fontSize = 64.sp,
style = TextStyle.Default.copy(shadow = Shadow(blurRadius = 12f)),
color = Color.Black,
text = "AndyB",
letterSpacing = (-1).sp
)
Spacer(modifier = Modifier.weight(1f))
}
}
}

@Preview
@Composable
fun PreviewAndyA() {
AndyA()
}

@Preview
@Composable
fun PreviewAndyB() {
AndyB()
}
32 changes: 32 additions & 0 deletions app/src/main/java/de/berlindroid/zepatch/patchable/AppLogo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package de.berlindroid.zepatch.patchable

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.size
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import de.berlindroid.zepatch.R
import de.berlindroid.zepatch.annotations.Patch
import de.berlindroid.zepatch.ui.SafeArea

@OptIn(ExperimentalMaterial3Api::class)
@Patch("AppLogo")
@Composable
fun AppLogo(
shouldCapture: Boolean = false,
onBitmap: (ImageBitmap) -> Unit = {},
) {
SafeArea(
shouldCapture = shouldCapture,
onBitmap = onBitmap,
) {
Image(
modifier = Modifier.size(200.dp),
painter = painterResource(R.drawable.ai_logo),
contentDescription = null
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package de.berlindroid.zepatch.patchable

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.size
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import de.berlindroid.zepatch.R
import de.berlindroid.zepatch.annotations.Patch
import de.berlindroid.zepatch.ui.SafeArea

@OptIn(ExperimentalMaterial3Api::class)
@Patch("BerlindroidLogo")
@Composable
fun BerlindroidLogo(
shouldCapture: Boolean = false,
onBitmap: (ImageBitmap) -> Unit = {},
) {
SafeArea(
shouldCapture = shouldCapture,
onBitmap = onBitmap,
) {
Image(
modifier = Modifier.size(200.dp),
painter = painterResource(R.drawable.voltron_nosign),
contentDescription = null
)
}
}

@Preview
@Composable
fun PreviewBerlindroid() {
BerlindroidLogo()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package de.berlindroid.zepatch.patchable

import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import de.berlindroid.zepatch.annotations.Patch
import de.berlindroid.zepatch.ui.SafeArea
import dev.nstv.composablesheep.library.ComposableSheep
import dev.nstv.composablesheep.library.model.Sheep
import dev.nstv.composablesheep.library.util.SheepColor

@Preview
@Patch("Composable Sheep")
@Composable
fun ComposableSheepPatchable(
shouldCapture: Boolean = false, // used to activate the convert to bitmap
onBitmap: (ImageBitmap) -> Unit = {}, // used to return the bitmap from the SafeArea
) {
SafeArea(
shouldCapture = shouldCapture,
onBitmap = onBitmap,
) {
ComposableSheep(
sheep = Sheep(fluffColor = SheepColor.Green),
modifier = Modifier.size(300.dp),
)
}
}
Loading