From 492e227af37e59b42ffa52864a47cf9c7223ba9f Mon Sep 17 00:00:00 2001 From: Patrick Hoefer Date: Thu, 17 Dec 2020 17:51:34 +0100 Subject: [PATCH] refactor(main): extract layout functions --- .../ck3workbench/app/ui/MainUiComponents.kt | 19 +++++++ ...orkbenchFunctions.kt => WorkbenchPanel.kt} | 56 ++++++++++--------- src/main/kotlin/main.kt | 19 +------ 3 files changed, 52 insertions(+), 42 deletions(-) rename src/main/kotlin/com/github/xetra11/ck3workbench/app/ui/{WorkbenchFunctions.kt => WorkbenchPanel.kt} (51%) diff --git a/src/main/kotlin/com/github/xetra11/ck3workbench/app/ui/MainUiComponents.kt b/src/main/kotlin/com/github/xetra11/ck3workbench/app/ui/MainUiComponents.kt index c812449..3725f02 100644 --- a/src/main/kotlin/com/github/xetra11/ck3workbench/app/ui/MainUiComponents.kt +++ b/src/main/kotlin/com/github/xetra11/ck3workbench/app/ui/MainUiComponents.kt @@ -2,15 +2,20 @@ package com.github.xetra11.ck3workbench.app.ui import androidx.compose.foundation.border import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.BoxScope import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.RowScope +import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp +import com.github.xetra11.ck3workbench.module.character.ui.WorkbenchPanel object MainUiComponents { @Composable @@ -26,4 +31,18 @@ object MainUiComponents { content = content ) } + @Composable + fun MainLayoutRow( + view: @Composable BoxScope.() -> Unit + ) { + Row(modifier = Modifier.fillMaxWidth().fillMaxHeight(0.95F).border(3.dp, Color.Green)) { + Box( + Modifier.border(5.dp, Color.Black).fillMaxWidth(0.2F).fillMaxHeight(), + contentAlignment = Alignment.Center + ) { + WorkbenchPanel() + } + Box(Modifier.border(5.dp, Color.Red).fillMaxWidth(), content = view) + } + } } diff --git a/src/main/kotlin/com/github/xetra11/ck3workbench/app/ui/WorkbenchFunctions.kt b/src/main/kotlin/com/github/xetra11/ck3workbench/app/ui/WorkbenchPanel.kt similarity index 51% rename from src/main/kotlin/com/github/xetra11/ck3workbench/app/ui/WorkbenchFunctions.kt rename to src/main/kotlin/com/github/xetra11/ck3workbench/app/ui/WorkbenchPanel.kt index 80752ff..2e889c5 100644 --- a/src/main/kotlin/com/github/xetra11/ck3workbench/app/ui/WorkbenchFunctions.kt +++ b/src/main/kotlin/com/github/xetra11/ck3workbench/app/ui/WorkbenchPanel.kt @@ -1,7 +1,6 @@ package com.github.xetra11.ck3workbench.module.character.ui import androidx.compose.foundation.Image -import androidx.compose.foundation.border import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box @@ -10,45 +9,52 @@ import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.preferredSize import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.ImageBitmap -import androidx.compose.ui.graphics.imageFromResource import androidx.compose.ui.res.imageResource import androidx.compose.ui.unit.dp import com.github.xetra11.ck3workbench.app.NotificationsService @Composable -fun WorkbenchFunctions() { +fun WorkbenchPanel() { Column(Modifier.fillMaxHeight(0.8F), verticalArrangement = Arrangement.SpaceBetween) { val squareImage = imageResource("icons/thepinkpanzer/BG_Square_Brown.png") - Box(Modifier.preferredSize(50.dp) - .clickable( - onClick = { NotificationsService.notify("CLICK") } - )) { + Box( + Modifier.preferredSize(50.dp) + .clickable( + onClick = { NotificationsService.notify("CLICK") } + ) + ) { Image(squareImage) } - Box(Modifier.preferredSize(50.dp) - .clickable( - onClick = { NotificationsService.notify("CLICK 2") } - )) { + Box( + Modifier.preferredSize(50.dp) + .clickable( + onClick = { NotificationsService.notify("CLICK 2") } + ) + ) { Image(squareImage) } - Box(Modifier.preferredSize(50.dp) - .clickable( - onClick = { NotificationsService.notify("CLICK 3") } - )) { + Box( + Modifier.preferredSize(50.dp) + .clickable( + onClick = { NotificationsService.notify("CLICK 3") } + ) + ) { Image(squareImage) } - Box(Modifier.preferredSize(50.dp) - .clickable( - onClick = { NotificationsService.notify("CLICK") } - )) { + Box( + Modifier.preferredSize(50.dp) + .clickable( + onClick = { NotificationsService.notify("CLICK") } + ) + ) { Image(squareImage) } - Box(Modifier.preferredSize(50.dp) - .clickable( - onClick = { NotificationsService.notify("CLICK") } - )) { + Box( + Modifier.preferredSize(50.dp) + .clickable( + onClick = { NotificationsService.notify("CLICK") } + ) + ) { Image(squareImage) } } diff --git a/src/main/kotlin/main.kt b/src/main/kotlin/main.kt index 9d28105..f5dd047 100644 --- a/src/main/kotlin/main.kt +++ b/src/main/kotlin/main.kt @@ -1,19 +1,13 @@ import androidx.compose.desktop.AppManager import androidx.compose.desktop.AppWindow -import androidx.compose.foundation.border -import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.shape.CutCornerShape import androidx.compose.material.Colors import androidx.compose.material.MaterialTheme import androidx.compose.material.Shapes import androidx.compose.runtime.MutableState import androidx.compose.runtime.mutableStateOf -import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.IntSize @@ -24,7 +18,6 @@ import androidx.compose.ui.window.MenuItem import com.github.xetra11.ck3workbench.app.ui.MainUiComponents import com.github.xetra11.ck3workbench.module.character.importer.CharacterScriptImporter import com.github.xetra11.ck3workbench.module.character.ui.NotificationPanel -import com.github.xetra11.ck3workbench.module.character.ui.WorkbenchFunctions import com.github.xetra11.ck3workbench.module.character.view.CharacterModuleView import org.slf4j.Logger import org.slf4j.LoggerFactory @@ -68,16 +61,8 @@ fun main() = invokeLater { shapes = workBenchShapes() ) { Column(Modifier.fillMaxSize()) { - Row(modifier = Modifier.fillMaxWidth().fillMaxHeight(0.95F).border(3.dp, Color.Green)) { - Box( - Modifier.border(5.dp, Color.Black).fillMaxWidth(0.2F).fillMaxHeight(), - contentAlignment = Alignment.Center - ) { - WorkbenchFunctions() - } - Box(Modifier.border(5.dp, Color.Red).fillMaxWidth()) { - CharacterModuleView() - } + MainUiComponents.MainLayoutRow { + CharacterModuleView() } MainUiComponents.NotificationPanelRow { NotificationPanel()