Browse Source

Add mouse move demo to imageviewer.

pull/4/head
Nikolay Igotti 4 years ago
parent
commit
d96a1090cb
  1. 10
      examples/imageviewer/common/src/androidMain/kotlin/example/imageviewer/view/ActualAndroid.kt
  2. 2
      examples/imageviewer/common/src/commonMain/kotlin/example/imageviewer/view/Draggable.kt
  3. 10
      examples/imageviewer/common/src/commonMain/kotlin/example/imageviewer/view/PointerMoveFilter.kt
  4. 11
      examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/ActualDesktop.kt
  5. 39
      examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/MainScreen.kt
  6. 2
      examples/imageviewer/settings.gradle.kts

10
examples/imageviewer/common/src/androidMain/kotlin/example/imageviewer/view/ActualAndroid.kt

@ -0,0 +1,10 @@
package example.imageviewer.view
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
actual fun Modifier.maybePointerMoveFilter(
onEnter: () -> Boolean,
onExit: () -> Boolean,
onMove: (Offset) -> Boolean
): Modifier = this

2
examples/imageviewer/common/src/commonMain/kotlin/example/imageviewer/view/Draggable.kt

@ -105,4 +105,4 @@ class Point {
this.x = x
this.y = y
}
}
}

10
examples/imageviewer/common/src/commonMain/kotlin/example/imageviewer/view/PointerMoveFilter.kt

@ -0,0 +1,10 @@
package example.imageviewer.view
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
expect fun Modifier.maybePointerMoveFilter(
onEnter: () -> Boolean = { true },
onExit: () -> Boolean = { true },
onMove: (Offset) -> Boolean = { true }
): Modifier

11
examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/ActualDesktop.kt

@ -0,0 +1,11 @@
package example.imageviewer.view
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.input.pointer.pointerMoveFilter
actual fun Modifier.maybePointerMoveFilter(
onEnter: () -> Boolean,
onExit: () -> Boolean,
onMove: (Offset) -> Boolean
): Modifier = this.pointerMoveFilter(onEnter = onEnter, onExit = onExit, onMove = onMove)

39
examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/MainScreen.kt

@ -15,22 +15,18 @@
*/
package example.imageviewer.view
import androidx.compose.foundation.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.asImageAsset
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.foundation.clickable
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.ScrollableColumn
import androidx.compose.foundation.Text
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.Stack
import androidx.compose.foundation.Box
import androidx.compose.foundation.layout.preferredHeight
import androidx.compose.foundation.layout.preferredWidth
import androidx.compose.foundation.layout.preferredSize
@ -44,6 +40,10 @@ import androidx.compose.material.MaterialTheme
import androidx.compose.material.TopAppBar
import androidx.compose.material.Card
import androidx.compose.material.Divider
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import example.imageviewer.model.AppState
import example.imageviewer.model.Picture
@ -173,7 +173,7 @@ fun setMiniatureUI(
picture: Picture,
content: ContentState
) {
val active = remember { mutableStateOf(false) }
Card(
backgroundColor = MiniatureColor,
modifier = Modifier.padding(start = 10.dp, end = 10.dp).preferredHeight(70.dp)
@ -184,11 +184,22 @@ fun setMiniatureUI(
shape = RectangleShape,
elevation = 2.dp
) {
Row(modifier = Modifier.padding(end = 30.dp)) {
Clickable(
onClick = {
content.fullscreen(picture)
Row(modifier = Modifier
.padding(end = 30.dp)
.maybePointerMoveFilter(onEnter = {
active.value = true
false
},
onExit = {
active.value = false
false
}
)
.background(color = if (active.value) Color.LightGray else Color.Black)) {
Clickable(
onClick = {
content.fullscreen(picture)
}
) {
Image(
Image.makeFromEncoded(
@ -202,8 +213,12 @@ fun setMiniatureUI(
}
Text(
text = picture.name,
color = Foreground,
modifier = Modifier.weight(1f).align(Alignment.CenterVertically).padding(start = 16.dp),
color = if (active.value) Color.Red else Foreground,
modifier = Modifier
.weight(1f)
.align(Alignment.CenterVertically)
.padding(start = 16.dp),
fontSize = TextUnit.Sp(if (active.value) 40 else 16),
style = MaterialTheme.typography.body1
)

2
examples/imageviewer/settings.gradle.kts

@ -6,7 +6,7 @@ buildscript {
}
dependencies {
classpath("org.jetbrains.compose:compose-gradle-plugin:0.1.0-build58")
classpath("org.jetbrains.compose:compose-gradle-plugin:0.1.0-build60")
classpath("com.android.tools.build:gradle:4.0.1")
classpath(kotlin("gradle-plugin", version = "1.4.0"))
}

Loading…
Cancel
Save