Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sizing by not using multipliers. Fixes #1385 #1386

Merged
merged 2 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions app/src/main/java/com/jerboa/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ package com.jerboa

const val DEBOUNCE_DELAY = 1000L
const val MAX_POST_TITLE_LENGTH = 200
const val DEFAULT_FONT_SIZE = 16
const val INSTANCE_FONT_SIZE = 9
const val VIEW_VOTES_LIMIT = 40L
2 changes: 1 addition & 1 deletion app/src/main/java/com/jerboa/db/AppDB.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.sqlite.db.SupportSQLiteDatabase
import com.jerboa.DEFAULT_FONT_SIZE
import com.jerboa.db.dao.AccountDao
import com.jerboa.db.dao.AppSettingsDao
import com.jerboa.db.entity.Account
import com.jerboa.db.entity.AppSettings
import com.jerboa.feat.SwipeToActionPreset
import com.jerboa.ui.theme.DEFAULT_FONT_SIZE
import java.util.concurrent.Executors

val APP_SETTINGS_DEFAULT =
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/jerboa/db/entity/AppSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.jerboa.db.entity
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.jerboa.DEFAULT_FONT_SIZE
import com.jerboa.ui.theme.DEFAULT_FONT_SIZE

@Entity
data class AppSettings(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.jerboa.INSTANCE_FONT_SIZE
import com.jerboa.hostName
import com.jerboa.ui.theme.muted

Expand Down Expand Up @@ -65,9 +63,7 @@ fun ItemAndInstanceTitle(
itemColor: Color = MaterialTheme.colorScheme.primary,
itemStyle: TextStyle = MaterialTheme.typography.bodyMedium,
instanceColor: Color = MaterialTheme.colorScheme.onSurface.muted,
instanceStyle: TextStyle = MaterialTheme.typography.bodySmall.copy(
fontSize = INSTANCE_FONT_SIZE.sp,
),
instanceStyle: TextStyle = MaterialTheme.typography.bodySmall,
) {
val text = remember(title, local, itemColor) {
val serverStr = if (!local && actorId != null) {
Expand Down
18 changes: 11 additions & 7 deletions app/src/main/java/com/jerboa/ui/components/common/TimeAgo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.jerboa.R
import com.jerboa.datatypes.samplePerson
import com.jerboa.datatypes.samplePost
import com.jerboa.formatDuration
import com.jerboa.ui.theme.SCORE_SIZE_ADD
import com.jerboa.ui.theme.SMALL_PADDING
import com.jerboa.ui.theme.muted
import java.time.Instant
Expand Down Expand Up @@ -57,13 +59,13 @@ fun TimeAgo(
Text(
text = afterPreceding,
color = MaterialTheme.colorScheme.onBackground.muted,
style = MaterialTheme.typography.bodyMedium,
style = MaterialTheme.typography.labelMedium,
)

updated?.also {
DotSpacer(
padding = SMALL_PADDING,
style = MaterialTheme.typography.bodyMedium,
style = MaterialTheme.typography.labelMedium,
)
val updatedPretty = dateStringToPretty(it, longTimeFormat)

Expand All @@ -72,7 +74,7 @@ fun TimeAgo(
} else {
Text(
text = "($updatedPretty)",
style = MaterialTheme.typography.bodyMedium,
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.onBackground.muted,
fontStyle = FontStyle.Italic,
)
Expand Down Expand Up @@ -135,10 +137,12 @@ fun ScoreAndTime(
Text(
text = score.toString(),
color = scoreColor(myVote = myVote),
fontSize = MaterialTheme.typography.bodyMedium.fontSize.times(1.3),
style = MaterialTheme.typography.labelMedium.copy(
fontSize = MaterialTheme.typography.labelMedium.fontSize.value.plus(SCORE_SIZE_ADD).sp,
),
)
}
DotSpacer(style = MaterialTheme.typography.bodyMedium)
DotSpacer(style = MaterialTheme.typography.labelMedium)
TimeAgo(published = published, updated = updated)
}
}
Expand Down Expand Up @@ -175,7 +179,7 @@ fun CollapsedIndicator(
) {
Text(
text = "+$descendants",
style = MaterialTheme.typography.bodyMedium,
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.onSecondary,
)
}
Expand Down Expand Up @@ -206,7 +210,7 @@ fun NsfwBadge(visible: Boolean) {
) {
Text(
text = "NSFW",
style = MaterialTheme.typography.bodyMedium,
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.onSecondary,
)
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/jerboa/ui/components/home/Home.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fun HomeHeaderTitle(
)
Text(
text = ctx.getString(selectedSortType.data.shortForm),
style = MaterialTheme.typography.titleSmall,
style = MaterialTheme.typography.titleMedium,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ fun CommentsHeaderTitle(selectedSortType: CommentSortType) {
)
Text(
text = getLocalizedCommentSortTypeName(ctx, selectedSortType),
style = MaterialTheme.typography.titleSmall,
style = MaterialTheme.typography.titleMedium,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ fun PostName(

Text(
text = postView.post.name,
style = MaterialTheme.typography.titleLarge,
style = MaterialTheme.typography.headlineLarge,
color = color,
modifier = Modifier.testTag("jerboa:posttitle"),
)
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/jerboa/ui/theme/Sizes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package com.jerboa.ui.theme

import androidx.compose.ui.unit.dp

const val DEFAULT_FONT_SIZE = 16
const val SCORE_SIZE_ADD = 4

val ACTION_BAR_ICON_SIZE = 16.dp
val MARKDOWN_BAR_ICON_SIZE = 24.dp

Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/com/jerboa/ui/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.unit.sp
import androidx.core.graphics.ColorUtils
import androidx.core.view.WindowCompat
import com.jerboa.ThemeColor
Expand All @@ -33,7 +32,7 @@ fun JerboaTheme(
) {
val themeMode = ThemeMode.entries[appSettings.theme]
val themeColor = ThemeColor.entries[appSettings.themeColor]
val fontSize = appSettings.fontSize.sp
val fontSize = appSettings.fontSize

val ctx = LocalContext.current
val android12OrLater = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
Expand Down
78 changes: 55 additions & 23 deletions app/src/main/java/com/jerboa/ui/theme/Type.kt
Original file line number Diff line number Diff line change
@@ -1,44 +1,76 @@
package com.jerboa.ui.theme

import androidx.compose.material3.Typography
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.sp

const val FONT_LARGE_MULTIPLIER = 1.3
const val FONT_MEDIUM_MULTIPLIER = 0.8
const val FONT_SMALL_MULTIPLIER = 0.7
const val FONT_SMALL_ADD = -7
const val FONT_MEDIUM_ADD = -3
const val FONT_LARGE_ADD = 0
const val LINE_HEIGHT_MULTIPLIER = 1.5

// Set of Material typography styles to start with
fun generateTypography(baseFontSize: TextUnit): Typography {
// Example from here: https://egeniq.com/blog/dynamic-font-sizes-with-jetpack-compose/
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was incorrectly using multipliers on the baseFontSize. The link above suggested to use simple additions, and a multiplier for line height.

fun generateTypography(baseFontSize: Int): Typography {
return Typography(
bodyLarge =
Typography().bodyLarge.copy(
fontSize = baseFontSize,
lineHeight = baseFontSize.times(FONT_LARGE_MULTIPLIER),
bodySmall =
Typography().bodySmall.copy(
fontSize = baseFontSize.plus(FONT_SMALL_ADD).sp,
lineHeight = baseFontSize.plus(FONT_SMALL_ADD).times(LINE_HEIGHT_MULTIPLIER).sp,
),
bodyMedium =
Typography().bodyMedium.copy(
fontSize = baseFontSize.times(FONT_MEDIUM_MULTIPLIER),
lineHeight = baseFontSize.times(FONT_MEDIUM_MULTIPLIER * FONT_LARGE_MULTIPLIER),
fontSize = baseFontSize.plus(FONT_MEDIUM_ADD).sp,
lineHeight = baseFontSize.plus(FONT_MEDIUM_ADD).times(LINE_HEIGHT_MULTIPLIER).sp,
),
bodySmall =
Typography().bodySmall.copy(
fontSize = baseFontSize.times(FONT_SMALL_MULTIPLIER),
lineHeight = baseFontSize.times(FONT_SMALL_MULTIPLIER * FONT_LARGE_MULTIPLIER),
bodyLarge =
Typography().bodyLarge.copy(
fontSize = baseFontSize.plus(FONT_LARGE_ADD).sp,
lineHeight = baseFontSize.plus(FONT_LARGE_ADD).times(LINE_HEIGHT_MULTIPLIER).sp,
),
titleSmall =
Typography().titleSmall.copy(
fontSize = baseFontSize.plus(FONT_SMALL_ADD).sp,
lineHeight = baseFontSize.plus(FONT_SMALL_ADD).times(LINE_HEIGHT_MULTIPLIER).sp,
),
titleMedium =
Typography().titleMedium.copy(
fontSize = baseFontSize,
lineHeight = baseFontSize.times(FONT_LARGE_MULTIPLIER),
fontSize = baseFontSize.plus(FONT_MEDIUM_ADD).sp,
lineHeight = baseFontSize.plus(FONT_MEDIUM_ADD).times(LINE_HEIGHT_MULTIPLIER).sp,
),
titleLarge =
Typography().titleLarge.copy(
fontSize = baseFontSize,
lineHeight = baseFontSize.times(FONT_LARGE_MULTIPLIER),
fontSize = baseFontSize.plus(FONT_LARGE_ADD).sp,
lineHeight = baseFontSize.plus(FONT_LARGE_ADD).times(LINE_HEIGHT_MULTIPLIER).sp,
),
titleSmall =
Typography().titleSmall.copy(
fontSize = baseFontSize.times(FONT_MEDIUM_MULTIPLIER),
lineHeight = baseFontSize.times(FONT_LARGE_MULTIPLIER),
headlineSmall =
Typography().headlineSmall.copy(
fontSize = baseFontSize.plus(FONT_SMALL_ADD).sp,
lineHeight = baseFontSize.plus(FONT_SMALL_ADD).times(LINE_HEIGHT_MULTIPLIER).sp,
),
headlineMedium =
Typography().headlineMedium.copy(
fontSize = baseFontSize.plus(FONT_MEDIUM_ADD).sp,
lineHeight = baseFontSize.plus(FONT_MEDIUM_ADD).times(LINE_HEIGHT_MULTIPLIER).sp,
),
headlineLarge =
Typography().headlineLarge.copy(
fontSize = baseFontSize.plus(FONT_LARGE_ADD).sp,
lineHeight = baseFontSize.plus(FONT_LARGE_ADD).times(LINE_HEIGHT_MULTIPLIER).sp,
),
labelSmall =
Typography().labelSmall.copy(
fontSize = baseFontSize.plus(FONT_SMALL_ADD).sp,
lineHeight = baseFontSize.plus(FONT_SMALL_ADD).times(LINE_HEIGHT_MULTIPLIER).sp,
),
labelMedium =
Typography().labelMedium.copy(
fontSize = baseFontSize.plus(FONT_MEDIUM_ADD).sp,
lineHeight = baseFontSize.plus(FONT_MEDIUM_ADD).times(LINE_HEIGHT_MULTIPLIER).sp,
),
labelLarge =
Typography().labelLarge.copy(
fontSize = baseFontSize.plus(FONT_LARGE_ADD).sp,
lineHeight = baseFontSize.plus(FONT_LARGE_ADD).times(LINE_HEIGHT_MULTIPLIER).sp,
),
)
}