Add font picker (Segoe UI, Tahoma, Tw Cen MT, Nunito, Quicksand, Varela Round), bump to 0.1.10
Each channel window's settings panel gets a Font list, and wIRC main gets a Font button that opens the same list for the server messages box. Every name is drawn in its own font as a preview. The choice is saved per window in window_prefs.json (fontId) and applies to the scrollback, user list, input box and title. - Segoe UI, Tahoma and Tw Cen MT are Microsoft-licensed, so they aren't bundled: they load from the Windows font folders at runtime and are only listed when present (Tw Cen MT comes with Office). - Nunito, Quicksand and Varela Round are SIL OFL fonts, bundled in resources/fonts with their license files. - A missing or unloadable font falls back to Monospace. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
3538274805
commit
efad80e141
@@ -108,7 +108,8 @@ fun main() = application {
|
||||
openBuffers = openBuffers + BufferKey(serverId, channelName)
|
||||
},
|
||||
onExitApp = shutdownApp,
|
||||
onUnreadChange = { mainUnread = it }
|
||||
onUnreadChange = { mainUnread = it },
|
||||
onFontChange = { id -> prefsRepo.setFontId(MAIN_BUFFER_KEY.storageId(), id) }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ data class WindowDisplaySettings(
|
||||
val backgroundAlpha: Float = 0.85f, // 0f = fully transparent, 1f = fully opaque
|
||||
val textColorMircIndex: Int = 0, // index into the standard mIRC palette; 0 = white
|
||||
val fontSize: Float = 14f,
|
||||
val fontId: String = "monospace", // see ui/AppFonts.kt; unknown/missing ids fall back to monospace
|
||||
val showUserList: Boolean = true,
|
||||
val mentionHighlightColorArgb: Int = 0x40FFA500.toInt(), // translucent orange
|
||||
val nickColorsEnabled: Boolean = true,
|
||||
@@ -64,6 +65,8 @@ class WindowPrefsRepository(rootDir: File) {
|
||||
|
||||
fun setFontSize(bufferKeyId: String, fontSize: Float) = update(bufferKeyId) { it.copy(fontSize = fontSize) }
|
||||
|
||||
fun setFontId(bufferKeyId: String, fontId: String) = update(bufferKeyId) { it.copy(fontId = fontId) }
|
||||
|
||||
fun setShowUserList(bufferKeyId: String, show: Boolean) = update(bufferKeyId) { it.copy(showUserList = show) }
|
||||
|
||||
fun setMentionHighlightColor(bufferKeyId: String, colorArgb: Int) = update(bufferKeyId) { it.copy(mentionHighlightColorArgb = colorArgb) }
|
||||
@@ -107,6 +110,7 @@ class WindowPrefsRepository(rootDir: File) {
|
||||
backgroundAlpha = o.optDouble("backgroundAlpha", 0.85).toFloat(),
|
||||
textColorMircIndex = o.optInt("textColorMircIndex", 0),
|
||||
fontSize = o.optDouble("fontSize", 14.0).toFloat(),
|
||||
fontId = o.optString("fontId", "monospace"),
|
||||
showUserList = o.optBoolean("showUserList", true),
|
||||
mentionHighlightColorArgb = o.optLong("mentionHighlightColorArgb", 0x40FFA500L).toInt(),
|
||||
nickColorsEnabled = o.optBoolean("nickColorsEnabled", true),
|
||||
@@ -138,6 +142,7 @@ class WindowPrefsRepository(rootDir: File) {
|
||||
put("backgroundAlpha", settings.backgroundAlpha)
|
||||
put("textColorMircIndex", settings.textColorMircIndex)
|
||||
put("fontSize", settings.fontSize)
|
||||
put("fontId", settings.fontId)
|
||||
put("showUserList", settings.showUserList)
|
||||
put("mentionHighlightColorArgb", settings.mentionHighlightColorArgb)
|
||||
put("nickColorsEnabled", settings.nickColorsEnabled)
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
package ui
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.platform.Font
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Fonts offered in each window's settings. Stored in window_prefs.json by [id], so the ids
|
||||
* must never change once shipped.
|
||||
*
|
||||
* Two kinds:
|
||||
* - Windows fonts (Segoe UI, Tahoma, Tw Cen MT) are Microsoft-licensed, so they are NOT
|
||||
* bundled. They are loaded straight out of the Windows font folders at runtime and only
|
||||
* listed when the file is actually there (Tw Cen MT only exists if Office is installed).
|
||||
* - Rounded fonts (Nunito, Quicksand, Varela Round) are SIL OFL licensed and bundled in
|
||||
* src/main/resources/fonts with their license files.
|
||||
*
|
||||
* Anything missing or failing to load falls back to Monospace, so a font uninstalled after
|
||||
* being picked can never crash a window.
|
||||
*/
|
||||
data class FontOption(val id: String, val label: String, val family: FontFamily)
|
||||
|
||||
object AppFonts {
|
||||
const val DEFAULT_ID = "monospace"
|
||||
|
||||
private val fontDirs: List<File> = buildList {
|
||||
add(File(System.getenv("WINDIR") ?: "C:\\Windows", "Fonts"))
|
||||
System.getenv("LOCALAPPDATA")?.let { add(File(it, "Microsoft\\Windows\\Fonts")) }
|
||||
}
|
||||
|
||||
/** Case-insensitive lookup across the system and per-user font folders. */
|
||||
private fun findSystemFont(name: String): File? {
|
||||
for (dir in fontDirs) {
|
||||
val direct = File(dir, name)
|
||||
if (direct.isFile) return direct
|
||||
dir.listFiles()?.firstOrNull { it.name.equals(name, ignoreCase = true) }?.let { return it }
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
private fun systemFamily(regular: String, bold: String?): FontFamily? {
|
||||
val reg = findSystemFont(regular) ?: return null
|
||||
return try {
|
||||
val fonts = mutableListOf(Font(reg, FontWeight.Normal))
|
||||
bold?.let { findSystemFont(it) }?.let { fonts.add(Font(it, FontWeight.Bold)) }
|
||||
FontFamily(fonts)
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
private fun bundledFamily(regular: String, bold: String?): FontFamily? = try {
|
||||
val fonts = mutableListOf(Font("fonts/$regular", FontWeight.Normal))
|
||||
bold?.let { fonts.add(Font("fonts/$it", FontWeight.Bold)) }
|
||||
FontFamily(fonts)
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
|
||||
/** Built once at startup; the font folders don't change while wIRC is running. */
|
||||
val options: List<FontOption> by lazy {
|
||||
buildList {
|
||||
add(FontOption(DEFAULT_ID, "Monospace", FontFamily.Monospace))
|
||||
systemFamily("segoeui.ttf", "segoeuib.ttf")?.let { add(FontOption("segoe-ui", "Segoe UI", it)) }
|
||||
systemFamily("tahoma.ttf", "tahomabd.ttf")?.let { add(FontOption("tahoma", "Tahoma", it)) }
|
||||
systemFamily("TCM_____.TTF", "TCB_____.TTF")?.let { add(FontOption("tw-cen-mt", "Tw Cen MT", it)) }
|
||||
bundledFamily("Nunito-Regular.ttf", "Nunito-Bold.ttf")?.let { add(FontOption("nunito", "Nunito (rounded)", it)) }
|
||||
bundledFamily("Quicksand-Regular.ttf", "Quicksand-Bold.ttf")?.let { add(FontOption("quicksand", "Quicksand (rounded)", it)) }
|
||||
bundledFamily("VarelaRound-Regular.ttf", null)?.let { add(FontOption("varela-round", "Varela Round (rounded)", it)) }
|
||||
}
|
||||
}
|
||||
|
||||
fun familyFor(id: String): FontFamily =
|
||||
options.firstOrNull { it.id == id }?.family ?: FontFamily.Monospace
|
||||
}
|
||||
|
||||
/**
|
||||
* The font list used in both the channel-window settings and wIRC main's Font dialog. Each
|
||||
* name is drawn in its own font as a live preview; plain square-cornered rows, no dropdown.
|
||||
*/
|
||||
@Composable
|
||||
fun FontPickerList(selectedId: String, textColor: Color, onPick: (String) -> Unit) {
|
||||
val effectiveId = if (AppFonts.options.any { it.id == selectedId }) selectedId else AppFonts.DEFAULT_ID
|
||||
Column {
|
||||
AppFonts.options.forEach { option ->
|
||||
Text(
|
||||
text = option.label,
|
||||
color = textColor,
|
||||
fontFamily = option.family,
|
||||
fontSize = 15.sp,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(if (option.id == effectiveId) Color.White.copy(alpha = 0.18f) else Color.Transparent)
|
||||
.clickable { onPick(option.id) }
|
||||
.padding(horizontal = 6.dp, vertical = 4.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -195,6 +195,7 @@ fun WindowScope.ChannelScreen(
|
||||
onAlphaChange: (Float) -> Unit,
|
||||
onTextColorChange: (Int) -> Unit,
|
||||
onFontSizeChange: (Float) -> Unit,
|
||||
onFontChange: (String) -> Unit,
|
||||
onShowUserListChange: (Boolean) -> Unit,
|
||||
onNickColorsToggle: (Boolean) -> Unit,
|
||||
onMentionHighlightColorChange: (Int) -> Unit,
|
||||
@@ -370,7 +371,7 @@ fun WindowScope.ChannelScreen(
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(channelName, color = textColor, fontFamily = FontFamily.Monospace, style = MaterialTheme.typography.labelSmall)
|
||||
Text(channelName, color = textColor, fontFamily = AppFonts.familyFor(displaySettings.fontId), style = MaterialTheme.typography.labelSmall)
|
||||
Row {
|
||||
FadingTitleBarButton(onClick = { onShowUserListChange(!displaySettings.showUserList) }) {
|
||||
Icon(Icons.Default.Person, contentDescription = "Toggle user list", tint = textColor, modifier = Modifier.size(16.dp))
|
||||
@@ -420,6 +421,7 @@ fun WindowScope.ChannelScreen(
|
||||
onAlphaChange = onAlphaChange,
|
||||
onTextColorChange = onTextColorChange,
|
||||
onFontSizeChange = onFontSizeChange,
|
||||
onFontChange = onFontChange,
|
||||
onNickColorsToggle = onNickColorsToggle,
|
||||
onMentionHighlightColorChange = onMentionHighlightColorChange,
|
||||
onShowImagePreviewsChange = onShowImagePreviewsChange
|
||||
@@ -453,7 +455,7 @@ fun WindowScope.ChannelScreen(
|
||||
Text(
|
||||
text = (if (user.isOp) "@" else if (user.isVoice) "+" else "") + user.nick,
|
||||
color = textColor,
|
||||
fontFamily = FontFamily.Monospace,
|
||||
fontFamily = AppFonts.familyFor(displaySettings.fontId),
|
||||
fontSize = displaySettings.fontSize.sp,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@@ -491,7 +493,7 @@ fun WindowScope.ChannelScreen(
|
||||
onValueChange = { input = it },
|
||||
singleLine = true,
|
||||
textStyle = androidx.compose.ui.text.TextStyle(
|
||||
fontFamily = FontFamily.Monospace,
|
||||
fontFamily = AppFonts.familyFor(displaySettings.fontId),
|
||||
color = textColor,
|
||||
fontSize = displaySettings.fontSize.sp
|
||||
),
|
||||
@@ -840,11 +842,11 @@ fun MessageScrollback(
|
||||
// then converts that now-stale pixel value using the NEW density, so the
|
||||
// two silently disagreed until the window (and this remember scope) was
|
||||
// recreated by closing and reopening it.
|
||||
val lineHeightPx = remember(displaySettings.fontSize, density) {
|
||||
val lineHeightPx = remember(displaySettings.fontSize, displaySettings.fontId, density) {
|
||||
textMeasurer.measure(
|
||||
text = "Mg",
|
||||
style = androidx.compose.ui.text.TextStyle(
|
||||
fontFamily = FontFamily.Monospace,
|
||||
fontFamily = AppFonts.familyFor(displaySettings.fontId),
|
||||
fontSize = displaySettings.fontSize.sp
|
||||
)
|
||||
).size.height
|
||||
@@ -875,7 +877,7 @@ fun MessageScrollback(
|
||||
// second independent one.
|
||||
|
||||
val textStyle = androidx.compose.ui.text.TextStyle(
|
||||
fontFamily = FontFamily.Monospace,
|
||||
fontFamily = AppFonts.familyFor(displaySettings.fontId),
|
||||
fontSize = displaySettings.fontSize.sp
|
||||
)
|
||||
val selection = selectionState.selection
|
||||
@@ -1404,6 +1406,7 @@ private fun WindowSettingsPanel(
|
||||
onAlphaChange: (Float) -> Unit,
|
||||
onTextColorChange: (Int) -> Unit,
|
||||
onFontSizeChange: (Float) -> Unit,
|
||||
onFontChange: (String) -> Unit,
|
||||
onNickColorsToggle: (Boolean) -> Unit,
|
||||
onMentionHighlightColorChange: (Int) -> Unit,
|
||||
onShowImagePreviewsChange: (Boolean) -> Unit
|
||||
@@ -1441,6 +1444,9 @@ private fun WindowSettingsPanel(
|
||||
colors = sliderColors
|
||||
)
|
||||
Spacer(Modifier.height(4.dp))
|
||||
Text("Font:", color = textColor, style = MaterialTheme.typography.bodySmall)
|
||||
FontPickerList(displaySettings.fontId, textColor, onFontChange)
|
||||
Spacer(Modifier.height(4.dp))
|
||||
Text("Text color:", color = textColor, style = MaterialTheme.typography.bodySmall)
|
||||
FlowSwatchGrid(
|
||||
selected = displaySettings.textColorMircIndex,
|
||||
|
||||
@@ -181,6 +181,9 @@ fun ChannelWindow(
|
||||
onFontSizeChange = { size ->
|
||||
scope.launch(Dispatchers.IO) { prefsRepo.setFontSize(bufferKey.storageId(), size) }
|
||||
},
|
||||
onFontChange = { id ->
|
||||
scope.launch(Dispatchers.IO) { prefsRepo.setFontId(bufferKey.storageId(), id) }
|
||||
},
|
||||
onShowUserListChange = { show ->
|
||||
scope.launch(Dispatchers.IO) { prefsRepo.setShowUserList(bufferKey.storageId(), show) }
|
||||
},
|
||||
|
||||
@@ -43,8 +43,10 @@ fun MainScreen(
|
||||
displaySettings: WindowDisplaySettings,
|
||||
onOpenChannel: (serverId: String, channelName: String) -> Unit,
|
||||
onExitApp: () -> Unit,
|
||||
onUnreadChange: (Int) -> Unit
|
||||
onUnreadChange: (Int) -> Unit,
|
||||
onFontChange: (String) -> Unit
|
||||
) {
|
||||
var showFontDialog by remember { mutableStateOf(false) }
|
||||
var servers by remember { mutableStateOf(repo.loadAll()) }
|
||||
var showAddDialog by remember { mutableStateOf(false) }
|
||||
var editingServer by remember { mutableStateOf<ServerConfig?>(null) }
|
||||
@@ -87,6 +89,12 @@ fun MainScreen(
|
||||
Text("+ Add Server")
|
||||
}
|
||||
Spacer(Modifier.width(8.dp))
|
||||
// Font for the server messages box (channel windows pick theirs in their own
|
||||
// settings).
|
||||
TextButton(onClick = { showFontDialog = true }) {
|
||||
Text("Font")
|
||||
}
|
||||
Spacer(Modifier.width(8.dp))
|
||||
// Disconnects every server and terminates the process. (A bare "/quit" in a
|
||||
// channel window only disconnects that window's server.)
|
||||
TextButton(onClick = onExitApp) {
|
||||
@@ -187,6 +195,25 @@ fun MainScreen(
|
||||
)
|
||||
}
|
||||
|
||||
if (showFontDialog) {
|
||||
DialogWindow(
|
||||
onCloseRequest = { showFontDialog = false },
|
||||
title = "wIRC main font",
|
||||
state = rememberDialogState(size = DpSize(300.dp, 360.dp)),
|
||||
resizable = true
|
||||
) {
|
||||
MaterialTheme(colorScheme = colorScheme) {
|
||||
Surface {
|
||||
Column(modifier = Modifier.fillMaxSize().padding(8.dp).verticalScroll(rememberScrollState())) {
|
||||
Text("Server messages font:", color = textColor, style = MaterialTheme.typography.bodySmall)
|
||||
Spacer(Modifier.height(4.dp))
|
||||
FontPickerList(displaySettings.fontId, textColor, onFontChange)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (showAddDialog) {
|
||||
ServerEditDialog(
|
||||
existing = editingServer,
|
||||
|
||||
Reference in New Issue
Block a user