More robust dictionary search feature, styling tweaks for widgets
This commit is contained in:
parent
5999cc3533
commit
e893a04e13
@ -62,9 +62,11 @@ struct Toki_Trainer_WidgetsEntryView : View {
|
|||||||
Text(entry.word)
|
Text(entry.word)
|
||||||
.foregroundColor(Color("FontColorTitle"))
|
.foregroundColor(Color("FontColorTitle"))
|
||||||
.font(.title)
|
.font(.title)
|
||||||
|
.frame(maxWidth: .infinity, alignment: .topLeading)
|
||||||
.padding(8)
|
.padding(8)
|
||||||
Text(entry.definition)
|
Text(entry.definition)
|
||||||
.foregroundColor(Color("FontColorSubtitle"))
|
.foregroundColor(Color("FontColorSubtitle"))
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
.padding(8)
|
.padding(8)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,12 +7,12 @@
|
|||||||
<key>Toki Trainer WidgetsExtension.xcscheme_^#shared#^_</key>
|
<key>Toki Trainer WidgetsExtension.xcscheme_^#shared#^_</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>0</integer>
|
<integer>1</integer>
|
||||||
</dict>
|
</dict>
|
||||||
<key>Toki Trainer.xcscheme_^#shared#^_</key>
|
<key>Toki Trainer.xcscheme_^#shared#^_</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>1</integer>
|
<integer>0</integer>
|
||||||
</dict>
|
</dict>
|
||||||
</dict>
|
</dict>
|
||||||
</dict>
|
</dict>
|
||||||
|
@ -40,6 +40,32 @@ class TokiDictionaryViewModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func filterDictionaryEnglishMode(_ input: String) {
|
||||||
|
dictionary = []
|
||||||
|
|
||||||
|
for value in fullDictionary {
|
||||||
|
|
||||||
|
var entryMatch = false
|
||||||
|
|
||||||
|
// Check if word matches toki pona form, even partially
|
||||||
|
if value.word.hasPrefix(input) {
|
||||||
|
entryMatch = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if any part of the word definitions match in English, even partially
|
||||||
|
for definition in value.definitions {
|
||||||
|
if definition.definition.contains(input) {
|
||||||
|
entryMatch = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add to dictionary
|
||||||
|
if entryMatch == true {
|
||||||
|
dictionary.append(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func translatePhrase(_ input: String) {
|
func translatePhrase(_ input: String) {
|
||||||
dictionary = []
|
dictionary = []
|
||||||
translatedDictionary = []
|
translatedDictionary = []
|
||||||
|
@ -10,8 +10,8 @@ import SwiftUI
|
|||||||
struct DictionaryView: View {
|
struct DictionaryView: View {
|
||||||
@ObservedObject var tokiDictViewModel = TokiDictionaryViewModel()
|
@ObservedObject var tokiDictViewModel = TokiDictionaryViewModel()
|
||||||
|
|
||||||
@State var tokiInput: String = ""
|
@State private var tokiInput: String = ""
|
||||||
@State var selectedPartOfSpeech: String?
|
@State private var selectedPartOfSpeech: String?
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack {
|
VStack {
|
||||||
@ -30,7 +30,7 @@ struct DictionaryView: View {
|
|||||||
PartsOfSpeechView(selectedPartOfSpeech: selectedPOS)
|
PartsOfSpeechView(selectedPartOfSpeech: selectedPOS)
|
||||||
}
|
}
|
||||||
.onChange(of: tokiInput) { newValue in
|
.onChange(of: tokiInput) { newValue in
|
||||||
tokiDictViewModel.filterDictionary(newValue)
|
tokiDictViewModel.filterDictionaryEnglishMode(newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -39,6 +39,6 @@ struct DictionaryView: View {
|
|||||||
struct DictionaryView_Previews: PreviewProvider {
|
struct DictionaryView_Previews: PreviewProvider {
|
||||||
|
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
DictionaryView(selectedPartOfSpeech: "n").previewLayout(.sizeThatFits).environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
|
DictionaryView().previewLayout(.sizeThatFits).environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,14 +15,14 @@ struct TranslatorView: View {
|
|||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack {
|
VStack {
|
||||||
Button(action: changeTranslationDirection) {
|
// Button(action: changeTranslationDirection) {
|
||||||
// TODO: This needs to actually switch how the lookup happens
|
// #warning("This needs to actually switch how the lookup happens")
|
||||||
if translateToTokiPona == true {
|
// if translateToTokiPona == true {
|
||||||
LanguageDirectionView(from: "English", to: "Toki Pona", fromColor: .blue, toColor: .cyan)
|
// LanguageDirectionView(from: "English", to: "Toki Pona", fromColor: .blue, toColor: .cyan)
|
||||||
} else {
|
// } else {
|
||||||
LanguageDirectionView(from: "Toki Pona", to: "English", fromColor: .cyan, toColor: .blue)
|
// LanguageDirectionView(from: "Toki Pona", to: "English", fromColor: .cyan, toColor: .blue)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
TextField("Enter Toki Pona Word or Phrase", text: $tokiInput)
|
TextField("Enter Toki Pona Word or Phrase", text: $tokiInput)
|
||||||
.multilineTextAlignment(.center)
|
.multilineTextAlignment(.center)
|
||||||
.textInputAutocapitalization(.never)
|
.textInputAutocapitalization(.never)
|
||||||
|
Loading…
Reference in New Issue
Block a user