fix(desktop): width cap ordering, platform icon weight, Settings hierarchy

Three related fixes:

ReadingColumn modifier ordering:
- fillMaxSize().widthIn(max = 720) was locking width to parent before
  widthIn could cap it, so the cap had no effect in practice. Switched
  to widthIn(max = 720).fillMaxWidth().fillMaxHeight() which now caps
  correctly on wide displays. Same fix applied to the three screens
  that use Box+widthIn inline (UserProfile, Search, Settings).

Platform-aware Material Symbols weight:
- ProvideMaterialSymbols now takes an optional weight parameter that
  defaults to MaterialSymbolsDefaults.WEIGHT (300) so Android keeps
  current behavior. Desktop passes PlatformIconWeight.current which
  maps:
    macOS   → 200 (thin, matches SF Symbols stroke)
    GNOME   → 300 (matches libadwaita symbolic icons)
    KDE     → 300 (matches Breeze)
    Windows → 400 (matches Fluent Icons)
    other   → 300

Settings section hierarchy:
- "Wallet Connect (NWC)" and "Relay Settings" section headers dropped
  from titleLarge (22sp) to titleSmall (14sp) so they're smaller than
  the "Settings" screen title (titleMedium 16sp). Restores the
  visual hierarchy the user reported inverted.

https://claude.ai/code/session_01NufduPfZvYQVYwLkbCjCUo
This commit is contained in:
Claude
2026-04-24 15:27:53 +00:00
parent cd4dd42bc4
commit c4ae0a30eb
6 changed files with 88 additions and 13 deletions
@@ -47,24 +47,31 @@ private const val TEXT_MEASURER_CACHE_SIZE = 64
/**
* Builds the Material Symbols FontFamily and a shared TextMeasurer once for the subtree and
* exposes them via CompositionLocal. Wrap app roots (AmethystTheme, desktop MaterialTheme) in this.
*
* The optional [weight] override lets callers pick a stroke thickness different from the
* library default — desktop uses per-OS weights (macOS likes the thinner SF-Symbols-ish
* look at 200, Windows Fluent icons sit closer to 400) while Android keeps the default.
*/
@Composable
fun ProvideMaterialSymbols(content: @Composable () -> Unit) {
fun ProvideMaterialSymbols(
weight: Int = MaterialSymbolsDefaults.WEIGHT,
content: @Composable () -> Unit,
) {
val font =
Font(
resource = Res.font.material_symbols_outlined,
weight = FontWeight(MaterialSymbolsDefaults.WEIGHT),
weight = FontWeight(weight),
variationSettings =
FontVariation.Settings(
FontVariation.weight(MaterialSymbolsDefaults.WEIGHT),
FontVariation.weight(weight),
FontVariation.Setting("FILL", MaterialSymbolsDefaults.FILL),
FontVariation.Setting("opsz", MaterialSymbolsDefaults.OPTICAL_SIZE),
FontVariation.Setting("GRAD", MaterialSymbolsDefaults.GRADE),
),
)
// Keyless remember: the Font wrapper identity changes every composition but the underlying
// resource is a compile-time constant, so one FontFamily for the lifetime of the subtree.
val fontFamily = remember { FontFamily(font) }
// Keyless remember is safe only when weight is stable; key on weight so a platform-
// preview override swap actually rebuilds the FontFamily.
val fontFamily = remember(weight) { FontFamily(font) }
val textMeasurer = rememberTextMeasurer(cacheSize = TEXT_MEASURER_CACHE_SIZE)
CompositionLocalProvider(
LocalMaterialSymbolsFontFamily provides fontFamily,
@@ -26,6 +26,7 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
@@ -807,7 +808,9 @@ fun App(
.rememberSystemDark(LocalAwtWindow.current)
com.vitorpamplona.amethyst.desktop.platform.PlatformMaterialTheme(isDark = isDark) {
ProvideMaterialSymbols {
ProvideMaterialSymbols(
weight = com.vitorpamplona.amethyst.desktop.platform.PlatformIconWeight.current,
) {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background,
@@ -1328,8 +1331,9 @@ fun RelaySettingsScreen(
Column(
modifier =
Modifier
.fillMaxSize()
.widthIn(max = 720.dp)
.fillMaxWidth()
.fillMaxHeight()
.verticalScroll(rememberScrollState())
.padding(horizontal = 12.dp),
) {
@@ -1353,7 +1357,7 @@ fun RelaySettingsScreen(
// Wallet Connect Section
Text(
"Wallet Connect (NWC)",
style = MaterialTheme.typography.titleLarge,
style = MaterialTheme.typography.titleSmall,
color = MaterialTheme.colorScheme.onBackground,
)
Spacer(Modifier.height(8.dp))
@@ -1462,7 +1466,7 @@ fun RelaySettingsScreen(
Text(
"Relay Settings",
style = MaterialTheme.typography.titleLarge,
style = MaterialTheme.typography.titleSmall,
color = MaterialTheme.colorScheme.onBackground,
)
Spacer(Modifier.height(8.dp))
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2025 Vitor Pamplona
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.vitorpamplona.amethyst.desktop.platform
/**
* Preferred Material Symbols stroke weight per host OS. Each desktop UI language
* draws icons at a different visual weight; matching them makes the in-app icons
* feel at home next to the OS's own. Values use the Material Symbols variation
* axis (100 = Thin, 200 = ExtraLight, 300 = Light, 400 = Regular, …, 700 = Bold).
*
* Reference calibration:
* - macOS: SF Symbols "Regular" is visually lighter than 400 Material Symbols;
* 200 (Thin/ExtraLight) matches the delicate stroke macOS users expect.
* - GNOME: libadwaita symbolic icons are a hair thinner than Regular — 300 matches.
* - KDE Breeze: Breeze icons are thin-to-medium, also 300.
* - Windows (Fluent): Fluent Icons have moderate weight, 400 is the sweet spot.
*/
object PlatformIconWeight {
val current: Int by lazy {
when (PlatformInfo.current) {
Platform.MACOS -> 200
Platform.GNOME -> 300
Platform.KDE -> 300
Platform.WINDOWS -> 400
Platform.LINUX_OTHER, Platform.UNKNOWN -> 300
}
}
}
@@ -23,7 +23,9 @@ package com.vitorpamplona.amethyst.desktop.ui
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.widthIn
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
@@ -59,8 +61,15 @@ fun ReadingColumn(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.TopCenter,
) {
// Order matters: widthIn must come BEFORE fillMaxWidth, otherwise
// fillMaxWidth locks the Column to parent.width and the cap is ignored.
// fillMaxHeight is safe (it only constrains the other axis).
Column(
modifier = modifier.fillMaxSize().widthIn(max = maxWidth),
modifier =
modifier
.widthIn(max = maxWidth)
.fillMaxWidth()
.fillMaxHeight(),
content = content,
)
}
@@ -31,6 +31,7 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
@@ -300,8 +301,9 @@ fun SearchScreen(
Column(
modifier =
modifier
.fillMaxSize()
.widthIn(max = DefaultReadingWidth)
.fillMaxWidth()
.fillMaxHeight()
.onPreviewKeyEvent { event ->
if (event.type != KeyEventType.KeyDown) return@onPreviewKeyEvent false
when (event.key) {
@@ -30,6 +30,7 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
@@ -439,7 +440,13 @@ fun UserProfileScreen(
}
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.TopCenter) {
Box(modifier = Modifier.fillMaxSize().widthIn(max = DefaultReadingWidth)) {
Box(
modifier =
Modifier
.widthIn(max = DefaultReadingWidth)
.fillMaxWidth()
.fillMaxHeight(),
) {
if (connectedRelays.isEmpty()) {
LoadingState("Connecting to relays...")
} else {