Skip to content

Commit

Permalink
Make editor font size configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Desbeers committed Oct 5, 2023
1 parent cf17327 commit d4c8d0c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
1 change: 1 addition & 0 deletions Chord Provider/General/ChordProviderSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct ChordProviderSettings: Equatable, Codable {
var showChords: Bool = true
var showInlineDiagrams: Bool = false
var paging: Song.DisplayOptions.Paging = .asList
var editorFontSize: Int = 14
}

extension ChordProviderSettings {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ extension EditorView {
Label("More...", systemImage: "pencil")
}
)
Picker("Font Size:", selection: $appState.settings.editorFontSize) {
ForEach(12...24, id: \.self) { value in
Text("\(value)px")
.tag(value)
}
}
.labelsHidden()
.frame(maxWidth: 75)
}
.menuStyle(.button)
}
Expand Down
13 changes: 2 additions & 11 deletions Chord Provider/Views/EditorView/EditorView+rules.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ extension EditorView {
static let rules: [HighlightRule] = [
/// The rule for all lines
HighlightRule(pattern: NSRegularExpression.all, formattingRules: [
TextFormattingRule(key: .font, value: font(weight: .light)),
TextFormattingRule(key: .paragraphStyle, value: nsParagraphStyle)
]),
/// The rule for a chord
Expand All @@ -37,8 +36,7 @@ extension EditorView {
]),
/// The rule for a directive
HighlightRule(pattern: EditorView.directiveRegex, formattingRules: [
TextFormattingRule(key: .foregroundColor, value: SWIFTColor.systemTeal),
TextFormattingRule(key: .font, value: font(weight: .medium))
TextFormattingRule(key: .foregroundColor, value: SWIFTColor.systemTeal)
]),
/// The rule for the value of a directive
HighlightRule(pattern: EditorView.directiveValueRegex, formattingRules: [
Expand All @@ -53,15 +51,8 @@ extension EditorView {
/// The style of a paragraph in the editor
static let nsParagraphStyle: NSParagraphStyle = {
let style = NSMutableParagraphStyle()
style.lineHeightMultiple = 1.2
style.lineHeightMultiple = 1.5
style.headIndent = 10
return style
}()

/// The font for a line in the editor
/// - Parameter weight: The weight of a font
/// - Returns: A font declaration
static func font(weight: SWIFTFont.Weight) -> SWIFTFont {
return SWIFTFont.monospacedSystemFont(ofSize: 14, weight: weight)
}
}
6 changes: 6 additions & 0 deletions Chord Provider/Views/EditorView/EditorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import HighlightedTextEditor
struct EditorView: View {
/// The ChordPro document
@Binding var document: ChordProDocument
/// The app state
@EnvironmentObject var appState: AppState
/// The scene state
@EnvironmentObject var sceneState: SceneState
/// Show a directive sheet
Expand Down Expand Up @@ -90,6 +92,10 @@ struct EditorView: View {
#endif
sceneState.textView = editor.textView
}
editor.textView.font = SWIFTFont.monospacedSystemFont(
ofSize: Double(appState.settings.editorFontSize),
weight: .regular
)
}
}
}
Expand Down

0 comments on commit d4c8d0c

Please sign in to comment.