mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Render post in correct font
This commit is contained in:
parent
99551b9a1d
commit
c2e124de31
@ -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 = {}
|
||||
|
@ -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))
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user