Skip to content

Commit

Permalink
FadingLazy moved to Components
Browse files Browse the repository at this point in the history
Random Cleanup
  • Loading branch information
baec23 committed Dec 16, 2023
1 parent 1af80de commit bee0611
Show file tree
Hide file tree
Showing 13 changed files with 205 additions and 195 deletions.
4 changes: 3 additions & 1 deletion app/src/main/java/com/baec23/ludwig/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import com.baec23.ludwig.ui.MorpherSample
import com.baec23.ludwig.ui.TestScreen2
import com.baec23.ludwig.ui.theme.LudwigTheme

Expand All @@ -21,7 +22,8 @@ class MainActivity : ComponentActivity() {
.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
TestScreen2()
MorpherSample()
// TestScreen2()
// Column(
// modifier = Modifier
// .fillMaxWidth()
Expand Down
51 changes: 51 additions & 0 deletions app/src/main/java/com/baec23/ludwig/ui/MorpherSample.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.baec23.ludwig.ui

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Star
import androidx.compose.material3.Button
import androidx.compose.material3.Text
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.unit.dp
import com.baec23.ludwig.morpher.component.AnimatedVector
import com.baec23.ludwig.morpher.model.morpher.VectorSource

@Composable
fun MorpherSample() {
val vectorSource1 = VectorSource.fromImageVector(Icons.Outlined.Star)
val vectorSource2 =
VectorSource.fromPathString("m256-200-56-56 224-224-224-224 56-56 224 224 224-224 56 56-224 224 224 224-56 56-224-224-224 224Z")
var selectedVectorSource by remember { mutableStateOf(vectorSource1) }

Column(
modifier = Modifier.fillMaxWidth()
) {
AnimatedVector(
modifier = Modifier
.fillMaxWidth()
.aspectRatio(1f),
vectorSource = selectedVectorSource,
)
Row(modifier = Modifier.fillMaxWidth()) {
Button(
modifier = Modifier.weight(1f),
onClick = { selectedVectorSource = vectorSource1 }) {
Text(text = "Source 1")
}
Button(
modifier = Modifier.weight(1f),
onClick = { selectedVectorSource = vectorSource2 }) {
Text(text = "Source 2")
}
}
}
}
67 changes: 0 additions & 67 deletions app/src/main/java/com/baec23/ludwig/ui/ScalingCanvas.kt

This file was deleted.

142 changes: 55 additions & 87 deletions app/src/main/java/com/baec23/ludwig/ui/TestScreen2.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package com.baec23.ludwig.ui

import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.EaseInOutExpo
import androidx.compose.animation.core.RepeatMode
import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
Expand All @@ -19,34 +17,31 @@ import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material.icons.filled.Star
import androidx.compose.material.icons.outlined.Create
import androidx.compose.material.icons.outlined.Face
import androidx.compose.material.icons.outlined.Home
import androidx.compose.material.icons.outlined.Refresh
import androidx.compose.material.icons.outlined.ShoppingCart
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.Fill
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.unit.dp
import com.baec23.ludwig.R
import com.baec23.ludwig.core.fadingLazy.FadingLazyVerticalGrid
import com.baec23.ludwig.morpher.component.AnimatedMorphVector
import com.baec23.ludwig.component.section.DisplaySection
import com.baec23.ludwig.component.fadinglazy.FadingLazyVerticalGrid
import com.baec23.ludwig.morpher.component.AnimatedVector
import com.baec23.ludwig.morpher.component.VectorImage
import com.baec23.ludwig.morpher.model.morpher.VectorSource
import kotlinx.coroutines.launch


@Composable
Expand Down Expand Up @@ -84,111 +79,84 @@ fun TestScreen2() {
val shoppingCartVectorSource = VectorSource.fromImageVector(Icons.Outlined.ShoppingCart)
val createVectorSource = VectorSource.fromImageVector(Icons.Outlined.Create)
val settingsVectorSource = VectorSource.fromImageVector(Icons.Default.Settings)
val yinYangVectorSource = VectorSource.fromImageVector(ImageVector.vectorResource(R.drawable.yinyang))
val cloverVectorSource = VectorSource.fromImageVector(ImageVector.vectorResource(R.drawable.clover))
val worldLoveVectorSource = VectorSource.fromImageVector(ImageVector.vectorResource(R.drawable.worldlove))
val yinYangVectorSource =
VectorSource.fromImageVector(ImageVector.vectorResource(R.drawable.yinyang))
val cloverVectorSource =
VectorSource.fromImageVector(ImageVector.vectorResource(R.drawable.clover))
val worldLoveVectorSource =
VectorSource.fromImageVector(ImageVector.vectorResource(R.drawable.worldlove))
val fireVectorSource = VectorSource.fromImageVector(ImageVector.vectorResource(R.drawable.fire))
val diamondVectorSource = VectorSource.fromImageVector(ImageVector.vectorResource(R.drawable.diamond))
val helloBubbleVectorSource = VectorSource.fromImageVector(ImageVector.vectorResource(R.drawable.hellobubble))
val diamondVectorSource =
VectorSource.fromImageVector(ImageVector.vectorResource(R.drawable.diamond))
val helloBubbleVectorSource =
VectorSource.fromImageVector(ImageVector.vectorResource(R.drawable.hellobubble))


val targetVectors: List<VectorSource> = listOf(
androidVectorSource,
// redditVectorSource,
// androidVectorSource,
appleVectorSource,
firefoxVectorSource,
slackVectorSource,
youtubeVectorSource,
instagramVectorSource,
paypalVectorSource,
skypeVectorSource,
slackVectorSource,
pinterestVectorSource,
snapchatVectorSource,
twitterVectorSource,
fireVectorSource,
diamondVectorSource,
flowerVectorSource,
refreshVectorSource,
faceVectorSource,
shoppingCartVectorSource,
createVectorSource,
yinYangVectorSource,
settingsVectorSource,
cloverVectorSource,
yinYangVectorSource,
worldLoveVectorSource,
)

val animationProgress = remember {
Animatable(0f)
}

// LaunchedEffect(Unit) {
// animationProgress.animateTo(
// 1f,
// animationSpec = infiniteRepeatable(
// tween(
// durationMillis = 1000,
// easing = EaseInOutExpo
// ), RepeatMode.Reverse
// )
// )
// }

var currStartSource by remember { mutableStateOf(androidVectorSource) }
var currEndSource by remember { mutableStateOf(flowerVectorSource) }
val coroutineScope = rememberCoroutineScope()
var currSelectedSource by remember { mutableStateOf(appleVectorSource) }

Column(modifier = Modifier.fillMaxSize()) {
Column(
modifier = Modifier
.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally
modifier = Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally
) {
AnimatedMorphVector(
AnimatedVector(
modifier = Modifier
.fillMaxWidth()
.aspectRatio(1f)
.padding(36.dp),
startSource = currStartSource,
endSource = currEndSource,
progress = animationProgress.value,
strokeWidth = 20f,
strokeColor = Color.Black,
animationSmoothness = 200
vectorSource = currSelectedSource,
strokeWidth = 30f,
animationSpec = tween(durationMillis = 800, easing = EaseInOutExpo)
)
}
FadingLazyVerticalGrid(
columns = GridCells.Adaptive(minSize = 75.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp)
DisplaySection(
modifier = Modifier.padding(horizontal = 8.dp),
headerText = "Controls",
contentPadding = PaddingValues(16.dp),
headerIcon = Icons.Default.Star
) {
items(targetVectors) {
Box(
modifier = Modifier
FadingLazyVerticalGrid(
columns = GridCells.Adaptive(minSize = 100.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
gradientHeightPercent = 0.2f
) {
items(targetVectors) {
Box(modifier = Modifier
.aspectRatio(1f)
.clip(CircleShape)
.background(color = Color.LightGray)
.clickable(enabled = !animationProgress.isRunning) {
if(animationProgress.value == 0f){
currEndSource = it
coroutineScope.launch {
animationProgress.animateTo(targetValue = 1f, animationSpec = tween(durationMillis = 1000, easing = EaseInOutExpo))
}
}else{
currStartSource = it
coroutineScope.launch {
animationProgress.animateTo(targetValue = 0f, animationSpec = tween(durationMillis = 1000, easing = EaseInOutExpo))
}
}
.alpha(if (currSelectedSource == it) 1f else 0.5f)
.border(
width = if (currSelectedSource == it) 6.dp else 2.dp,
color = Color.Black,
shape = CircleShape
)
.clickable() {
currSelectedSource = it
}
.padding(12.dp)
)
{
VectorImage(
modifier = Modifier
.aspectRatio(1f),
source = it,
style = Stroke(width = 5f)
)
.padding(24.dp)) {
VectorImage(
modifier = Modifier.aspectRatio(1f),
source = it,
style = Stroke(width = 5f)
)
}
}
}
}
Expand Down
Loading

0 comments on commit bee0611

Please sign in to comment.