Skip to content
Snippets Groups Projects
Verified Commit 110152ec authored by Sebastian's avatar Sebastian Committed by Mikolai Gütschow
Browse files

Fix UI scale for AddForumDialog

parent b0060fb4
No related branches found
No related tags found
1 merge request!226Add setting for ui scale using LocalDensity
...@@ -204,7 +204,6 @@ fun AddContactDialog( ...@@ -204,7 +204,6 @@ fun AddContactDialog(
onCloseRequest = onClose, onCloseRequest = onClose,
state = rememberDialogState( state = rememberDialogState(
position = WindowPosition(Alignment.Center), position = WindowPosition(Alignment.Center),
size = DpSize(width = 560.dp, height = 520.dp),
), ),
) { ) {
CompositionLocalProvider(LocalDensity provides density) { CompositionLocalProvider(LocalDensity provides density) {
......
...@@ -34,6 +34,7 @@ import androidx.compose.material.Text ...@@ -34,6 +34,7 @@ import androidx.compose.material.Text
import androidx.compose.material.TextButton import androidx.compose.material.TextButton
import androidx.compose.material.rememberScaffoldState import androidx.compose.material.rememberScaffoldState
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
...@@ -42,6 +43,7 @@ import androidx.compose.ui.Alignment ...@@ -42,6 +43,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog import androidx.compose.ui.window.Dialog
...@@ -51,7 +53,7 @@ import org.briarproject.briar.api.forum.ForumConstants.MAX_FORUM_NAME_LENGTH ...@@ -51,7 +53,7 @@ import org.briarproject.briar.api.forum.ForumConstants.MAX_FORUM_NAME_LENGTH
import org.briarproject.briar.desktop.utils.AccessibilityUtils.description import org.briarproject.briar.desktop.utils.AccessibilityUtils.description
import org.briarproject.briar.desktop.utils.InternationalizationUtils.i18n import org.briarproject.briar.desktop.utils.InternationalizationUtils.i18n
import org.briarproject.briar.desktop.utils.PreviewUtils.preview import org.briarproject.briar.desktop.utils.PreviewUtils.preview
import java.awt.Dimension import org.briarproject.briar.desktop.utils.UiUtils.DensityDimension
fun main() = preview { fun main() = preview {
val visible = mutableStateOf(true) val visible = mutableStateOf(true)
...@@ -65,6 +67,7 @@ fun AddForumDialog( ...@@ -65,6 +67,7 @@ fun AddForumDialog(
onCancelButtonClicked: () -> Unit, onCancelButtonClicked: () -> Unit,
) { ) {
if (!visible) return if (!visible) return
val density = LocalDensity.current
Dialog( Dialog(
title = i18n("forum.add.title"), title = i18n("forum.add.title"),
onCloseRequest = onCancelButtonClicked, onCloseRequest = onCancelButtonClicked,
...@@ -72,43 +75,46 @@ fun AddForumDialog( ...@@ -72,43 +75,46 @@ fun AddForumDialog(
position = WindowPosition(Alignment.Center), position = WindowPosition(Alignment.Center),
), ),
) { ) {
window.minimumSize = Dimension(360, 180) CompositionLocalProvider(LocalDensity provides density) {
val scaffoldState = rememberScaffoldState() window.minimumSize = DensityDimension(360, 240)
val name = rememberSaveable { mutableStateOf("") } window.preferredSize = DensityDimension(360, 240)
val onNameChanged = { changedName: String -> val scaffoldState = rememberScaffoldState()
// not checking for blank here, so user can still remove all characters val name = rememberSaveable { mutableStateOf("") }
if (changedName.length <= MAX_FORUM_NAME_LENGTH) name.value = changedName val onNameChanged = { changedName: String ->
} // not checking for blank here, so user can still remove all characters
Surface { if (changedName.length <= MAX_FORUM_NAME_LENGTH) name.value = changedName
Scaffold( }
modifier = Modifier Surface {
.padding(horizontal = 24.dp) Scaffold(
.padding(top = 24.dp, bottom = 12.dp), modifier = Modifier
scaffoldState = scaffoldState, .padding(horizontal = 24.dp)
topBar = { .padding(top = 24.dp, bottom = 12.dp),
Box(Modifier.fillMaxWidth()) { scaffoldState = scaffoldState,
Text( topBar = {
text = i18n("forum.add.title"), Box(Modifier.fillMaxWidth()) {
style = MaterialTheme.typography.h6, Text(
modifier = Modifier.padding(bottom = 12.dp) text = i18n("forum.add.title"),
style = MaterialTheme.typography.h6,
modifier = Modifier.padding(bottom = 12.dp)
)
}
},
content = {
AddForumContent(name.value, onNameChanged, onCreate)
},
bottomBar = {
OkCancelBottomBar(
okButtonLabel = i18n("forum.add.button"),
okButtonEnabled = isValidForumName(name.value),
onOkButtonClicked = {
onCreate(name.value)
onNameChanged("")
},
onCancelButtonClicked = onCancelButtonClicked,
) )
} },
}, )
content = { }
AddForumContent(name.value, onNameChanged, onCreate)
},
bottomBar = {
OkCancelBottomBar(
okButtonLabel = i18n("forum.add.button"),
okButtonEnabled = isValidForumName(name.value),
onOkButtonClicked = {
onCreate(name.value)
onNameChanged("")
},
onCancelButtonClicked = onCancelButtonClicked,
)
},
)
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment