ProCraft for Android: An Android native painting app written in Rust
Rust
feat(gallery): About from the app's name; a Blank grain first in the source library
Josh0d2b746422ad
diff --git a/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/canvas/CanvasViewModel.kt b/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/canvas/CanvasViewModel.ktindex 2dab810..4901726 100644--- a/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/canvas/CanvasViewModel.kt+++ b/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/canvas/CanvasViewModel.kt@@ -3262,6 +3262,9 @@ class CanvasViewModel(app: Application) : AndroidViewModel(app) {return Bitmap.createBitmap(argb, n, n, Bitmap.Config.ARGB_8888).asImageBitmap()}+ /** Library image [index]'s place among the shipped images: none for the grains' Blank, which isn't one. */+ fun shippedOf(grain: Boolean, index: Int): Int? = if (grain) (index - 1).takeIf { it >= 0 } else index+/** Shipped image [index] of the source library. */fun librarySource(grain: Boolean, index: Int): ByteArray =io.github.artcraftandroid.procraft.core.sourceLibrary(grain).getOrNull(index)?.pixels ?: ByteArray(0)diff --git a/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/ui/GalleryScreen.kt b/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/ui/GalleryScreen.ktindex 41de9ba..6d9238b 100644--- a/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/ui/GalleryScreen.kt+++ b/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/ui/GalleryScreen.kt@@ -125,6 +125,8 @@ fun GalleryScreen(vm: CanvasViewModel) {// where each stack's cell is (window pixels), for its artworks to fly out of as it opensval stackCellAt = remember { mutableMapOf<String, androidx.compose.ui.geometry.Rect>() }var renaming by remember { mutableStateOf<Artwork?>(null) }+ // the app's name tapped: what it is and its version, over the gallery+ var about by remember { mutableStateOf(false) }var deleting by remember { mutableStateOf<Artwork?>(null) }// the artwork (by folder) whose actions a swipe left is showingvar swiped by remember { mutableStateOf<String?>(null) }@@ -159,8 +161,8 @@ fun GalleryScreen(vm: CanvasViewModel) {vm.windowPx = androidx.compose.ui.unit.IntSize(constraints.maxWidth, constraints.maxHeight)// out of focus while an artwork is being renamedval blur by androidx.compose.animation.core.animateDpAsState(- if (renaming != null) RenameBlur else 0.dp,- if (renaming != null) tween(300) else tween(150),+ if (renaming != null || about) RenameBlur else 0.dp,+ if (renaming != null || about) tween(300) else tween(150),label = "blur",)Column(Modifier.fillMaxSize().then(if (blur > 0.dp) Modifier.blur(blur) else Modifier)) {@@ -189,6 +191,7 @@ fun GalleryScreen(vm: CanvasViewModel) {GalleryHeader(stack = vm.openStack?.name,onBack = { vm.showStack(null) },+ onAbout = { about = true },onSelect = { selecting = true },onNew = { newCanvas = !newCanvas },onImport = { importFile.launch(arrayOf("*/*")) },@@ -483,6 +486,11 @@ fun GalleryScreen(vm: CanvasViewModel) {.background(Pc.Panel).padding(horizontal = 18.dp, vertical = 12.dp),)}+ androidx.compose.animation.AnimatedVisibility(+ about,+ enter = androidx.compose.animation.fadeIn(tween(300)),+ exit = androidx.compose.animation.fadeOut(tween(150)),+ ) { AboutApp { about = false } }}// deleting the picked artworks, or one swiped to@@ -515,7 +523,7 @@ fun GalleryScreen(vm: CanvasViewModel) {/** The title row: the app's name, the select/import/photo capsule and the new-canvas button. */@Composable-private fun GalleryHeader(stack: String?, onBack: () -> Unit, onSelect: () -> Unit, onNew: () -> Unit, onImport: () -> Unit, onPhoto: () -> Unit) {+private fun GalleryHeader(stack: String?, onBack: () -> Unit, onAbout: () -> Unit, onSelect: () -> Unit, onNew: () -> Unit, onImport: () -> Unit, onPhoto: () -> Unit) {Box(Modifier.fillMaxWidth().height(55.dp)) {// into a stack the title changes at once; back out, the stack's name fades out as the// gallery's fades in@@ -557,7 +565,8 @@ private fun GalleryHeader(stack: String?, onBack: () -> Unit, onSelect: () -> Uncolor = Pc.GalleryTitle,fontSize = 36.sp,fontWeight = FontWeight.Bold,- modifier = Modifier.padding(start = 32.dp, top = 11.dp),+ modifier = Modifier.padding(start = 32.dp, top = 11.dp)+ .clickable(remember { androidx.compose.foundation.interaction.MutableInteractionSource() }, indication = null, onClick = onAbout),)}}@@ -1130,3 +1139,51 @@ private fun Chip(text: String, modifier: Modifier = Modifier) {Text(text, color = Pc.LightText, fontSize = 13.sp, maxLines = 1)}}++/**+ * What the app is, over the gallery (blurred and dimmed under it): its icon 300 across, its name,+ * its version; a round button at the top right closes it, as back does.+ */+@Composable+private fun AboutApp(onClose: () -> Unit) {+ BackHandler(onBack = onClose)+ val context = androidx.compose.ui.platform.LocalContext.current+ val version = remember {+ runCatching {+ val info = context.packageManager.getPackageInfo(context.packageName, 0)+ "Version ${info.versionName} Build ${androidx.core.content.pm.PackageInfoCompat.getLongVersionCode(info)}"+ }.getOrDefault("")+ }+ Box(Modifier.fillMaxSize().background(AboutVeil).pointerInput(Unit) { awaitEachGesture { awaitFirstDown().consume() } }) {+ Column(Modifier.fillMaxWidth().padding(top = 95.dp), horizontalAlignment = Alignment.CenterHorizontally) {+ // the launcher icon: its field, and its picture drawn at the adaptive icon's full size+ Box(Modifier.size(300.dp).clip(RoundedCornerShape(67.dp)).background(AboutIconField), contentAlignment = Alignment.Center) {+ androidx.compose.foundation.Image(+ androidx.compose.ui.res.painterResource(io.github.artcraftandroid.procraft.R.drawable.ic_launcher_foreground),+ contentDescription = null,+ modifier = Modifier.requiredSize(450.dp),+ )+ }+ Text("ProCraft", color = Color.White, fontSize = 64.sp, fontWeight = FontWeight.Bold, maxLines = 1, modifier = Modifier.padding(top = 12.dp))+ Text(version, color = AboutInk, fontSize = 13.sp, maxLines = 1, modifier = Modifier.padding(top = 14.dp))+ }+ Box(+ Modifier.align(Alignment.TopEnd).padding(top = 31.dp, end = 31.5.dp).size(22.5.dp).clip(CircleShape).background(AboutClose)+ .clickable(onClick = onClose),+ contentAlignment = Alignment.Center,+ ) {+ androidx.compose.foundation.Canvas(Modifier.size(8.dp)) {+ val w = 1.8.dp.toPx()+ drawLine(AboutCloseInk, androidx.compose.ui.geometry.Offset.Zero, androidx.compose.ui.geometry.Offset(size.width, size.height), w, cap = androidx.compose.ui.graphics.StrokeCap.Round)+ drawLine(AboutCloseInk, androidx.compose.ui.geometry.Offset(size.width, 0f), androidx.compose.ui.geometry.Offset(0f, size.height), w, cap = androidx.compose.ui.graphics.StrokeCap.Round)+ }+ }+ }+}++// as measured: the gallery under a near-black veil, the light round close button+private val AboutVeil = Color(0xD90B0B0B)+private val AboutIconField = Color(0xFF1C1C1E)+private val AboutInk = Color(0xFFBDBDBD)+private val AboutClose = Color(0xFFE3E3E3)+private val AboutCloseInk = Color(0xFF1C1C1C)diff --git a/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/ui/SourceEditorUi.kt b/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/ui/SourceEditorUi.ktindex 2b92508..d7ce7ed 100644--- a/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/ui/SourceEditorUi.kt+++ b/apps/procraft-android/android/app/src/main/java/io/github/artcraftandroid/procraft/ui/SourceEditorUi.kt@@ -199,7 +199,7 @@ fun SourceEditor(vm: CanvasViewModel) {)if (library) SourceLibrary(vm, grain, onPick = { i ->image = vm.librarySource(grain, i)- shipped = i+ shipped = vm.shippedOf(grain, i)library = false}) { library = false }}diff --git a/apps/procraft-android/src/studio.rs b/apps/procraft-android/src/studio.rsindex 8829bdb..f907436 100644--- a/apps/procraft-android/src/studio.rs+++ b/apps/procraft-android/src/studio.rs@@ -30,11 +30,20 @@ pub struct SourceImage {pub pixels: Vec<u8>,}-/// The shipped shape images (or, `grain`, grain images), in order: the source library.+/// The shipped shape images (or, `grain`, grain images after a blank one), in order: the source+/// library.#[uniffi::export]pub fn source_library(grain: bool) -> Vec<SourceImage> {let images = if grain { textures::grains() } else { textures::shapes() };- images.into_iter().map(|i| SourceImage { name: i.name.to_owned(), pixels: i.pixels }).collect()+ // the grains start with a blank one: plain white, no texture+ let blank = grain.then(|| SourceImage {+ name: "Blank".to_owned(),+ pixels: vec![255; textures::TEXTURE_SIZE * textures::TEXTURE_SIZE],+ });+ blank+ .into_iter()+ .chain(images.into_iter().map(|i| SourceImage { name: i.name.to_owned(), pixels: i.pixels }))+ .collect()}/// `pixels` (a `source_size` square greyscale image) made to repeat without seams: the graindiff --git a/apps/procraft-android/src/tests.rs b/apps/procraft-android/src/tests.rsindex 1f1ea8d..1fab8d8 100644--- a/apps/procraft-android/src/tests.rs+++ b/apps/procraft-android/src/tests.rs@@ -1704,7 +1704,10 @@ fn a_brush_paints_with_a_shape_of_the_users_own_and_keeps_it() {// a shipped shape againassert!(t.set_studio_shipped_source(crate::studio::SourceKind::Shape, 0));assert_ne!(t.studio_source(crate::studio::SourceKind::Shape), vec![255; n * n]);- assert_eq!(crate::studio::source_library(true).len(), procraft_engine::textures::grains().len());+ // the grains' library starts with the Blank, which isn't a shipped grain+ let library = crate::studio::source_library(true);+ assert_eq!(library.len(), procraft_engine::textures::grains().len() + 1);+ assert!(library.first().is_some_and(|b| b.name == "Blank" && b.pixels.iter().all(|&v| v == 255)));}#[test]