Add adjustable text reader side margins
Build & Test / Build & Test App (push) Has been cancelled
Release / Extract tag name (push) Has been cancelled
Update website / update_website (release) Has been cancelled
Release / Build (push) Has been cancelled
Release / Build (FOSS) (push) Has been cancelled
Release / Create GitHub Release (push) Has been cancelled

This commit is contained in:
BookOasis Reader
2026-09-29 08:16:09 +09:00
parent eca7a3b886
commit 95b1199f1d
5 changed files with 28 additions and 4 deletions
@@ -27,7 +27,7 @@ internal data class PaginatedTextPage(
)
internal object TextPageRenderer {
private const val MARGIN_DP = 32f
private const val VERTICAL_MARGIN_DP = 32f
private const val STREAM_BUFFER_CHARS = 64 * 1024
private const val STREAM_READ_CHARS = 8 * 1024
@@ -220,9 +220,12 @@ internal object TextPageRenderer {
private fun resolveLayoutMetrics(style: TextReaderStyle): LayoutMetrics {
val pageWidth = style.pageWidthPx.coerceAtLeast(1)
val pageHeight = style.pageHeightPx.coerceAtLeast(1)
val requestedMargin = (MARGIN_DP * style.density).roundToInt().coerceAtLeast(1)
val horizontalMargin = requestedMargin.coerceAtMost(((pageWidth - 1) / 2).coerceAtLeast(0))
val verticalMargin = requestedMargin.coerceAtMost(((pageHeight - 1) / 2).coerceAtLeast(0))
val requestedHorizontalMargin = (style.horizontalMarginDp * style.density)
.roundToInt()
.coerceAtLeast(0)
val requestedVerticalMargin = (VERTICAL_MARGIN_DP * style.density).roundToInt().coerceAtLeast(1)
val horizontalMargin = requestedHorizontalMargin.coerceAtMost(((pageWidth - 1) / 2).coerceAtLeast(0))
val verticalMargin = requestedVerticalMargin.coerceAtMost(((pageHeight - 1) / 2).coerceAtLeast(0))
return LayoutMetrics(
pageWidth = pageWidth,
@@ -120,6 +120,8 @@ class ReaderPreferences(
val textParagraphSpacing: Preference<Int> = preferenceStore.getInt("reader_text_paragraph_spacing", 4)
val textHorizontalMargin: Preference<Int> = preferenceStore.getInt("reader_text_horizontal_margin", 32)
val textFontFamily: Preference<TextFontFamily> = preferenceStore.getEnum(
"reader_text_font_family",
TextFontFamily.SYSTEM,
@@ -161,6 +163,7 @@ class ReaderPreferences(
fontSize = textFontSize.get(),
lineSpacingPercent = textLineSpacing.get(),
paragraphSpacing = textParagraphSpacing.get(),
horizontalMarginDp = textHorizontalMargin.get(),
fontFamily = textFontFamily.get(),
readerTheme = readerTheme.get(),
automaticDark = (context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) ==
@@ -435,6 +438,7 @@ data class TextReaderStyle(
val fontSize: Int,
val lineSpacingPercent: Int,
val paragraphSpacing: Int,
val horizontalMarginDp: Int,
val fontFamily: ReaderPreferences.TextFontFamily,
val readerTheme: Int,
val automaticDark: Boolean,