@@ -9,6 +9,19 @@ import SwiftUI
99import ClassDump
1010
1111struct RuntimeObjectDetail : View {
12+ // influenced by
13+ // https://developer.apple.com/design/human-interface-guidelines/typography
14+ private static var defaultFontSize : Int {
15+ #if os(iOS) || os(visionOS)
16+ 16
17+ #elseif os(macOS)
18+ 13
19+ #else
20+ #warning("Unknown platform")
21+ 12
22+ #endif
23+ }
24+
1225 let type : RuntimeObjectType
1326
1427 @State private var stripProtocolConformance : Bool = false
@@ -17,6 +30,8 @@ struct RuntimeObjectDetail: View {
1730 @State private var stripSynthesized : Bool = true
1831 @State private var addSymbolImageComments : Bool = false
1932
33+ @AppStorage ( " code_font_size " ) private var fontSize : Int = Self . defaultFontSize
34+
2035 private var generationOptions : CDGenerationOptions {
2136 let options : CDGenerationOptions = . init( )
2237 options. stripProtocolConformance = stripProtocolConformance
@@ -36,7 +51,7 @@ struct RuntimeObjectDetail: View {
3651 if let cls = NSClassFromString ( name) {
3752 let semanticString : CDSemanticString = CDClassModel ( with: cls)
3853 . semanticLines ( with: generationOptions)
39- SemanticStringView ( semanticString)
54+ SemanticStringView ( semanticString, fontSize : CGFloat ( fontSize ) )
4055 } else {
4156 Text ( " No class named \( Text ( name) . font ( . callout. monospaced ( ) ) ) found " )
4257 . scenePadding ( )
@@ -45,7 +60,7 @@ struct RuntimeObjectDetail: View {
4560 if let prtcl = NSProtocolFromString ( name) {
4661 let semanticString : CDSemanticString = CDProtocolModel ( with: prtcl)
4762 . semanticLines ( with: generationOptions)
48- SemanticStringView ( semanticString)
63+ SemanticStringView ( semanticString, fontSize : CGFloat ( fontSize ) )
4964 } else {
5065 Text ( " No protocol named \( Text ( name) . font ( . callout. monospaced ( ) ) ) found " )
5166 . scenePadding ( )
@@ -54,6 +69,8 @@ struct RuntimeObjectDetail: View {
5469 }
5570 . navigationTitle ( type. name)
5671 . toolbar {
72+ FontToolbarItem ( fontSize: $fontSize)
73+
5774 ToolbarItem {
5875 Menu {
5976 Toggle ( " Strip protocol conformance " , isOn: $stripProtocolConformance)
@@ -74,3 +91,60 @@ struct RuntimeObjectDetail: View {
7491#endif
7592 }
7693}
94+
95+ private struct FontToolbarItem : ToolbarContent {
96+ @Binding var fontSize : Int
97+
98+ private var sizeDescription : String {
99+ fontSize. formatted ( . number)
100+ }
101+
102+ private var smallerButton : some View {
103+ Button ( " Smaller " , systemImage: " textformat.size.smaller " ) {
104+ guard fontSize > 4 else { return }
105+ fontSize -= 1
106+ }
107+ }
108+
109+ private var largerButton : some View {
110+ Button ( " Larger " , systemImage: " textformat.size.larger " ) {
111+ guard fontSize < 28 else { return }
112+ fontSize += 1
113+ }
114+ }
115+
116+ private func sizeControlGroup( withDescription: Bool ) -> some View {
117+ ControlGroup ( " Font Size " , systemImage: " textformat.size " ) {
118+ smallerButton
119+ if withDescription {
120+ Text ( sizeDescription)
121+ }
122+ largerButton
123+ }
124+ }
125+
126+ var body : some ToolbarContent {
127+ ToolbarItem {
128+ #if os(iOS) || os(visionOS)
129+ if #available( iOS 16 . 4 , * ) {
130+ Menu {
131+ sizeControlGroup ( withDescription: true )
132+ . controlGroupStyle ( . compactMenu)
133+ } label: {
134+ Label ( " Font " , systemImage: " textformat.size " )
135+ }
136+ . menuActionDismissBehavior ( . disabled)
137+ } else {
138+ Menu {
139+ sizeControlGroup ( withDescription: true )
140+ } label: {
141+ Label ( " Font " , systemImage: " textformat.size " )
142+ }
143+ }
144+ #else
145+ sizeControlGroup ( withDescription: false )
146+ . controlGroupStyle ( . navigation)
147+ #endif
148+ }
149+ }
150+ }
0 commit comments