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
1 change: 1 addition & 0 deletions app/src/main/java/de/berlindroid/zepatch/Holzmesser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ import de.berlindroid.zepatch.generated.PatchRegistry
*/

// Generated via @Patch + KSP

val patchables = PatchRegistry.patchables
22 changes: 17 additions & 5 deletions app/src/main/java/de/berlindroid/zepatch/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private fun PatchableDetail(
modifier: Modifier = Modifier,
name: String,
onBackClick: () -> Unit,
patchable: @Composable () -> Unit,
patchable: @Composable (Boolean, (ImageBitmap) -> Unit) -> Unit,
) {
var imageBitmap by remember { mutableStateOf<ImageBitmap?>(null) }
var reducedImageBitmap by remember { mutableStateOf<ImageBitmap?>(null) }
Expand Down Expand Up @@ -245,12 +245,24 @@ private fun PatchableDetail(
name,
onBitmapUpdated = { imageBitmap = it },
onColorCountUpdated = { colorCount = it },
onReducedUpdated = { img, histo -> reducedImageBitmap = img;reducedHistogram = histo },
onEmbroideryUpdated = { data, preview -> embroideryData = data; embroideryPreviewImage = preview },
onReducedUpdated = { img, histo ->
reducedImageBitmap = img;reducedHistogram = histo
},
onEmbroideryUpdated = { data, preview ->
embroideryData = data
embroideryPreviewImage = preview
},
patchable
)

WizardButtons(currentMode, imageBitmap, reducedImageBitmap, embroideryData, name, launcher) {
WizardButtons(
currentMode,
imageBitmap,
reducedImageBitmap,
embroideryData,
name,
launcher
) {
currentMode = it
}
}
Expand All @@ -269,7 +281,7 @@ private fun WizardContent(
onColorCountUpdated: (Int) -> Unit,
onReducedUpdated: (ImageBitmap, Histogram) -> Unit,
onEmbroideryUpdated: (ByteArray, ImageBitmap) -> Unit,
patchable: @Composable (() -> Unit),
patchable: @Composable (Boolean, (ImageBitmap) -> Unit) -> Unit,
) {
Card(
modifier = Modifier
Expand Down
196 changes: 126 additions & 70 deletions app/src/main/java/de/berlindroid/zepatch/patchable/Demo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.ExperimentalMaterial3Api
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.res.painterResource
import androidx.compose.ui.text.TextStyle
Expand All @@ -29,12 +34,17 @@ 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() {
SafeArea {
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),
Expand All @@ -47,8 +57,14 @@ fun AppLogo() {
@OptIn(ExperimentalMaterial3Api::class)
@Patch("BerlindroidLogo")
@Composable
fun BerlindroidLogo() {
SafeArea {
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),
Expand All @@ -61,8 +77,14 @@ fun BerlindroidLogo() {
@OptIn(ExperimentalMaterial3Api::class)
@Patch("GoogleLogo")
@Composable
fun GoogleLogo() {
SafeArea {
fun GoogleLogo(
shouldCapture: Boolean = false,
onBitmap: (ImageBitmap) -> Unit = {},
) {
SafeArea(
shouldCapture = shouldCapture,
onBitmap = onBitmap,
) {
Image(
modifier = Modifier.size(200.dp),
painter = painterResource(R.drawable.g),
Expand All @@ -75,8 +97,14 @@ fun GoogleLogo() {
@OptIn(ExperimentalMaterial3Api::class)
@Patch("Android")
@Composable
fun AndroidLogo() {
SafeArea {
fun AndroidLogo(
shouldCapture: Boolean = false,
onBitmap: (ImageBitmap) -> Unit = {},
) {
SafeArea(
shouldCapture = shouldCapture,
onBitmap = onBitmap,
) {
Image(
modifier = Modifier.size(200.dp),
painter = painterResource(R.drawable.andriod),
Expand All @@ -88,69 +116,85 @@ fun AndroidLogo() {

@Patch("AndyA")
@Composable
fun AndyA() {
SafeArea(
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
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,
)
),
) {
Column(modifier = Modifier.fillMaxSize()) {
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 = "Andy",
)
Spacer(modifier = Modifier.weight(1f))
Spacer(modifier = Modifier.weight(1f))
}
}
TextField(value = name, onValueChange = { name = it })

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes this particular patch interactive so you can change the name on the patch. The part that will be converted is in the SafeArea. See the screenshot

}
}

@Patch("AndyB")
@Composable
fun AndyB() {
fun AndyB(
shouldCapture: Boolean = false,
onBitmap: (ImageBitmap) -> Unit = {},
) {
SafeArea(
modifier = Modifier
.size(200.dp)
.background(
color = Color.White,
shape = RoundedCornerShape(
topStartPercent = 0,
topEndPercent = 50,
bottomStartPercent = 50,
bottomEndPercent = 50
)
)
.border(
12.dp, Color.Black, RoundedCornerShape(
topStartPercent = 0,
topEndPercent = 50,
bottomStartPercent = 50,
bottomEndPercent = 50
)
),
shouldCapture = shouldCapture,
onBitmap = onBitmap,
) {
Column(modifier = Modifier.fillMaxSize()) {
Column(
modifier = Modifier
.size(200.dp)
.background(
color = Color.White,
shape = RoundedCornerShape(
topStartPercent = 0,
topEndPercent = 50,
bottomStartPercent = 50,
bottomEndPercent = 50
)
)
.border(
12.dp, Color.Black, RoundedCornerShape(
topStartPercent = 0,
topEndPercent = 50,
bottomStartPercent = 50,
bottomEndPercent = 50
)
),
) {
Spacer(modifier = Modifier.weight(1f))
Text(
modifier = Modifier.fillMaxWidth(),
Expand All @@ -161,7 +205,7 @@ fun AndyB() {
style = TextStyle.Default.copy(shadow = Shadow(blurRadius = 12f)),
color = Color.Black,
text = "Andy",
letterSpacing = -1.sp
letterSpacing = (-1).sp
)
Spacer(modifier = Modifier.weight(1f))
}
Expand All @@ -170,22 +214,34 @@ fun AndyB() {

@Patch("flex")
@Composable
fun Emoji() {
SafeArea {
fun Emoji(
shouldCapture: Boolean = false,
onBitmap: (ImageBitmap) -> Unit = {},
) {
SafeArea(
shouldCapture = shouldCapture,
onBitmap = onBitmap,
) {
Text("💪", fontSize = 48.sp)
}
}

@Patch("ROBOT")
@Composable
fun Emoji2() {
SafeArea {
fun Emoji2(
shouldCapture: Boolean = false,
onBitmap: (ImageBitmap) -> Unit = {},
) {
SafeArea(
shouldCapture = shouldCapture,
onBitmap = onBitmap,
) {
Text("🦾🤖\nHereWeGo", fontSize = 34.sp)
}
}

@Preview
@Composable
fun PreviewDemo() {
AndyB()
AndyA()
}
20 changes: 7 additions & 13 deletions app/src/main/java/de/berlindroid/zepatch/ui/PatchableToBitmap.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ImageBitmap
import de.berlindroid.zepatch.utils.CaptureToBitmap

/**
* Renders the provided [patchable] into a Bitmap-like [ImageBitmap] and displays it via [Image].
Expand All @@ -23,7 +22,7 @@ import de.berlindroid.zepatch.utils.CaptureToBitmap
fun PatchableToBitmap(
modifier: Modifier = Modifier,
onBitmap: (ImageBitmap) -> Unit = {},
patchable: @Composable () -> Unit,
patchable: @Composable (Boolean, (ImageBitmap) -> Unit) -> Unit,
) {
var image by remember { mutableStateOf<ImageBitmap?>(null) }
var shouldCapture by remember { mutableStateOf(false) }
Expand All @@ -33,16 +32,12 @@ fun PatchableToBitmap(
image = null
shouldCapture = true
}) { Text("Do it") }
// Compose the content through the composable utility; it will invoke the callback when ready.
CaptureToBitmap(
modifier = Modifier.fillMaxWidth(),
shouldCapture = shouldCapture,
onBitmap = { img ->
image = img
shouldCapture = false
},
content = patchable
)

// Render the patchable; it will capture via SafeArea when shouldCapture is true
patchable(shouldCapture) { img ->
image = img
shouldCapture = false
}

image?.let {
Image(
Expand All @@ -52,7 +47,6 @@ fun PatchableToBitmap(
)
onBitmap(it)
} ?: CircularProgressIndicator()

}
}

Expand Down
Loading