diff --git a/apps/documentViewer/build.gradle.kts b/apps/documentViewer/build.gradle.kts index 2936fdc..87c9a51 100644 --- a/apps/documentViewer/build.gradle.kts +++ b/apps/documentViewer/build.gradle.kts @@ -2,9 +2,14 @@ plugins { id("org.jetbrains.compose") version "1.5.11" } +repositories { + google() +} + dependencies { implementation("org.pushing-pixels:aurora-theming:1.3.0") implementation("org.pushing-pixels:aurora-component:1.3.0") implementation("org.pushing-pixels:aurora-window:1.3.0") implementation(compose.desktop.currentOs) + implementation("io.github.panpf.zoomimage:zoomimage-compose:1.0.0-beta11") } \ No newline at end of file diff --git a/apps/documentViewer/src/main/kotlin/de/itkl/documentViewer/DocumentViewer.kt b/apps/documentViewer/src/main/kotlin/de/itkl/documentViewer/DocumentViewer.kt index 5f84ded..b3a6e24 100644 --- a/apps/documentViewer/src/main/kotlin/de/itkl/documentViewer/DocumentViewer.kt +++ b/apps/documentViewer/src/main/kotlin/de/itkl/documentViewer/DocumentViewer.kt @@ -1,20 +1,32 @@ package de.itkl.documentViewer +import androidx.compose.foundation.Image import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue +import androidx.compose.foundation.layout.width +import androidx.compose.runtime.* import androidx.compose.ui.text.ExperimentalTextApi import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.ImageBitmap +import androidx.compose.ui.graphics.painter.BitmapPainter +import androidx.compose.ui.graphics.painter.Painter +import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.res.loadImageBitmap +import androidx.compose.ui.res.painterResource import androidx.compose.ui.unit.DpSize import androidx.compose.ui.unit.dp import androidx.compose.ui.window.WindowPlacement import androidx.compose.ui.window.WindowPosition import androidx.compose.ui.window.rememberWindowState +import com.github.panpf.zoomimage.ZoomImage +import com.github.panpf.zoomimage.compose.ZoomState +import com.github.panpf.zoomimage.compose.rememberZoomState +import com.github.panpf.zoomimage.compose.subsampling.fromResource +import com.github.panpf.zoomimage.subsampling.ImageSource +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext import org.pushingpixels.aurora.component.model.Command import org.pushingpixels.aurora.component.projection.CommandButtonProjection import org.pushingpixels.aurora.theming.auroraBackground @@ -22,6 +34,9 @@ import org.pushingpixels.aurora.theming.marinerSkin import org.pushingpixels.aurora.window.AuroraWindow import org.pushingpixels.aurora.window.AuroraWindowTitlePaneConfigurations import org.pushingpixels.aurora.window.auroraApplication +import java.io.File +import java.io.IOException +import java.nio.file.Paths class DocumentViewer { } @@ -36,7 +51,7 @@ fun main() = auroraApplication { AuroraWindow( skin = marinerSkin(), - title = "Aurora Demo", + title = "Document Viewer", state = state, windowTitlePaneConfiguration = AuroraWindowTitlePaneConfigurations.AuroraPlain(), onCloseRequest = ::exitApplication @@ -48,12 +63,51 @@ fun main() = auroraApplication { verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxSize().auroraBackground() ) { - CommandButtonProjection( - contentModel = Command( - text = text, - action = { text = "Hello, Desktop!" } - ) - ).project() + AsyncImage( + load = { loadImageBitmap(File("assets/xs-reg/00001.jpg")) }, + painterFor = { remember { BitmapPainter(it) } }, + contentDescription = "Sample", + modifier = Modifier.fillMaxSize() + + ) +// CommandButtonProjection( +// contentModel = Command( +// text = text, +// action = { text = "Hello, Desktop!" } +// ) +// ).project() } } -} \ No newline at end of file +} +@Composable +fun AsyncImage( + load: suspend () -> T, + painterFor: @Composable (T) -> Painter, + contentDescription: String, + modifier: Modifier = Modifier, + contentScale: ContentScale = ContentScale.Fit, +) { + val image: T? by produceState(null) { + value = withContext(Dispatchers.IO) { + try { + load() + } catch (e: IOException) { + // instead of printing to console, you can also write this to log, + // or show some error placeholder + e.printStackTrace() + null + } + } + } + + if (image != null) { + ZoomImage( + painter = painterFor(image!!), + contentDescription = contentDescription, + contentScale = contentScale, + modifier = modifier + ) + } +} +fun loadImageBitmap(file: File): ImageBitmap = + file.inputStream().buffered().use(::loadImageBitmap)