Render post in correct font

This commit is contained in:
Angelo Stavrow 2020-11-23 14:13:15 -05:00
parent 99551b9a1d
commit c2e124de31
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
3 changed files with 35 additions and 28 deletions

View File

@ -15,7 +15,7 @@ struct MacEditorTextView: NSViewRepresentable {
@Binding var text: String
var isFirstResponder: Bool = false
var isEditable: Bool = true
var font: NSFont? = .systemFont(ofSize: 14, weight: .regular)
var font: NSFont? = NSFont(name: PostAppearance.serif.rawValue, size: 17)
var onEditingChanged: () -> Void = {}
var onCommit: () -> Void = {}

View File

@ -6,14 +6,12 @@ struct PostEditorView: View {
@ObservedObject var post: WFAPost
@State private var isHovering: Bool = false
@State private var updatingTitleFromServer: Bool = false
@State private var updatingBodyFromServer: Bool = false
@State private var updatingFromServer: Bool = false
var body: some View {
PostTextEditingView(
post: post,
updatingTitleFromServer: $updatingTitleFromServer,
updatingBodyFromServer: $updatingBodyFromServer
updatingFromServer: $updatingFromServer
)
.padding()
.background(Color(NSColor.controlBackgroundColor))

View File

@ -2,9 +2,7 @@ import SwiftUI
struct PostTextEditingView: View {
@ObservedObject var post: WFAPost
@Binding var updatingTitleFromServer: Bool
@Binding var updatingBodyFromServer: Bool
@State private var isHovering: Bool = false
@Binding var updatingFromServer: Bool
@State private var appearance: PostAppearance = .serif
@State private var combinedText = ""
@ -58,28 +56,40 @@ struct PostTextEditingView: View {
.padding(.horizontal, 5)
.font(.custom(appearance.rawValue, size: 17, relativeTo: .body))
}
MacEditorTextView(
text: $combinedText,
isFirstResponder: combinedText.isEmpty,
isEditable: true,
font: NSFont(name: appearance.rawValue, size: 17),
onEditingChanged: onEditingChanged,
onCommit: onCommit,
onTextChange: onTextChange
)
if post.appearance == "sans" {
MacEditorTextView(
text: $combinedText,
isFirstResponder: combinedText.isEmpty,
isEditable: true,
font: NSFont(name: "OpenSans-Regular", size: 17),
onEditingChanged: onEditingChanged,
onCommit: onCommit,
onTextChange: onTextChange
)
} else if post.appearance == "wrap" || post.appearance == "mono" || post.appearance == "code" {
MacEditorTextView(
text: $combinedText,
isFirstResponder: combinedText.isEmpty,
isEditable: true,
font: NSFont(name: "Hack-Regular", size: 17),
onEditingChanged: onEditingChanged,
onCommit: onCommit,
onTextChange: onTextChange
)
} else {
MacEditorTextView(
text: $combinedText,
isFirstResponder: combinedText.isEmpty,
isEditable: true,
font: NSFont(name: "Lora-Regular", size: 17),
onEditingChanged: onEditingChanged,
onCommit: onCommit,
onTextChange: onTextChange
)
}
}
.background(Color(NSColor.controlBackgroundColor))
.onAppear(perform: {
switch post.appearance {
case "sans":
self.appearance = .sans
case "wrap", "mono", "code":
self.appearance = .mono
default:
self.appearance = .serif
}
print("Font: \(appearance.rawValue)")
if post.title.isEmpty {
self.combinedText = post.body
} else {
@ -93,7 +103,6 @@ struct PostTextEditingView: View {
}
private func onTextChange(_ text: String) {
print("onTextChange fired")
extractTitle(text)
}