🛠️ Fix issues with Paragraph Indentation

* Fixed indent is not even for all paragraphs in Justify text alignment
* Disabled indent for END and CENTER text alignments
This commit is contained in:
Acclorite 2024-09-10 21:17:43 +03:00
parent 287e92b0d2
commit e70848a9cf
3 changed files with 33 additions and 22 deletions

View file

@ -82,6 +82,7 @@ import ua.acclorite.book_story.presentation.screens.reader.components.app_bar.Re
import ua.acclorite.book_story.presentation.screens.reader.components.readerFastColorPresetChange
import ua.acclorite.book_story.presentation.screens.reader.components.settings_bottom_sheet.ReaderSettingsBottomSheet
import ua.acclorite.book_story.presentation.screens.reader.data.ReaderEvent
import ua.acclorite.book_story.presentation.screens.settings.nested.reader.data.ReaderTextAlignment
@Composable
fun ReaderScreenRoot(screen: Screen.Reader) {
@ -250,12 +251,17 @@ private fun ReaderScreen(lazyListState: LazyListState) {
false -> FontStyle.Normal
}
}
val paragraphIndentation = remember(mainState.value.paragraphIndentation) {
var indentation = ""
repeat(mainState.value.paragraphIndentation) {
indentation += " "
val paragraphIndentation = remember(
mainState.value.paragraphIndentation,
mainState.value.textAlignment
) {
if (
mainState.value.textAlignment == ReaderTextAlignment.CENTER ||
mainState.value.textAlignment == ReaderTextAlignment.END
) {
return@remember 0.sp
}
indentation
(mainState.value.paragraphIndentation * 6).sp
}
val density = LocalDensity.current

View file

@ -15,10 +15,10 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.style.LineBreak
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextIndent
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.TextUnit
import ua.acclorite.book_story.R
@ -59,7 +59,7 @@ fun LazyItemScope.ReaderTextParagraph(
fontSize: TextUnit,
letterSpacing: TextUnit,
sidePadding: Dp,
paragraphIndentation: String,
paragraphIndentation: TextUnit,
fullscreenMode: Boolean,
doubleClickTranslationEnabled: Boolean,
toolbarHidden: Boolean
@ -81,10 +81,7 @@ fun LazyItemScope.ReaderTextParagraph(
}
) {
BasicText(
text = buildAnnotatedString {
append(paragraphIndentation)
append(line)
},
text = line,
modifier = Modifier.then(
if (
doubleClickTranslationEnabled &&
@ -128,6 +125,7 @@ fun LazyItemScope.ReaderTextParagraph(
ReaderTextAlignment.CENTER -> TextAlign.Center
ReaderTextAlignment.END -> TextAlign.End
},
textIndent = TextIndent(firstLine = paragraphIndentation),
fontStyle = fontStyle,
letterSpacing = letterSpacing,
fontSize = fontSize,

View file

@ -6,6 +6,8 @@ import ua.acclorite.book_story.R
import ua.acclorite.book_story.presentation.core.components.LocalMainViewModel
import ua.acclorite.book_story.presentation.data.MainEvent
import ua.acclorite.book_story.presentation.screens.settings.components.SliderWithTitle
import ua.acclorite.book_story.presentation.screens.settings.nested.reader.data.ReaderTextAlignment
import ua.acclorite.book_story.presentation.ui.ExpandingTransition
/**
* Paragraph Indentation setting.
@ -16,10 +18,14 @@ fun ParagraphIndentationSetting() {
val state = LocalMainViewModel.current.state
val onMainEvent = LocalMainViewModel.current.onEvent
ExpandingTransition(
visible = state.value.textAlignment != ReaderTextAlignment.CENTER &&
state.value.textAlignment != ReaderTextAlignment.END
) {
SliderWithTitle(
value = state.value.paragraphIndentation to "pt",
fromValue = 0,
toValue = 10,
toValue = 12,
title = stringResource(id = R.string.paragraph_indentation_option),
onValueChange = {
onMainEvent(
@ -27,4 +33,5 @@ fun ParagraphIndentationSetting() {
)
}
)
}
}