From 7813eb86ca3e2ea13708bbf73470a19993445ee3 Mon Sep 17 00:00:00 2001 From: Andrew Skurlatov Date: Sat, 20 Jan 2024 21:29:39 +0100 Subject: [PATCH] refactor: refactoring dynamic table views --- Source/Views/DynamicTable.swift | 599 +++++++++++++------------------- 1 file changed, 238 insertions(+), 361 deletions(-) diff --git a/Source/Views/DynamicTable.swift b/Source/Views/DynamicTable.swift index 7345b19..10cbee3 100644 --- a/Source/Views/DynamicTable.swift +++ b/Source/Views/DynamicTable.swift @@ -5,21 +5,45 @@ struct DynamicTable: View { func Headers() -> some View { - HStack(spacing: 0) { - Text("") - .frame(minWidth: 87, minHeight: 0, maxHeight: .infinity, alignment: .center) - .padding(.vertical, 10) - .background(Color.gray.opacity(0.2)) - .border(Color.black, width: 1) + Group { + HStack(spacing: 0) { + Text("") + .frame(minWidth: 87, minHeight: 0, maxHeight: .infinity, alignment: .center) + .padding(.vertical, 10) + .background(Color.gray.opacity(0.2)) + .border(Color.black, width: 1) + + ForEach(Number.allCases, id: \.rawValue) { num in + if word.shouldShowNumber(number: num) { + let headerWidthValue = headerWidth(for: num) + Text(num.rawValue.capitalized) + .frame(minWidth: headerWidthValue, minHeight: 0, maxHeight: .infinity, alignment: .center) + .padding(.vertical, 10) + .background(Color.gray.opacity(0.2)) + .border(Color.black, width: 1) + } + } + } - ForEach(Number.allCases, id: \.rawValue) { num in - if word.shouldShowNumber(number: num) { - let headerWidthValue = headerWidth(for: num) - Text(num.rawValue.capitalized) - .frame(minWidth: headerWidthValue, minHeight: 0, maxHeight: .infinity, alignment: .center) - .padding(.vertical, 10) - .background(Color.gray.opacity(0.2)) - .border(Color.black, width: 1) + HStack(spacing: 0) { + Text("") + .frame(minWidth: 87, maxWidth: 87) + .padding(.vertical, 10) + .background(Color.gray.opacity(0.2)) + .border(Color.black, width: 1) + + ForEach(Number.allCases, id: \.rawValue) { num in + if word.shouldShowNumber(number: num) { + ForEach(Gender.allCases, id: \.rawValue) { gen in + if word.shouldShowGender(number: num, gen: gen) { + Text(gen.rawValue.capitalized) + .frame(minWidth: calcWidth(), maxWidth: calcWidth()) + .padding(.vertical, 10) + .background(Color.gray.opacity(0.2)) + .border(Color.black, width: 1) + } + } + } } } } @@ -47,29 +71,6 @@ struct DynamicTable: View { Headers() - // Sub-Headers - HStack(spacing: 0) { - Text("") - .frame(minWidth: 87, maxWidth: 87) - .padding(.vertical, 10) - .background(Color.gray.opacity(0.2)) - .border(Color.black, width: 1) - - ForEach(Number.allCases, id: \.rawValue) { num in - if word.shouldShowNumber(number: num) { - ForEach(Gender.allCases, id: \.rawValue) { gen in - if word.shouldShowGender(number: num, gen: gen) { - Text(gen.rawValue.capitalized) - .frame(minWidth: calcWidth(), maxWidth: calcWidth()) - .padding(.vertical, 10) - .background(Color.gray.opacity(0.2)) - .border(Color.black, width: 1) - } - } - } - } - } - // Rows ForEach(Case.allCases, id: \.rawValue) { c in HStack(spacing: 0) { @@ -105,330 +106,206 @@ struct DynamicTable: View { } } -// if word.type == .adjective { -// HStack(spacing: 0) { -// Text("") -// .frame(minWidth: 87, minHeight: 0, maxHeight: .infinity, alignment: .center) -// .padding(.vertical, 10) -// .background(Color.gray.opacity(0.2)) -// .border(Color.black, width: 1) -// -// Text("Weak Inflection") -// .frame(minWidth: 522, minHeight: 0, maxHeight: .infinity, alignment: .center) -// .padding(.vertical, 10) -// .background(Color.gray.opacity(0.2)) -// .border(Color.black, width: 1) -// } -// -// // Main Headers -// Headers() -// -// // Sub-Headers -// HStack(spacing: 0) { -// Text("") -// .frame(minWidth: 87, maxWidth: 87) -// .padding(.vertical, 10) -// .background(Color.gray.opacity(0.2)) -// .border(Color.black, width: 1) -// -// ForEach(Number.allCases, id: \.rawValue) { num in -// if num == .plural { -// Text("Any") -// .frame(minWidth: 261, maxWidth: 261) -// .padding(.vertical, 10) -// .background(Color.gray.opacity(0.2)) -// .border(Color.black, width: 1) -// } else { -// if word.shouldShowNumber(number: num) { -// ForEach(Gender.allCases, id: \.rawValue) { gen in -// if word.shouldShowGender(number: num, gen: gen) { -// Text(gen.rawValue.capitalized) -// .frame(minWidth: calcWidth(), maxWidth: calcWidth()) -// .padding(.vertical, 10) -// .background(Color.gray.opacity(0.2)) -// .border(Color.black, width: 1) -// } -// } -// } -// } -// } -// } -// -// // Rows -// ForEach(Case.allCases, id: \.rawValue) { c in -// HStack(spacing: 0) { -// Text(c.rawValue.capitalized) -// .frame(minWidth: 87, maxWidth: 87) -// .padding(.vertical, 10) -// .border(Color.black, width: 1) -// .background(Color.gray.opacity(0.2)) -// -// ForEach(Number.allCases, id: \.rawValue) { num in -// if num == .plural { -// if let weakAdjective = word.generateWeakAdjective(number: num, gender: .any, caseWeak: c) { -// Text(weakAdjective) -// .frame(minWidth: 261, maxWidth: 261) -// .padding(.vertical, 10) -// .border(Color.black, width: 1) -// } -// } else { -// if word.shouldShowNumber(number: num) { -// ForEach(Gender.allCases, id: \.rawValue) { gen in -// if word.shouldShowGender(number: num, gen: gen) { -// if let weakAdjective = word.generateWeakAdjective(number: num, gender: gen, caseWeak: c) { -// Text(weakAdjective) -// .frame(minWidth: calcWidth(), maxWidth: calcWidth()) -// .padding(.vertical, 10) -// .border(Color.black, width: 1) -// } -// } -// } -// } -// } -// } -// } -// } -// -// HStack(spacing: 0) { -// Text("") -// .frame(minWidth: 87, minHeight: 0, maxHeight: .infinity, alignment: .center) -// .padding(.vertical, 10) -// .background(Color.gray.opacity(0.2)) -// .border(Color.black, width: 1) -// -// Text("Comparative") -// .frame(minWidth: 522, minHeight: 0, maxHeight: .infinity, alignment: .center) -// .padding(.vertical, 10) -// .background(Color.gray.opacity(0.2)) -// .border(Color.black, width: 1) -// } -// -// // Main Headers -// Headers() -// -// // Sub-Headers -// HStack(spacing: 0) { -// Text("") -// .frame(minWidth: 87, maxWidth: 87) -// .padding(.vertical, 10) -// .background(Color.gray.opacity(0.2)) -// .border(Color.black, width: 1) -// -// ForEach(Number.allCases, id: \.rawValue) { num in -// if num == .plural { -// Text("Any") -// .frame(minWidth: 261, maxWidth: 261) -// .padding(.vertical, 10) -// .background(Color.gray.opacity(0.2)) -// .border(Color.black, width: 1) -// } else { -// if word.shouldShowNumber(number: num) { -// ForEach(Gender.allCases, id: \.rawValue) { gen in -// if word.shouldShowGender(number: num, gen: gen) { -// Text(gen.rawValue.capitalized) -// .frame(minWidth: calcWidth(), maxWidth: calcWidth()) -// .padding(.vertical, 10) -// .background(Color.gray.opacity(0.2)) -// .border(Color.black, width: 1) -// } -// } -// } -// } -// } -// } -// -// // Rows -// ForEach(Case.allCases, id: \.rawValue) { c in -// HStack(spacing: 0) { -// Text(c.rawValue.capitalized) -// .frame(minWidth: 87, maxWidth: 87) -// .padding(.vertical, 10) -// .border(Color.black, width: 1) -// .background(Color.gray.opacity(0.2)) -// -// ForEach(Number.allCases, id: \.rawValue) { num in -// if num == .plural { -// if let weakAdjective = word.generateComparativeAdjective(number: num, gender: .any, caseWeak: c) { -// Text(weakAdjective) -// .frame(minWidth: 261, maxWidth: 261) -// .padding(.vertical, 10) -// .border(Color.black, width: 1) -// } -// } else { -// if word.shouldShowNumber(number: num) { -// ForEach(Gender.allCases, id: \.rawValue) { gen in -// if word.shouldShowGender(number: num, gen: gen) { -// if let weakAdjective = word.generateComparativeAdjective(number: num, gender: gen, caseWeak: c) { -// Text(weakAdjective) -// .frame(minWidth: calcWidth(), maxWidth: calcWidth()) -// .padding(.vertical, 10) -// .border(Color.black, width: 1) -// } -// } -// } -// } -// } -// } -// } -// } -// -// HStack(spacing: 0) { -// Text("") -// .frame(minWidth: 87, minHeight: 0, maxHeight: .infinity, alignment: .center) -// .padding(.vertical, 10) -// .background(Color.gray.opacity(0.2)) -// .border(Color.black, width: 1) -// -// Text("Comparison Strong") -// .frame(minWidth: 522, minHeight: 0, maxHeight: .infinity, alignment: .center) -// .padding(.vertical, 10) -// .background(Color.gray.opacity(0.2)) -// .border(Color.black, width: 1) -// } -// -// // Main Headers -// Headers() -// -// // Sub-Headers -// HStack(spacing: 0) { -// Text("") -// .frame(minWidth: 87, maxWidth: 87) -// .padding(.vertical, 10) -// .background(Color.gray.opacity(0.2)) -// .border(Color.black, width: 1) -// -// ForEach(Number.allCases, id: \.rawValue) { num in -// if num == .plural { -// Text("Any") -// .frame(minWidth: 261, maxWidth: 261) -// .padding(.vertical, 10) -// .background(Color.gray.opacity(0.2)) -// .border(Color.black, width: 1) -// } else { -// if word.shouldShowNumber(number: num) { -// ForEach(Gender.allCases, id: \.rawValue) { gen in -// if word.shouldShowGender(number: num, gen: gen) { -// Text(gen.rawValue.capitalized) -// .frame(minWidth: calcWidth(), maxWidth: calcWidth()) -// .padding(.vertical, 10) -// .background(Color.gray.opacity(0.2)) -// .border(Color.black, width: 1) -// } -// } -// } -// } -// } -// } -// -// // Rows -// ForEach(Case.allCases, id: \.rawValue) { c in -// HStack(spacing: 0) { -// Text(c.rawValue.capitalized) -// .frame(minWidth: 87, maxWidth: 87) -// .padding(.vertical, 10) -// .border(Color.black, width: 1) -// .background(Color.gray.opacity(0.2)) -// -// ForEach(Number.allCases, id: \.rawValue) { num in -// if word.shouldShowNumber(number: num) { -// ForEach(Gender.allCases, id: \.rawValue) { gen in -// if word.shouldShowGender(number: num, gen: gen) { -// if let wordWithCase = word.generateComparisonStrongAdjective(number: num, gender: gen, caseStrong: c) { -// Text(wordWithCase) -// .frame(minWidth: calcWidth(), maxWidth: calcWidth()) -// .padding(.vertical, 10) -// .border(Color.black, width: 1) -// } -// } -// } -// } -// } -// } -// } -// -// HStack(spacing: 0) { -// Text("") -// .frame(minWidth: 87, minHeight: 0, maxHeight: .infinity, alignment: .center) -// .padding(.vertical, 10) -// .background(Color.gray.opacity(0.2)) -// .border(Color.black, width: 1) -// -// Text("Comparison Weak") -// .frame(minWidth: 522, minHeight: 0, maxHeight: .infinity, alignment: .center) -// .padding(.vertical, 10) -// .background(Color.gray.opacity(0.2)) -// .border(Color.black, width: 1) -// } -// -// // Main Headers -// Headers() -// -// // Sub-Headers -// HStack(spacing: 0) { -// Text("") -// .frame(minWidth: 87, maxWidth: 87) -// .padding(.vertical, 10) -// .background(Color.gray.opacity(0.2)) -// .border(Color.black, width: 1) -// -// ForEach(Number.allCases, id: \.rawValue) { num in -// if num == .plural { -// Text("Any") -// .frame(minWidth: 261, maxWidth: 261) -// .padding(.vertical, 10) -// .background(Color.gray.opacity(0.2)) -// .border(Color.black, width: 1) -// } else { -// if word.shouldShowNumber(number: num) { -// ForEach(Gender.allCases, id: \.rawValue) { gen in -// if word.shouldShowGender(number: num, gen: gen) { -// Text(gen.rawValue.capitalized) -// .frame(minWidth: calcWidth(), maxWidth: calcWidth()) -// .padding(.vertical, 10) -// .background(Color.gray.opacity(0.2)) -// .border(Color.black, width: 1) -// } -// } -// } -// } -// } -// } -// -// // Rows -// ForEach(Case.allCases, id: \.rawValue) { c in -// HStack(spacing: 0) { -// Text(c.rawValue.capitalized) -// .frame(minWidth: 87, maxWidth: 87) -// .padding(.vertical, 10) -// .border(Color.black, width: 1) -// .background(Color.gray.opacity(0.2)) -// -// ForEach(Number.allCases, id: \.rawValue) { num in -// if num == .plural { -// if let weakAdjective = word.generateComparisonWeakAdjective(number: num, gender: .any, caseWeak: c) { -// Text(weakAdjective) -// .frame(minWidth: 261, maxWidth: 261) -// .padding(.vertical, 10) -// .border(Color.black, width: 1) -// } -// } else { -// if word.shouldShowNumber(number: num) { -// ForEach(Gender.allCases, id: \.rawValue) { gen in -// if word.shouldShowGender(number: num, gen: gen) { -// if let weakAdjective = word.generateComparisonWeakAdjective(number: num, gender: gen, caseWeak: c) { -// Text(weakAdjective) -// .frame(minWidth: calcWidth(), maxWidth: calcWidth()) -// .padding(.vertical, 10) -// .border(Color.black, width: 1) -// } -// } -// } -// } -// } -// } -// } -// } -// } + if word.type == .adjective { + HStack(spacing: 0) { + Text("") + .frame(minWidth: 87, minHeight: 0, maxHeight: .infinity, alignment: .center) + .padding(.vertical, 10) + .background(Color.gray.opacity(0.2)) + .border(Color.black, width: 1) + + Text("Weak Inflection") + .frame(minWidth: 522, minHeight: 0, maxHeight: .infinity, alignment: .center) + .padding(.vertical, 10) + .background(Color.gray.opacity(0.2)) + .border(Color.black, width: 1) + } + + // Main Headers + Headers() + + // Rows + ForEach(Case.allCases, id: \.rawValue) { c in + HStack(spacing: 0) { + Text(c.rawValue.capitalized) + .frame(minWidth: 87, maxWidth: 87) + .padding(.vertical, 10) + .border(Color.black, width: 1) + .background(Color.gray.opacity(0.2)) + + ForEach(Number.allCases, id: \.rawValue) { num in + if num == .plural { + if let weakAdjective = word.generateWeakAdjective(number: num, gender: .any, caseWeak: c) { + Text(weakAdjective) + .frame(minWidth: 261, maxWidth: 261) + .padding(.vertical, 10) + .border(Color.black, width: 1) + } + } else { + if word.shouldShowNumber(number: num) { + ForEach(Gender.allCases, id: \.rawValue) { gen in + if word.shouldShowGender(number: num, gen: gen) { + if let weakAdjective = word.generateWeakAdjective(number: num, gender: gen, caseWeak: c) { + Text(weakAdjective) + .frame(minWidth: calcWidth(), maxWidth: calcWidth()) + .padding(.vertical, 10) + .border(Color.black, width: 1) + } + } + } + } + } + } + } + } + + HStack(spacing: 0) { + Text("") + .frame(minWidth: 87, minHeight: 0, maxHeight: .infinity, alignment: .center) + .padding(.vertical, 10) + .background(Color.gray.opacity(0.2)) + .border(Color.black, width: 1) + + Text("Comparative") + .frame(minWidth: 522, minHeight: 0, maxHeight: .infinity, alignment: .center) + .padding(.vertical, 10) + .background(Color.gray.opacity(0.2)) + .border(Color.black, width: 1) + } + + // Main Headers + Headers() + + // Rows + ForEach(Case.allCases, id: \.rawValue) { c in + HStack(spacing: 0) { + Text(c.rawValue.capitalized) + .frame(minWidth: 87, maxWidth: 87) + .padding(.vertical, 10) + .border(Color.black, width: 1) + .background(Color.gray.opacity(0.2)) + + ForEach(Number.allCases, id: \.rawValue) { num in + if num == .plural { + if let weakAdjective = word.generateComparativeAdjective(number: num, gender: .any, caseWeak: c) { + Text(weakAdjective) + .frame(minWidth: 261, maxWidth: 261) + .padding(.vertical, 10) + .border(Color.black, width: 1) + } + } else { + if word.shouldShowNumber(number: num) { + ForEach(Gender.allCases, id: \.rawValue) { gen in + if word.shouldShowGender(number: num, gen: gen) { + if let weakAdjective = word.generateComparativeAdjective(number: num, gender: gen, caseWeak: c) { + Text(weakAdjective) + .frame(minWidth: calcWidth(), maxWidth: calcWidth()) + .padding(.vertical, 10) + .border(Color.black, width: 1) + } + } + } + } + } + } + } + } + + HStack(spacing: 0) { + Text("") + .frame(minWidth: 87, minHeight: 0, maxHeight: .infinity, alignment: .center) + .padding(.vertical, 10) + .background(Color.gray.opacity(0.2)) + .border(Color.black, width: 1) + + Text("Comparison Strong") + .frame(minWidth: 522, minHeight: 0, maxHeight: .infinity, alignment: .center) + .padding(.vertical, 10) + .background(Color.gray.opacity(0.2)) + .border(Color.black, width: 1) + } + + // Main Headers + Headers() + + // Rows + ForEach(Case.allCases, id: \.rawValue) { c in + HStack(spacing: 0) { + Text(c.rawValue.capitalized) + .frame(minWidth: 87, maxWidth: 87) + .padding(.vertical, 10) + .border(Color.black, width: 1) + .background(Color.gray.opacity(0.2)) + + ForEach(Number.allCases, id: \.rawValue) { num in + if word.shouldShowNumber(number: num) { + ForEach(Gender.allCases, id: \.rawValue) { gen in + if word.shouldShowGender(number: num, gen: gen) { + if let wordWithCase = word.generateComparisonStrongAdjective(number: num, gender: gen, caseStrong: c) { + Text(wordWithCase) + .frame(minWidth: calcWidth(), maxWidth: calcWidth()) + .padding(.vertical, 10) + .border(Color.black, width: 1) + } + } + } + } + } + } + } + + HStack(spacing: 0) { + Text("") + .frame(minWidth: 87, minHeight: 0, maxHeight: .infinity, alignment: .center) + .padding(.vertical, 10) + .background(Color.gray.opacity(0.2)) + .border(Color.black, width: 1) + + Text("Comparison Weak") + .frame(minWidth: 522, minHeight: 0, maxHeight: .infinity, alignment: .center) + .padding(.vertical, 10) + .background(Color.gray.opacity(0.2)) + .border(Color.black, width: 1) + } + + // Main Headers + Headers() + + // Rows + ForEach(Case.allCases, id: \.rawValue) { c in + HStack(spacing: 0) { + Text(c.rawValue.capitalized) + .frame(minWidth: 87, maxWidth: 87) + .padding(.vertical, 10) + .border(Color.black, width: 1) + .background(Color.gray.opacity(0.2)) + + ForEach(Number.allCases, id: \.rawValue) { num in + if num == .plural { + if let weakAdjective = word.generateComparisonWeakAdjective(number: num, gender: .any, caseWeak: c) { + Text(weakAdjective) + .frame(minWidth: 261, maxWidth: 261) + .padding(.vertical, 10) + .border(Color.black, width: 1) + } + } else { + if word.shouldShowNumber(number: num) { + ForEach(Gender.allCases, id: \.rawValue) { gen in + if word.shouldShowGender(number: num, gen: gen) { + if let weakAdjective = word.generateComparisonWeakAdjective(number: num, gender: gen, caseWeak: c) { + Text(weakAdjective) + .frame(minWidth: calcWidth(), maxWidth: calcWidth()) + .padding(.vertical, 10) + .border(Color.black, width: 1) + } + } + } + } + } + } + } + } + } } } }