@@ -73,6 +73,7 @@ struct ContentView: View {
7373 @State private var imagePickerSourceType : UIImagePickerController . SourceType = . photoLibrary
7474
7575 @State private var showingSettings = false
76+ @FocusState private var textFieldFocused : Bool
7677
7778 enum PickerType {
7879 case model
@@ -102,29 +103,46 @@ struct ContentView: View {
102103 VStack {
103104 if showingSettings {
104105 VStack ( spacing: 20 ) {
105- Form {
106- Section ( header: Text ( " Model and Tokenizer " )
107- . font ( . headline)
108- . foregroundColor ( . primary) ) {
106+ HStack {
107+ VStack ( spacing: 10 ) {
109108 Button ( action: { pickerType = . model } ) {
110- Label ( resourceManager. modelName == " " ? modelTitle : resourceManager. modelName, systemImage: " doc " )
109+ Label ( modelTitle, systemImage: " doc " )
110+ . lineLimit ( 1 )
111+ . truncationMode ( . middle)
112+ . frame ( maxWidth: 300 , alignment: . leading)
111113 }
112114 Button ( action: { pickerType = . tokenizer } ) {
113- Label ( resourceManager. tokenizerName == " " ? tokenizerTitle : resourceManager. tokenizerName, systemImage: " doc " )
115+ Label ( tokenizerTitle, systemImage: " doc " )
116+ . lineLimit ( 1 )
117+ . truncationMode ( . middle)
118+ . frame ( maxWidth: 300 , alignment: . leading)
114119 }
115120 }
121+ . padding ( )
122+ . background ( Color . gray. opacity ( 0.1 ) )
123+ . cornerRadius ( 10 )
124+ . fixedSize ( horizontal: true , vertical: false )
125+ Spacer ( )
116126 }
127+ . padding ( )
117128 }
118129 }
119130
120131 MessageListView ( messages: $messages)
121- . gesture (
132+ . simultaneousGesture (
122133 DragGesture ( ) . onChanged { value in
123134 if value. translation. height > 10 {
124- UIApplication . shared . sendAction ( #selector ( UIResponder . resignFirstResponder ) , to : nil , from : nil , for : nil )
135+ hideKeyboard ( )
125136 }
137+ showingSettings = false
138+ textFieldFocused = false
126139 }
127140 )
141+ . onTapGesture {
142+ showingSettings = false
143+ textFieldFocused = false
144+ }
145+
128146 HStack {
129147 Button ( action: {
130148 imagePickerSourceType = . photoLibrary
@@ -164,6 +182,11 @@ struct ContentView: View {
164182 . stroke ( isInputEnabled ? Color . blue : Color . gray, lineWidth: 1 )
165183 )
166184 . disabled ( !isInputEnabled)
185+ . focused ( $textFieldFocused)
186+ . onAppear { textFieldFocused = false }
187+ . onTapGesture {
188+ showingSettings = false
189+ }
167190
168191 Button ( action: isGenerating ? stop : generate) {
169192 Image ( systemName: isGenerating ? " stop.circle " : " arrowshape.up.circle.fill " )
@@ -185,7 +208,7 @@ struct ContentView: View {
185208 Button ( action: {
186209 showingSettings. toggle ( )
187210 } ) {
188- Image ( systemName: " gearshape " )
211+ Image ( systemName: " folder " )
189212 . imageScale ( . large)
190213 } ,
191214 trailing:
@@ -465,6 +488,10 @@ struct ContentView: View {
465488 case . tokenizer:
466489 resourceManager. tokenizerPath = url. path
467490 }
491+ if resourceManager. isModelValid && resourceManager. isTokenizerValid {
492+ showingSettings = false
493+ textFieldFocused = true
494+ }
468495 case . failure( let error) :
469496 withAnimation {
470497 messages. append ( Message ( type: . info, text: " Failed to select a file: \( error. localizedDescription) " ) )
0 commit comments