damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 14ba33674b914db5afc515d33a4e5310382e894d
parent c0f4e3fe037a5b546e8fecc65d6dd19470b40341
Author: William Casarin <jb55@jb55.com>
Date:   Thu,  3 Aug 2023 18:38:20 -0700

setting: adjustable font size for jack the zapper

Changelog-Added: Adjustable font size

Diffstat:
Mdamus/Components/TranslateView.swift | 6+++---
Mdamus/Models/UserSettingsStore.swift | 5++++-
Mdamus/TestData.swift | 5+++--
Mdamus/Util/Router.swift | 2+-
Mdamus/Views/EventView.swift | 12++++++------
Mdamus/Views/NoteContentView.swift | 8+++++---
Mdamus/Views/Profile/EventProfileName.swift | 2+-
Mdamus/Views/Settings/AppearanceSettingsView.swift | 29++++++++++++++++++++++++++++-
8 files changed, 51 insertions(+), 18 deletions(-)

diff --git a/damus/Components/TranslateView.swift b/damus/Components/TranslateView.swift @@ -42,7 +42,7 @@ struct TranslateView: View { .translate_button_style() } - func TranslatedView(lang: String?, artifacts: NoteArtifactsSeparated) -> some View { + func TranslatedView(lang: String?, artifacts: NoteArtifactsSeparated, font_size: Double) -> some View { return VStack(alignment: .leading) { let translatedFromLanguageString = String(format: NSLocalizedString("Translated from %@", comment: "Button to indicate that the note has been translated from a different language."), lang ?? "ja") Text(translatedFromLanguageString) @@ -54,7 +54,7 @@ struct TranslateView: View { SelectableText(attributedString: artifacts.content.attributed, size: self.size) } else { artifacts.content.text - .font(eventviewsize_to_font(self.size)) + .font(eventviewsize_to_font(self.size, font_size: font_size)) } } } @@ -98,7 +98,7 @@ struct TranslateView: View { Text("") case .translated(let translated): let languageName = Locale.current.localizedString(forLanguageCode: translated.language) - TranslatedView(lang: languageName, artifacts: translated.artifacts) + TranslatedView(lang: languageName, artifacts: translated.artifacts, font_size: damus_state.settings.font_size) case .not_needed: Text("") } diff --git a/damus/Models/UserSettingsStore.swift b/damus/Models/UserSettingsStore.swift @@ -127,7 +127,10 @@ class UserSettingsStore: ObservableObject { @Setting(key: "repost_notification", default_value: true) var repost_notification: Bool - + + @Setting(key: "font_size", default_value: 1.0) + var font_size: Double + @Setting(key: "dm_notification", default_value: true) var dm_notification: Bool diff --git a/damus/TestData.swift b/damus/TestData.swift @@ -20,10 +20,11 @@ let test_keypair_full = test_keypair.to_full()! let test_event_holder = EventHolder(events: [], incoming: [test_note]) +let jack_keypair = Keypair(pubkey: bech32_pubkey_decode("npub1sg6plzptd64u62a878hep2kev88swjh3tw00gjsfl8f237lmu63q0uf63m")!, privkey: nil) let test_note = NostrEvent( - content: "hello there https://jb55.com/s/Oct12-150217.png https://jb55.com/red-me.jpg cool", - keypair: test_keypair, + content: "Nostr is the super app. Because it’s actually an ecosystem of apps, all of which make each other better. People haven’t grasped that yet. They will when it’s more accessible and onboarding is more straightforward and intuitive.", + keypair: jack_keypair, createdAt: UInt32(Date().timeIntervalSince1970 - 100) )! diff --git a/damus/Util/Router.swift b/damus/Util/Router.swift @@ -75,7 +75,7 @@ enum Route: Hashable { case .KeySettings(let keypair): KeySettingsView(keypair: keypair) case .AppearanceSettings(let settings): - AppearanceSettingsView(settings: settings) + AppearanceSettingsView(damus_state: damusState, settings: settings) case .NotificationSettings(let settings): NotificationSettingsView(settings: settings) case .ZapSettings(let settings): diff --git a/damus/Views/EventView.swift b/damus/Views/EventView.swift @@ -102,18 +102,18 @@ func make_actionbar_model(ev: NoteId, damus: DamusState) -> ActionBarModel { return model } -func eventviewsize_to_font(_ size: EventViewKind) -> Font { +func eventviewsize_to_font(_ size: EventViewKind, font_size: Double) -> Font { switch size { case .small: - return .body + return Font.system(size: 12.0 * font_size) case .normal: - return .body + return Font.system(size: 17.0 * font_size) // Assuming .body is 17pt by default case .selected: - return .custom("selected", size: 21.0) + return .custom("selected", size: 21.0 * font_size) case .title: - return .title + return Font.system(size: 24.0 * font_size) // Assuming .title is 24pt by default case .subheadline: - return .subheadline + return Font.system(size: 14.0 * font_size) // Assuming .subheadline is 14pt by default } } diff --git a/damus/Views/NoteContentView.swift b/damus/Views/NoteContentView.swift @@ -33,7 +33,8 @@ struct NoteContentView: View { @ObservedObject var artifacts_model: NoteArtifactsModel @ObservedObject var preview_model: PreviewModel - + @ObservedObject var settings: UserSettingsStore + var note_artifacts: NoteArtifacts { return self.artifacts_model.state.artifacts ?? .separated(.just_content(event.get_content(damus_state.keypair.privkey))) } @@ -48,6 +49,7 @@ struct NoteContentView: View { let cached = damus_state.events.get_cache_data(event.id) self._preview_model = ObservedObject(wrappedValue: cached.preview_model) self._artifacts_model = ObservedObject(wrappedValue: cached.artifacts_model) + self._settings = ObservedObject(wrappedValue: damus_state.settings) } var truncate: Bool { @@ -72,10 +74,10 @@ struct NoteContentView: View { Group { if truncate { TruncatedText(text: content) - .font(eventviewsize_to_font(size)) + .font(eventviewsize_to_font(size, font_size: damus_state.settings.font_size)) } else { content.text - .font(eventviewsize_to_font(size)) + .font(eventviewsize_to_font(size, font_size: damus_state.settings.font_size)) } } } diff --git a/damus/Views/Profile/EventProfileName.swift b/damus/Views/Profile/EventProfileName.swift @@ -69,7 +69,7 @@ struct EventProfileName: View { Text(verbatim: "@\(both.username)") .foregroundColor(.gray) - .font(eventviewsize_to_font(size)) + .font(eventviewsize_to_font(size, font_size: damus_state.settings.font_size)) } /* diff --git a/damus/Views/Settings/AppearanceSettingsView.swift b/damus/Views/Settings/AppearanceSettingsView.swift @@ -8,12 +8,39 @@ import SwiftUI +struct ResizedEventPreview: View { + let damus_state: DamusState + @ObservedObject var settings: UserSettingsStore + + var body: some View { + EventView(damus: damus_state, event: test_note, pubkey: test_note.pubkey, options: [.wide, .no_action_bar]) + } +} + struct AppearanceSettingsView: View { + let damus_state: DamusState @ObservedObject var settings: UserSettingsStore @Environment(\.dismiss) var dismiss + var FontSize: some View { + VStack(alignment: .leading) { + Slider(value: $settings.font_size, in: 0.5...2.0, step: 0.1) { + Text("Font Size") + } + .padding() + + // Sample text to show how the font size would look + ResizedEventPreview(damus_state: damus_state, settings: settings) + + } + } + var body: some View { Form { + Section("Font Size") { + FontSize + } + // MARK: - Text Truncation Section(header: Text(NSLocalizedString("Text Truncation", comment: "Section header for damus text truncation user configuration"))) { Toggle(NSLocalizedString("Truncate timeline text", comment: "Setting to truncate text in timeline"), isOn: $settings.truncate_timeline_text) @@ -63,6 +90,6 @@ struct AppearanceSettingsView: View { struct TextFormattingSettings_Previews: PreviewProvider { static var previews: some View { - AppearanceSettingsView(settings: UserSettingsStore()) + AppearanceSettingsView(damus_state: test_damus_state(), settings: UserSettingsStore()) } }