fix(panel): draggable header and configurable translation text size

Add a native AppKit drag grip to the non-activating panel header; it accepts the first mouse and calls performDrag, so the panel can be moved before it becomes key. Keep a moved position while the panel stays visible and only recenter near the cursor when it is shown again (DeepL-like transient position).

Add persisted translationFontSize (default 17 pt, range 12–28) to AppSettings and PanelConfiguration, apply it to the translation text, and expose a native Settings stepper. Add English/German strings and AppSettings clamp/round-trip tests.

Verified: make verify green; synthetic double-copy opened the panel, dragging the grip moved the window, and a 22 pt capture showed the larger translation text.
This commit is contained in:
schihei committed 2026-11-26 14:35:34 +01:00
1 parent 2cce12ff17
commit 40733473c5
12 files changed
+98 -5

No files matched your search

@@ -59,6 +59,8 @@ public struct AppSettings: Codable, Sendable, Equatable {
public var autoCopy: Bool
/// Show the source preview in the panel.
public var showSourcePreview: Bool
/// Translation text size in points (12–28).
public var translationFontSize: Int
/// Reflect the login-item setting.
public var launchAtLogin: Bool
/// Keep the last translation in memory for the panel.
@@ -91,6 +93,7 @@ public struct AppSettings: Codable, Sendable, Equatable {
promptVariantPolicy = .defaultOnly
autoCopy = false
showSourcePreview = true
translationFontSize = 17
launchAtLogin = false
keepRecentTranslationInMemory = true
hasCompletedOnboarding = false
@@ -132,6 +135,7 @@ public struct AppSettings: Codable, Sendable, Equatable {
topP = min(max(topP, 0), 1)
topK = Self.clamp(topK, to: 1 ... 100)
repeatPenalty = min(max(repeatPenalty, 0.5), 2)
translationFontSize = Self.clamp(translationFontSize, to: 12 ... 28)
if !["5m", "30m", "1h", "0"].contains(keepModelLoaded) {
keepModelLoaded = HyMT3ModelPreset.defaultKeepAlive
}
@@ -161,6 +165,7 @@ public struct AppSettings: Codable, Sendable, Equatable {
let cjk: Int
let numCtx: Int
let numPredict: Int
let fontSize: Int
}
private struct DecodedSampling {
@@ -197,6 +202,11 @@ public struct AppSettings: Codable, Sendable, Equatable {
numPredict: clamp(
container.decodeIfPresent(Int.self, forKey: .numPredict) ?? defaults.numPredict,
to: 1 ... 8192
),
fontSize: clamp(
container.decodeIfPresent(Int.self, forKey: .translationFontSize)
?? defaults.translationFontSize,
to: 12 ... 28
)
)
}
@@ -225,7 +235,7 @@ public struct AppSettings: Codable, Sendable, Equatable {
case endpoint, allowRemoteEndpoint, model, fastModel, targetLanguage, recentTargetLanguages
case doubleCopyWindowMs, maxCharactersLatin, maxCharactersCJK, numCtx, numPredict
case temperature, topP, topK, repeatPenalty, keepModelLoaded, warmUpOnLaunch
case promptVariantPolicy, autoCopy, showSourcePreview, launchAtLogin
case promptVariantPolicy, autoCopy, showSourcePreview, translationFontSize, launchAtLogin
case keepRecentTranslationInMemory, hasCompletedOnboarding, settingsVersion
}
@@ -257,6 +267,7 @@ public struct AppSettings: Codable, Sendable, Equatable {
maxCharactersCJK = limits.cjk
numCtx = limits.numCtx
numPredict = limits.numPredict
translationFontSize = limits.fontSize
let sampling = try Self.decodeSampling(from: container, defaults: defaults)
temperature = sampling.temperature
topP = sampling.topP
@@ -307,6 +318,7 @@ public struct AppSettings: Codable, Sendable, Equatable {
try container.encode(promptVariantPolicy, forKey: .promptVariantPolicy)
try container.encode(autoCopy, forKey: .autoCopy)
try container.encode(showSourcePreview, forKey: .showSourcePreview)
try container.encode(translationFontSize, forKey: .translationFontSize)
try container.encode(launchAtLogin, forKey: .launchAtLogin)
try container.encode(keepRecentTranslationInMemory, forKey: .keepRecentTranslationInMemory)
try container.encode(hasCompletedOnboarding, forKey: .hasCompletedOnboarding)
@@ -28,6 +28,8 @@ public struct PanelConfiguration: Sendable, Equatable {
public var sampling: SamplingOptions
/// Whether to show the source preview.
public var showSourcePreview: Bool
/// Translation text size in points.
public var translationFontSize: Int
/// Recent targets, most recent first.
public var recentTargets: [ModelLanguage]
@@ -38,6 +40,7 @@ public struct PanelConfiguration: Sendable, Equatable {
keepAlive: String,
sampling: SamplingOptions = .publisherDefault,
showSourcePreview: Bool = true,
translationFontSize: Int = 17,
recentTargets: [ModelLanguage] = []
) {
self.target = target
@@ -45,6 +48,7 @@ public struct PanelConfiguration: Sendable, Equatable {
self.keepAlive = keepAlive
self.sampling = sampling
self.showSourcePreview = showSourcePreview
self.translationFontSize = translationFontSize
self.recentTargets = recentTargets
}
}
@@ -17,6 +17,7 @@ struct AppSettingsTests {
#expect(settings.maxCharactersLatin == 4000)
#expect(settings.maxCharactersCJK == 2000)
#expect(settings.numCtx == 8192)
#expect(settings.translationFontSize == 17)
#expect(!settings.autoCopy)
#expect(!settings.hasCompletedOnboarding)
}
@@ -28,6 +29,7 @@ struct AppSettingsTests {
settings.targetLanguage = "de"
settings.noteTarget(HyMT3Languages.german)
settings.temperature = 0.2
settings.translationFontSize = 22
settings.launchAtLogin = true
settings.hasCompletedOnboarding = true
@@ -82,6 +84,7 @@ struct AppSettingsTests {
"topK": 0,
"repeatPenalty": 9,
"keepModelLoaded": "forever",
"translationFontSize": 99,
"targetLanguage": "xx"
}
"""
@@ -96,6 +99,7 @@ struct AppSettingsTests {
#expect(decoded.topK == 1)
#expect(decoded.repeatPenalty == 2)
#expect(decoded.keepModelLoaded == HyMT3ModelPreset.defaultKeepAlive)
#expect(decoded.translationFontSize == 28)
#expect(HyMT3Languages.resolve(decoded.targetLanguage) != nil)
}
@@ -106,6 +110,7 @@ struct AppSettingsTests {
settings.topP = -1
settings.topK = 0
settings.keepModelLoaded = "forever"
settings.translationFontSize = 99
settings.autoCopy = true
settings.targetLanguage = "xx"
settings.sanitize()
@@ -115,6 +120,7 @@ struct AppSettingsTests {
#expect(settings.topP == 0)
#expect(settings.topK == 1)
#expect(settings.keepModelLoaded == HyMT3ModelPreset.defaultKeepAlive)
#expect(settings.translationFontSize == 28)
#expect(!settings.autoCopy)
#expect(HyMT3Languages.resolve(settings.targetLanguage) != nil)
}