-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract ImageVectorPreviewPanel as reusable component
- Loading branch information
Showing
9 changed files
with
262 additions
and
262 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
components/ir/src/main/kotlin/io/github/composegears/valkyrie/ir/Stub.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package io.git.luolix.topposegears.valkyrie.ir | ||
|
||
val IR_STUB = IrImageVector( | ||
name = "", | ||
defaultWidth = 24.0f, | ||
defaultHeight = 24.0f, | ||
viewportWidth = 18.0f, | ||
viewportHeight = 18.0f, | ||
nodes = emptyList(), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 0 additions & 146 deletions
146
...ugin/src/main/kotlin/io/github/composegears/valkyrie/editor/ui/ImageVectorPreviewPanel.kt
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
...lugin/src/main/kotlin/io/github/composegears/valkyrie/editor/ui/VirtualFileImageVector.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
@file:Suppress("NAME_SHADOWING") | ||
|
||
package io.git.luolix.topposegears.valkyrie.editor.ui | ||
|
||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.produceState | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import com.intellij.openapi.application.readAction | ||
import com.intellij.openapi.vfs.VirtualFile | ||
import io.git.luolix.topposegears.valkyrie.editor.toKtFile | ||
import io.git.luolix.topposegears.valkyrie.ir.IrImageVector | ||
import io.git.luolix.topposegears.valkyrie.psi.imagevector.ImageVectorPsiParser | ||
import io.git.luolix.topposegears.valkyrie.ui.foundation.components.previewer.ImageVectorPreviewPanel | ||
import io.git.luolix.topposegears.valkyrie.ui.foundation.rememberMutableState | ||
import io.git.luolix.topposegears.valkyrie.ui.foundation.theme.LocalProject | ||
import org.jetbrains.kotlin.psi.KtFile | ||
|
||
@Composable | ||
fun VirtualFileImageVector( | ||
file: VirtualFile, | ||
modifier: Modifier = Modifier, | ||
) { | ||
val project = LocalProject.current | ||
|
||
var irImageVector by rememberMutableState<IrImageVector?> { null } | ||
var isPreparing by rememberMutableState { true } | ||
|
||
val ktFile by produceState<KtFile?>(null) { | ||
value = readAction { | ||
file.toKtFile(project) | ||
} | ||
} | ||
|
||
LaunchedEffect(ktFile) { | ||
val ktFile = ktFile ?: return@LaunchedEffect | ||
|
||
readAction { | ||
isPreparing = true | ||
irImageVector = ImageVectorPsiParser.parseToIrImageVector(ktFile) | ||
isPreparing = false | ||
} | ||
} | ||
|
||
if (!isPreparing) { | ||
ImageVectorPreviewPanel( | ||
modifier = modifier.fillMaxSize(), | ||
irImageVector = irImageVector, | ||
) | ||
} | ||
} |
111 changes: 0 additions & 111 deletions
111
...src/main/kotlin/io/github/composegears/valkyrie/editor/ui/previewer/ImageVectorPreview.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.