Ver Fonte

control center scoped pages

milan jurkulák há 2 anos atrás
pai
commit
84ea2f3a76

+ 4 - 0
build.gradle.kts

@@ -65,6 +65,10 @@ allprojects {
         implementation(libs.fuzzywuzzy)
         // graphs
         implementation(libs.charts)
+        // qr code
+        implementation("io.github.alexzhirkevich:qrose:1.0.1")
+        // bar code
+//        implementation("io.github.alexzhirkevich:qrose-oned:1.0.1")
         // flow extensions
 //        implementation("io.github.hoc081098:FlowExt:1.0.0-RC")
         // drag & drop

+ 1 - 1
src/main/kotlin/eu/mjdev/desktop/components/charts/MemoryChart.kt

@@ -9,7 +9,7 @@ import androidx.compose.runtime.remember
 import androidx.compose.ui.Modifier
 import androidx.compose.ui.graphics.Color
 import com.aay.compose.baseComponents.model.LegendPosition
-import eu.mjdev.desktop.components.DraggableView
+import eu.mjdev.desktop.components.draggable.DraggableView
 import eu.mjdev.desktop.extensions.Compose.DarkDarkGray
 import eu.mjdev.desktop.helpers.MemInfo
 import eu.mjdev.desktop.helpers.MemInfo.Companion.toReadable

+ 8 - 1
src/main/kotlin/eu/mjdev/desktop/components/controlcenter/ControlCenter.kt

@@ -139,7 +139,14 @@ fun ControlCenter(
                                 Box(
                                     modifier = Modifier.width(controlCenterExpandedWidth),
                                 ) {
-                                    pages[pagerState.value].content(backgroundColor)
+                                    with(
+                                        ControlCenterPage.ControlCenterPageScope(
+                                            backgroundColor,
+                                            api
+                                        )
+                                    ) {
+                                        pages[pagerState.value].content(this)
+                                    }
                                 }
                                 Divider(
                                     modifier = Modifier.fillMaxHeight().width(controlCenterDividerWidth),

+ 8 - 2
src/main/kotlin/eu/mjdev/desktop/components/controlcenter/ControlCenterPage.kt

@@ -5,9 +5,15 @@ import androidx.compose.material.icons.filled.Settings
 import androidx.compose.runtime.Composable
 import androidx.compose.ui.graphics.Color
 import androidx.compose.ui.graphics.vector.ImageVector
+import eu.mjdev.desktop.provider.DesktopProvider
 
 class ControlCenterPage(
     val icon: ImageVector = Icons.Filled.Settings,
     val name: String = "",
-    val content: @Composable (backgroundColor: Color) -> Unit = {}
-)
+    val content: @Composable ControlCenterPageScope.() -> Unit = {}
+) {
+    class ControlCenterPageScope(
+        val backgroundColor: Color,
+        val api: DesktopProvider
+    )
+}

+ 6 - 2
src/main/kotlin/eu/mjdev/desktop/components/controlcenter/pages/MainSettingsPage.kt

@@ -19,7 +19,7 @@ import eu.mjdev.desktop.extensions.Modifier.rectShadow
 fun MainSettingsPage() = ControlCenterPage(
     icon = Icons.Filled.Home,
     name = "Home"
-) { backgroundColor ->
+) {
     Box(
         modifier = Modifier.fillMaxSize()
     ) {
@@ -49,7 +49,11 @@ fun MainSettingsPage() = ControlCenterPage(
                 .align(Alignment.BottomCenter)
         ) {
             PowerBlock(
-                backgroundColor = backgroundColor
+                backgroundColor = backgroundColor,
+                onPowerButtonClick = {
+                    // todo : dialog
+                    api.shutdown()
+                }
             )
         }
     }

+ 3 - 2
src/main/kotlin/eu/mjdev/desktop/components/custom/PowerBlock.kt

@@ -29,7 +29,8 @@ fun PowerBlock(
     backgroundColor: Color,
     shadowColor: Color = Color.Black,
     bottomBoxHeight: Dp = 128.dp,
-    iconHeight: Dp = 64.dp
+    iconHeight: Dp = 64.dp,
+    onPowerButtonClick: () -> Unit = {}
 ) = Column(
     modifier = Modifier.fillMaxWidth()
 ) {
@@ -54,7 +55,7 @@ fun PowerBlock(
                 .circleBorder(4.dp, backgroundColor)
                 .circleShadow(color = shadowColor),
             contentPadding = PaddingValues(1.dp),
-            onClick = {},
+            onClick = onPowerButtonClick,
             colors = ButtonDefaults.transparent(),
             elevation = ButtonDefaults.noElevation()
         ) {

+ 1 - 1
src/main/kotlin/eu/mjdev/desktop/components/DraggableView.kt → src/main/kotlin/eu/mjdev/desktop/components/draggable/DraggableView.kt

@@ -1,4 +1,4 @@
-package eu.mjdev.desktop.components
+package eu.mjdev.desktop.components.draggable
 
 import androidx.compose.foundation.background
 import androidx.compose.foundation.gestures.detectDragGestures

+ 56 - 0
src/main/kotlin/eu/mjdev/desktop/components/qrcode/QrCodeView.kt

@@ -0,0 +1,56 @@
+package eu.mjdev.desktop.components.qrcode
+
+import androidx.compose.foundation.Image
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.PaddingValues
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.padding
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.painter.Painter
+import androidx.compose.ui.unit.dp
+import io.github.alexzhirkevich.qrose.options.*
+import io.github.alexzhirkevich.qrose.rememberQrCodePainter
+
+// todo : params
+@Suppress("unused")
+@Composable
+fun QrCodeView(
+    modifier: Modifier = Modifier,
+    data: String = "https://mjdev.org",
+    logoPainter: Painter? = null,
+    contentPadding: PaddingValues = PaddingValues(8.dp, 48.dp),
+    contentDescription: String = data,
+    framesColor: Color = Color.Black,
+    pointColor: Color = Color.Black
+) {
+    val qrcodePainter = rememberQrCodePainter(data) {
+        if (logoPainter != null) {
+            logo {
+                painter = logoPainter
+                padding = QrLogoPadding.Natural(.1f)
+                shape = QrLogoShape.circle()
+                size = 0.2f
+            }
+        }
+        shapes {
+            ball = QrBallShape.circle()
+            darkPixel = QrPixelShape.roundCorners()
+            frame = QrFrameShape.roundCorners(.25f)
+        }
+        colors {
+            dark = QrBrush.solid(pointColor)
+            frame = QrBrush.solid(framesColor)
+        }
+    }
+    Box(
+        modifier = modifier.padding(contentPadding)
+    ) {
+        Image(
+            modifier = Modifier.fillMaxSize(),
+            painter = qrcodePainter,
+            contentDescription = contentDescription
+        )
+    }
+}