Dialog fixes

This commit is contained in:
Syer10
2021-08-20 20:10:17 -04:00
parent d72942c69e
commit fc85822c39
3 changed files with 16 additions and 12 deletions

View File

@@ -9,6 +9,7 @@ package ca.gosyer.ui.base
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.BoxWithConstraintsScope
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope import androidx.compose.foundation.layout.RowScope
@@ -131,8 +132,8 @@ fun WindowDialog(
onCloseRequest: (() -> Unit)? = null, onCloseRequest: (() -> Unit)? = null,
forceFocus: Boolean = true, forceFocus: Boolean = true,
keyboardShortcuts: Map<Key, (KeyEvent) -> Boolean> = emptyMap(), keyboardShortcuts: Map<Key, (KeyEvent) -> Boolean> = emptyMap(),
buttons: @Composable (() -> Unit) -> Unit, buttons: @Composable BoxWithConstraintsScope.(() -> Unit) -> Unit,
content: @Composable (() -> Unit) -> Unit content: @Composable BoxWithConstraintsScope.(() -> Unit) -> Unit
) = launchApplication { ) = launchApplication {
DisposableEffect(Unit) { DisposableEffect(Unit) {
onDispose { onDispose {
@@ -141,7 +142,7 @@ fun WindowDialog(
} }
val resources = remember { AppScope.getInstance<XmlResourceBundle>() } val resources = remember { AppScope.getInstance<XmlResourceBundle>() }
val windowState = rememberWindowState(size = size) val windowState = rememberWindowState(size = size, position = WindowPosition.Aligned(Alignment.Center))
Window( Window(
title = title, title = title,
@@ -155,17 +156,17 @@ fun WindowDialog(
else -> false else -> false
} }
}, },
alwaysOnTop = forceFocus alwaysOnTop = forceFocus,
) { ) {
CompositionLocalProvider( CompositionLocalProvider(
LocalResources provides resources LocalResources provides resources
) { ) {
AppTheme { AppTheme {
Surface { Surface {
Column( Column {
modifier = Modifier.fillMaxSize() BoxWithConstraints(
) { modifier = Modifier.fillMaxSize()
BoxWithConstraints { ) {
content(::exitApplication) content(::exitApplication)
buttons(::exitApplication) buttons(::exitApplication)
} }

View File

@@ -101,7 +101,7 @@ fun ColorPickerDialog(
buttons = { buttons = {
val showPresetsState by showPresets.collectAsState() val showPresetsState by showPresets.collectAsState()
val currentColorState by currentColor.collectAsState() val currentColorState by currentColor.collectAsState()
Row(Modifier.fillMaxWidth().padding(8.dp)) { Row(Modifier.fillMaxWidth().padding(8.dp).align(Alignment.BottomCenter)) {
TextButton( TextButton(
onClick = { onClick = {
showPresets.value = !showPresetsState showPresets.value = !showPresetsState
@@ -373,7 +373,8 @@ fun ColorPalette(
} else { } else {
textFieldHex = it textFieldHex = it
} }
} },
singleLine = true
) )
} }
} }

View File

@@ -26,10 +26,12 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.BoxWithConstraintsScope
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.defaultMinSize import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.requiredHeight import androidx.compose.foundation.layout.requiredHeight
@@ -228,14 +230,14 @@ fun <T> ChoiceDialog(
onCloseRequest: () -> Unit = {}, onCloseRequest: () -> Unit = {},
onSelected: (T) -> Unit, onSelected: (T) -> Unit,
title: String, title: String,
buttons: @Composable (() -> Unit) -> Unit = { } buttons: @Composable BoxWithConstraintsScope.(() -> Unit) -> Unit = { }
) { ) {
WindowDialog( WindowDialog(
onCloseRequest = onCloseRequest, onCloseRequest = onCloseRequest,
buttons = buttons, buttons = buttons,
title = title, title = title,
content = { content = {
LazyColumn { LazyColumn(Modifier.fillMaxSize()) {
items(items) { (value, text) -> items(items) { (value, text) ->
Row( Row(
modifier = Modifier.requiredHeight(48.dp).fillMaxWidth().clickable( modifier = Modifier.requiredHeight(48.dp).fillMaxWidth().clickable(