Skip to content

Commit

Permalink
refactor(main): extract layout functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Hoefer committed Dec 17, 2020
1 parent 91abe11 commit 492e227
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
}
}
Expand Down
19 changes: 2 additions & 17 deletions src/main/kotlin/main.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 492e227

Please sign in to comment.