Fix font field height

This commit is contained in:
1024jp 2024-05-30 12:34:52 +09:00
parent d16b0031b7
commit 087f01a42e
2 changed files with 7 additions and 10 deletions

View File

@ -47,8 +47,9 @@ struct AntialiasingText: NSViewRepresentable {
let nsView = AntialiasingTextField(string: self.text)
nsView.isEditable = false
nsView.isSelectable = false
nsView.frame.size.height = 22
nsView.alignment = .center
nsView.lineBreakMode = .byTruncatingMiddle
nsView.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
// keep initial field height
nsView.heightAnchor.constraint(equalToConstant: nsView.frame.height).isActive = true
@ -65,12 +66,6 @@ struct AntialiasingText: NSViewRepresentable {
}
func sizeThatFits(_ proposal: ProposedViewSize, nsView: NSTextField, context: Context) -> CGSize? {
proposal.replacingUnspecifiedDimensions()
}
/// Sets whether disables the antialias.
///
/// - Parameter disabled: The antialias state to change.
@ -131,7 +126,7 @@ private final class CenteringTextFieldCell: NSTextFieldCell {
var titleRect = super.titleRect(forBounds: rect)
let titleSize = self.attributedStringValue.size()
titleRect.origin.y = (rect.minY + (rect.height - titleSize.height) / 2).rounded(.down)
titleRect.origin.y = (rect.minY + (rect.height - titleSize.height) / 2).rounded(.up)
titleRect.size.height = rect.height - titleRect.origin.y
return titleRect
@ -157,6 +152,8 @@ private final class CenteringTextFieldCell: NSTextFieldCell {
AntialiasingText("Smooth Text")
.antialiasDisabled(false)
.font(nsFont: NSFont.monospacedSystemFont(ofSize: 8, weight: .regular))
.font(nsFont: .monospacedSystemFont(ofSize: 8, weight: .regular))
AntialiasingText("Very Long Long Long Long Long Long Text")
}.padding()
}

View File

@ -247,6 +247,6 @@ private extension AppearanceMode {
@State var antialias = false
@State var ligature = false
return FontSettingView(data: .constant(Data()), fallback: NSFont.systemFont(ofSize: 0), antialias: $antialias, ligature: $ligature)
return FontSettingView(data: .constant(Data()), fallback: .systemFont(ofSize: 0), antialias: $antialias, ligature: $ligature)
.padding()
}