gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-taler-ios] 08/12: Layout: View+fitsSideBySide


From: gnunet
Subject: [taler-taler-ios] 08/12: Layout: View+fitsSideBySide
Date: Tue, 31 Oct 2023 08:53:05 +0100

This is an automated email from the git hooks/post-receive script.

marc-stibane pushed a commit to branch master
in repository taler-ios.

commit ca17aeb1112bb7b47d614c6c004de3f085389679
Author: Marc Stibane <marc@taler.net>
AuthorDate: Mon Oct 30 17:44:33 2023 +0100

    Layout: View+fitsSideBySide
---
 TalerWallet.xcodeproj/project.pbxproj              | 12 +--
 TalerWallet1/Helper/TalerStrings.swift             | 42 +++++++++-
 TalerWallet1/Views/Balances/BalanceRowView.swift   | 26 +++----
 TalerWallet1/Views/Balances/TwoRowButtons.swift    | 14 ++--
 TalerWallet1/Views/Exchange/ExchangeRowView.swift  | 51 +++++++++---
 .../Views/HelperViews/View+fitsSideBySide.swift    | 63 +++++++++++++++
 .../Views/HelperViews/View+needVStack.swift        | 91 ----------------------
 .../Views/Transactions/TransactionRowView.swift    |  4 +-
 8 files changed, 169 insertions(+), 134 deletions(-)

diff --git a/TalerWallet.xcodeproj/project.pbxproj 
b/TalerWallet.xcodeproj/project.pbxproj
index 0259c6c..8ad0871 100644
--- a/TalerWallet.xcodeproj/project.pbxproj
+++ b/TalerWallet.xcodeproj/project.pbxproj
@@ -171,8 +171,8 @@
                4E9796902A3765ED006F73BC /* AgePicker.swift in Sources */ = 
{isa = PBXBuildFile; fileRef = 4E97968F2A3765ED006F73BC /* AgePicker.swift */; 
};
                4E983C292ADBDD3500FA9CC5 /* SingleAxisGeometryReader.swift in 
Sources */ = {isa = PBXBuildFile; fileRef = 4E983C282ADBDD3500FA9CC5 /* 
SingleAxisGeometryReader.swift */; };
                4E983C2A2ADBDD3500FA9CC5 /* SingleAxisGeometryReader.swift in 
Sources */ = {isa = PBXBuildFile; fileRef = 4E983C282ADBDD3500FA9CC5 /* 
SingleAxisGeometryReader.swift */; };
-               4E983C2C2ADC416800FA9CC5 /* View+needVStack.swift in Sources */ 
= {isa = PBXBuildFile; fileRef = 4E983C2B2ADC416800FA9CC5 /* 
View+needVStack.swift */; };
-               4E983C2D2ADC416800FA9CC5 /* View+needVStack.swift in Sources */ 
= {isa = PBXBuildFile; fileRef = 4E983C2B2ADC416800FA9CC5 /* 
View+needVStack.swift */; };
+               4E983C2C2ADC416800FA9CC5 /* View+fitsSideBySide.swift in 
Sources */ = {isa = PBXBuildFile; fileRef = 4E983C2B2ADC416800FA9CC5 /* 
View+fitsSideBySide.swift */; };
+               4E983C2D2ADC416800FA9CC5 /* View+fitsSideBySide.swift in 
Sources */ = {isa = PBXBuildFile; fileRef = 4E983C2B2ADC416800FA9CC5 /* 
View+fitsSideBySide.swift */; };
                4EA1ABBE29A3833A008821EA /* PublicConstants.swift in Sources */ 
= {isa = PBXBuildFile; fileRef = 4EA1ABBD29A3833A008821EA /* 
PublicConstants.swift */; };
                4EA551252A2C923600FEC9A8 /* CurrencyInputView.swift in Sources 
*/ = {isa = PBXBuildFile; fileRef = 4EA551242A2C923600FEC9A8 /* 
CurrencyInputView.swift */; };
                4EAD117629F672FA008EDD0B /* KeyboardResponder.swift in Sources 
*/ = {isa = PBXBuildFile; fileRef = 4EAD117529F672FA008EDD0B /* 
KeyboardResponder.swift */; };
@@ -347,7 +347,7 @@
                4E9320462A164BC700A87B0E /* PaymentPurpose.swift */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path 
= PaymentPurpose.swift; sourceTree = "<group>"; };
                4E97968F2A3765ED006F73BC /* AgePicker.swift */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path 
= AgePicker.swift; sourceTree = "<group>"; };
                4E983C282ADBDD3500FA9CC5 /* SingleAxisGeometryReader.swift */ = 
{isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = 
sourcecode.swift; path = SingleAxisGeometryReader.swift; sourceTree = 
"<group>"; };
-               4E983C2B2ADC416800FA9CC5 /* View+needVStack.swift */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path 
= "View+needVStack.swift"; sourceTree = "<group>"; };
+               4E983C2B2ADC416800FA9CC5 /* View+fitsSideBySide.swift */ = {isa 
= PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; 
path = "View+fitsSideBySide.swift"; sourceTree = "<group>"; };
                4EA1ABBD29A3833A008821EA /* PublicConstants.swift */ = {isa = 
PBXFileReference; lastKnownFileType = sourcecode.swift; path = 
PublicConstants.swift; sourceTree = "<group>"; };
                4EA551242A2C923600FEC9A8 /* CurrencyInputView.swift */ = {isa = 
PBXFileReference; lastKnownFileType = sourcecode.swift; path = 
CurrencyInputView.swift; sourceTree = "<group>"; };
                4EAD117529F672FA008EDD0B /* KeyboardResponder.swift */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path 
= KeyboardResponder.swift; sourceTree = "<group>"; };
@@ -748,7 +748,7 @@
                                4E5A88F42A38A4FD00072618 /* 
QRCodeDetailView.swift */,
                                4E6EDD862A363D8D0031D520 /* ListStyle.swift */,
                                4E983C282ADBDD3500FA9CC5 /* 
SingleAxisGeometryReader.swift */,
-                               4E983C2B2ADC416800FA9CC5 /* 
View+needVStack.swift */,
+                               4E983C2B2ADC416800FA9CC5 /* 
View+fitsSideBySide.swift */,
                                4EB095482989CBFE0043A8A1 /* 
TextFieldAlert.swift */,
                                4EBA82AA2A3EB2CA00E5F39A /* 
TransactionButton.swift */,
                                4EB095492989CBFE0043A8A1 /* AmountView.swift */,
@@ -1051,7 +1051,7 @@
                                4E3EAE252A990778009F1BE8 /* 
WithdrawAcceptDone.swift in Sources */,
                                4E3EAE262A990778009F1BE8 /* Transaction.swift 
in Sources */,
                                4E605DB72AB05E48002FB9A7 /* 
View+flippedDirection.swift in Sources */,
-                               4E983C2C2ADC416800FA9CC5 /* 
View+needVStack.swift in Sources */,
+                               4E983C2C2ADC416800FA9CC5 /* 
View+fitsSideBySide.swift in Sources */,
                                4E3EAE272A990778009F1BE8 /* WalletColors.swift 
in Sources */,
                                4EC400892AE3E7E800DF72C7 /* AboutView.swift in 
Sources */,
                                4E3EAE282A990778009F1BE8 /* 
BalancesListView.swift in Sources */,
@@ -1160,7 +1160,7 @@
                                4E5A88F72A3B9E5B00072618 /* 
WithdrawAcceptDone.swift in Sources */,
                                4EB095222989CBCB0043A8A1 /* Transaction.swift 
in Sources */,
                                4E605DB82AB05E48002FB9A7 /* 
View+flippedDirection.swift in Sources */,
-                               4E983C2D2ADC416800FA9CC5 /* 
View+needVStack.swift in Sources */,
+                               4E983C2D2ADC416800FA9CC5 /* 
View+fitsSideBySide.swift in Sources */,
                                4E9320432A14F6EA00A87B0E /* WalletColors.swift 
in Sources */,
                                4EC4008A2AE3E7E800DF72C7 /* AboutView.swift in 
Sources */,
                                4EB0955D2989CBFE0043A8A1 /* 
BalancesListView.swift in Sources */,
diff --git a/TalerWallet1/Helper/TalerStrings.swift 
b/TalerWallet1/Helper/TalerStrings.swift
index 70b7330..64fb58a 100644
--- a/TalerWallet1/Helper/TalerStrings.swift
+++ b/TalerWallet1/Helper/TalerStrings.swift
@@ -2,6 +2,7 @@
  * This file is part of GNU Taler, ©2022-23 Taler Systems S.A.
  * See LICENSE.md
  */
+import SwiftUI
 import Foundation
 import UIKit
 
@@ -44,7 +45,42 @@ extension String {
         let size = self.size(withAttributes: fontAttributes)
         return size.width
     }
+
+    func widthOfString(usingUIFont font: UIFont, _ sizeCategory: 
ContentSizeCategory) -> CGFloat {
+        let width = widthOfString(usingUIFont: font)
+        let correctForSize = correctForSize(sizeCategory)
+
+        return width * correctForSize
+    }
+
+    // This would be used like so:
+    // let uiFont = UIFont.systemFont(ofSize: 17, weight: .bold)
+    // let width = "SomeString".widthOfString(usingUIFont: uiFont)
+
+    ///
+    fileprivate func correctForSize(_ sizeCategory: ContentSizeCategory) -> 
CGFloat {
+        let corrValue = switch sizeCategory {
+            case .extraSmall: 0.7
+            case .small: 0.8
+            case .medium: 0.9
+//            case .large: 1.0
+            case .extraLarge: 1.15
+            case .extraExtraLarge: 1.25
+            case .extraExtraExtraLarge: 1.33
+            case .accessibilityMedium: 1.52
+            case .accessibilityLarge: 1.8
+            case .accessibilityExtraLarge: 2.0
+            case .accessibilityExtraExtraLarge: 2.2
+            case .accessibilityExtraExtraExtraLarge: 2.5
+            default: 1.0
+        }
+        if ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] 
== "1" {
+            // empirical values
+            return corrValue
+        } else {
+            // preview doesn't use ContentSizeCategory for 
widthOfString(usingUIFont)
+            // thus the empirical values are the square of what's really needed
+            return sqrt(corrValue)
+        }
+    }
 }
-// This would be used like so:
-// let uiFont = UIFont.systemFont(ofSize: 17, weight: .bold)
-// let width = "SomeString".widthOfString(usingUIFont: uiFont)
diff --git a/TalerWallet1/Views/Balances/BalanceRowView.swift 
b/TalerWallet1/Views/Balances/BalanceRowView.swift
index db5b951..4af0a15 100644
--- a/TalerWallet1/Views/Balances/BalanceRowView.swift
+++ b/TalerWallet1/Views/Balances/BalanceRowView.swift
@@ -15,15 +15,15 @@ struct BalanceButton: View {
     var body: some View {
         let balanceTitle = String(localized: "Balance:", comment: "Main view")
         Button(action: rowAction) {
-            SingleAxisGeometryReader { width in
+            SingleAxisGeometryReader { width in         // e.g. 301 instead of 
313 => padding = 6
                 Group {
                     let titles = [(balanceTitle, TalerFont.uiFont(.title2)),
                                   (amountStr,    TalerFont.uiFont(.title))]
-                    let needVStack = !iconOnly && Self.needVStack(titles, 
width: width,
+                    let fitsSideBySide = iconOnly || 
Self.fitsSideBySide(titles, availableWidth: width,
                                                                   
sizeCategory: sizeCategory,
                                                                   padding: 20, 
sameSize: false)
                     AmountRowV(amountStr: amountStr, amountColor: .primary, 
largeAmountFont: true,
-                               fitsHorizontal: !needVStack, vertAlignment: 
.lastTextBaseline) {
+                               fitsHorizontal: fitsSideBySide, vertAlignment: 
.lastTextBaseline) {
                         Text(iconOnly ? "" : balanceTitle)
                             .accessibilityFont(.title2)
                             .foregroundColor(.secondary)
@@ -38,8 +38,8 @@ struct BalanceButton: View {
 }
 
 
-/// This view shows the currency row in a currency section
-///  Balance:                          amount
+/// This view shows the currency row in a currency section, and two action 
buttons below
+///  Balance:               amount
 /// [Send Money]  [Request Payment]
 struct BalanceRowView: View {
     let amount: Amount
@@ -59,27 +59,27 @@ struct BalanceRowView: View {
     let requestTitle2 = String(localized: "Payment", comment: "Bottom of 
button <Request Payment>")
 
     var body: some View {
-        let correctForSize = Self.correctForSize(sizeCategory)
         SingleAxisGeometryReader { width in
             VStack (alignment: .trailing) {
                 let amountStr = amount.string(currencyInfo)
                 BalanceButton(amountStr: amountStr,
-                              sizeCategory: sizeCategory,
+                           sizeCategory: sizeCategory,
                               rowAction: rowAction)
                 let uiFont = TalerFont.uiFont(.title3)
                 let titles = iconOnly ? [(sendTitle0, uiFont), (requestTitle0, 
uiFont)]
                            : [(sendTitle1, uiFont), (sendTitle2, uiFont), 
(requestTitle1, uiFont), (requestTitle2, uiFont)]
-                let needVStack = Self.needVStack(titles, width: width, 
sizeCategory: sizeCategory, padding: 10)
+                let fitsSideBySide = Self.fitsSideBySide(titles, 
availableWidth: width, sizeCategory: sizeCategory, padding: 10)
                 let twoRowButtons = TwoRowButtons(sendTitles: iconOnly ? 
(sendTitle0, nil) : (sendTitle1, sendTitle2),
                                                   recvTitles: iconOnly ? 
(requestTitle0, nil) : (requestTitle1, requestTitle2),
-                                                isHorizontal: needVStack,
-                                                   lineLimit: 5, sendDisabled: 
amount.isZero,
+                                              fitsSideBySide: fitsSideBySide,
+                                                   lineLimit: 5,
+                                                sendDisabled: amount.isZero,
                                                   sendAction: sendAction,
                                                   recvAction: recvAction)
-                if needVStack {
-                    VStack { twoRowButtons }
-                } else {
+                if fitsSideBySide {
                     HStack(spacing: HSPACING) { twoRowButtons }
+                } else {
+                    VStack { twoRowButtons }
                 }
             }
         }
diff --git a/TalerWallet1/Views/Balances/TwoRowButtons.swift 
b/TalerWallet1/Views/Balances/TwoRowButtons.swift
index 1b67af3..423f4fd 100644
--- a/TalerWallet1/Views/Balances/TwoRowButtons.swift
+++ b/TalerWallet1/Views/Balances/TwoRowButtons.swift
@@ -6,8 +6,8 @@ import SwiftUI
 import taler_swift
 
 extension View {
-    func title(_ titles: (String, String?), _ horizontal: Bool) -> String {
-        let delimiter = horizontal ? " " : "\n"
+    func title(_ titles: (String, String?), _ fitsSideBySide: Bool) -> String {
+        let delimiter = fitsSideBySide ? "\n" : " "
         let (title1, title2) = titles
         if let title2 {
             return title1 + delimiter + title2
@@ -19,7 +19,7 @@ extension View {
 struct TwoRowButtons: View {
     let sendTitles: (String, String?)
     let recvTitles: (String, String?)
-    let isHorizontal: Bool
+    let fitsSideBySide: Bool
     let lineLimit: Int
     let sendDisabled: Bool
     let sendAction: () -> Void
@@ -29,13 +29,13 @@ struct TwoRowButtons: View {
 
     var body: some View {
         Group {
-            Button(title(sendTitles, isHorizontal), action: sendAction)
+            Button(title(sendTitles, fitsSideBySide), action: sendAction)
                 .lineLimit(lineLimit)
                 .disabled(sendDisabled)
                 .buttonStyle(TalerButtonStyle(type: .bordered,
                                             dimmed: false,
                                            aligned: .center))
-            Button(title(recvTitles, isHorizontal), action: recvAction)
+            Button(title(recvTitles, fitsSideBySide), action: recvAction)
                 .lineLimit(lineLimit)
                 .disabled(false)
                 .buttonStyle(TalerButtonStyle(type: .bordered,
@@ -50,13 +50,13 @@ struct TwoRowButtons_Previews: PreviewProvider {
         List {
                 TwoRowButtons(sendTitles: ("Send", TESTCURRENCY),
                               recvTitles: ("Receive", LONGCURRENCY),
-                            isHorizontal: true,
+                          fitsSideBySide: false,
                                lineLimit: 2, sendDisabled: true,
                               sendAction: {}, recvAction: {})
                 .listRowSeparator(.hidden)
                 TwoRowButtons(sendTitles: ("Send", DEMOCURRENCY),
                               recvTitles: ("Receive", DEMOCURRENCY),
-                            isHorizontal: true,
+                          fitsSideBySide: true,
                                lineLimit: 2, sendDisabled: true,
                               sendAction: {}, recvAction: {})
                 .listRowSeparator(.hidden)
diff --git a/TalerWallet1/Views/Exchange/ExchangeRowView.swift 
b/TalerWallet1/Views/Exchange/ExchangeRowView.swift
index 2848e58..7674c20 100644
--- a/TalerWallet1/Views/Exchange/ExchangeRowView.swift
+++ b/TalerWallet1/Views/Exchange/ExchangeRowView.swift
@@ -28,10 +28,32 @@ struct ExchangeRowView: View {
 //        }
     }
 
-    let depositTitle = String(localized: "Deposit", comment: "Top of button 
<Deposit (currency)>")
-    let withdrawTitle = String(localized: "Withdraw", comment: "Top of button 
<Withdraw (currency)>")
+
+//    func
+    func titles(_ title: String) -> (String, String?) {
+        if let separatorIndex = title.firstIndex(of: "\n") {
+            let title1 = String(title[..<separatorIndex])
+            let title2 = String(title[title.index(separatorIndex, offsetBy: 
1)...])
+            return (title1, title2)
+        }
+        return (title, nil)
+    }
+
+    func titles(_ titles: (String, String?), uiFont: UIFont) -> [(String, 
UIFont)] {
+        let (title1, title2) = titles
+        if let title2 {
+            return [(title1, uiFont), (title2, uiFont)]
+        }
+        return [(title1, uiFont)]
+    }
 
     var body: some View {
+        let depositTitle0 = String(localized: "Deposit", comment: 
"Abbreviation <Deposit (currency)>")
+        let depositTitle1 = String(localized: "Deposit\n\(currency)",
+                                   comment: "Button <Deposit (currency)>, must 
have ONE \n and ONE %s")
+        let withdrawTitle0 = String(localized: "Withdraw", comment: 
"Abbreviation <Withdraw (currency)>")
+        let withdrawTitle1 = String(localized: "Withdraw\n\(currency)",
+                                    comment: "Button <Withdraw (currency)>, 
must have ONE \n and ONE %s")
         let baseURL = exchange.exchangeBaseUrl
 
         HStack(spacing: 0) {    // can't use the built in Label because it 
adds the accessory arrow
@@ -53,20 +75,25 @@ struct ExchangeRowView: View {
         SingleAxisGeometryReader { width in
             Group {
                 let uiFont = TalerFont.uiFont(.title3)
-                let titles = iconOnly ? [(depositTitle, uiFont), 
(withdrawTitle, uiFont)]
-                                      : [(depositTitle, uiFont), 
(withdrawTitle, uiFont), (currency, uiFont)]
-                let needVStack = Self.needVStack(titles, width: width, 
sizeCategory: sizeCategory, padding: 10)
+                let (deposit1, deposit2) = titles(depositTitle1)
+                let (withdraw1, withdraw2) = titles(withdrawTitle1)
+                let titles = iconOnly ? [(depositTitle0, uiFont), 
(withdrawTitle0, uiFont)]
+                                      : titles((deposit1, deposit2), uiFont: 
uiFont) +
+                                        titles((withdraw1, withdraw2), uiFont: 
uiFont)
+                let fitsSideBySide = Self.fitsSideBySide(titles, 
availableWidth: width,
+                                                         sizeCategory: 
sizeCategory, padding: 10)
                                                                                
     // TODO:  amount.currencyStr
-                let twoRowButtons = TwoRowButtons(sendTitles: iconOnly ? 
(depositTitle, nil)  : (depositTitle, currency),
-                                                  recvTitles: iconOnly ? 
(withdrawTitle, nil) : (withdrawTitle, currency),
-                                                isHorizontal: needVStack,
-                                                   lineLimit: 5, sendDisabled: 
true,         // TODO: amount.isZero
+                let twoRowButtons = TwoRowButtons(sendTitles: iconOnly ? 
(depositTitle0, nil)  : (deposit1, deposit2),
+                                                  recvTitles: iconOnly ? 
(withdrawTitle0, nil) : (withdraw1, withdraw2),
+                                              fitsSideBySide: fitsSideBySide,
+                                                   lineLimit: 5,
+                                                sendDisabled: true,            
 // TODO: availableAmount.isZero
                                                   sendAction: { 
selectAndUpdate(1) },
                                                   recvAction: { 
selectAndUpdate(2) })
-                if needVStack {
-                    VStack { twoRowButtons }
-                } else {
+                if fitsSideBySide {
                     HStack(spacing: HSPACING) { twoRowButtons }
+                } else {
+                    VStack { twoRowButtons }
                 }
             }
         }
diff --git a/TalerWallet1/Views/HelperViews/View+fitsSideBySide.swift 
b/TalerWallet1/Views/HelperViews/View+fitsSideBySide.swift
new file mode 100644
index 0000000..a76011c
--- /dev/null
+++ b/TalerWallet1/Views/HelperViews/View+fitsSideBySide.swift
@@ -0,0 +1,63 @@
+/*
+ * This file is part of GNU Taler, ©2022-23 Taler Systems S.A.
+ * See LICENSE.md
+ */
+import SwiftUI
+import UIKit
+
+extension View {
+    /// if sameSize then this searches for the longest title
+    /// returns true if any of the strings in 'titles' wouldn't fit in a view 
1/'numViews' of the size of 'width', with 'spacing'
+    /// if !sameSize then all titles are added with spacing
+    static func fitsSideBySide(_ titles: [(String, UIFont)],
+                         availableWidth: CGFloat,                       // 
total width available
+                           sizeCategory: ContentSizeCategory,
+                                spacing: CGFloat = HSPACING,            // 
between titles
+                                padding: CGFloat = 20,
+                               sameSize: Bool = true,
+                               numViews: Int = 2)
+    -> Bool {
+//        let padding = 20.0        // TODO: depend on myListStyle
+        let totalSpacing = spacing * CGFloat(numViews - 1)
+        var totalWidth = padding + totalSpacing
+
+        var maxTitleWidth = 0.0
+        var minTitleWidth = 1000.0
+        for (title, uiFont) in titles {
+            let titleWidth = title.widthOfString(usingUIFont: uiFont, 
sizeCategory)
+            if titleWidth > maxTitleWidth {
+                maxTitleWidth = titleWidth
+            }
+            if titleWidth < minTitleWidth {
+                minTitleWidth = titleWidth
+            }
+//            if availableWidth > 20 {
+//                let widthStr = String(format: "%.2f + %.2f = %.2f", 
totalWidth, titleWidth, totalWidth + titleWidth)
+//                print("❗️  \(title)  \(widthStr)")
+//            }
+            totalWidth += titleWidth
+        }
+
+        if sameSize {
+            let nettoWidth = availableWidth - totalSpacing
+            let singleWidth = nettoWidth / CGFloat(numViews)
+            let neededWidth = padding + maxTitleWidth
+//            if availableWidth > 20 {
+//                let width1Str = String(format: "%.2f -spacing %.2f = %.2f / 
%d = %.2f", availableWidth, totalSpacing,
+//                                       nettoWidth, numViews, singleWidth)
+//                let width2Str = String(format: "%.2f +padding %.2f = %.2f", 
maxTitleWidth, padding, maxTitleWidth + padding)
+//                print("❗️ available: \(width1Str)   needed: \(width2Str)")
+//            }
+            return neededWidth < singleWidth
+        } else {
+//            if availableWidth > 20 {
+//                let totalStr = String(format: "%.2f -spacing %.2f = %.2f 
-padding %.2f = %.2f", totalWidth, totalSpacing,
+//                                      totalWidth - totalSpacing, padding, 
totalWidth - totalSpacing - padding)
+//                print("❗️ view width: \(availableWidth)   total: 
\(totalStr)")
+//                let (amount, font) = titles[1]
+//                print("❗️ view width: \(width)   total: \(totalStr)  min: 
\(minTitleWidth)  max: \(maxTitleWidth)  \(amount)")
+//            }
+            return totalWidth < availableWidth
+        }
+    }
+}
diff --git a/TalerWallet1/Views/HelperViews/View+needVStack.swift 
b/TalerWallet1/Views/HelperViews/View+needVStack.swift
deleted file mode 100644
index 739afce..0000000
--- a/TalerWallet1/Views/HelperViews/View+needVStack.swift
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * This file is part of GNU Taler, ©2022-23 Taler Systems S.A.
- * See LICENSE.md
- */
-import SwiftUI
-import UIKit
-
-extension View {
-    /// if sameSize then this searches for the longest title
-    /// returns true if any of the strings in 'titles' wouldn't fit in a view 
1/'numViews' of the size of 'width', with 'spacing'
-    /// if !sameSize then all titles are added with spacing
-    static func needVStack(_ titles: [(String, UIFont)],
-                              width: CGFloat,                   // total width 
available
-                       sizeCategory: ContentSizeCategory,
-                            spacing: CGFloat = HSPACING,        // between 
titles
-                            padding: CGFloat = 20,
-                           sameSize: Bool = true,
-                           numViews: Int = 2)
-    -> Bool {
-        let correctForSize = correctForSize(sizeCategory)
-//        let padding = 20.0        // TODO: depend on myListStyle
-        let totalSpacing = spacing * CGFloat(numViews - 1)
-        var totalWidth = padding + totalSpacing
-
-        var maxTitleWidth = 0.0
-        var minTitleWidth = 1000.0
-        for (title, uiFont) in titles {
-            let titleWidth = title.widthOfString(usingUIFont: uiFont)
-  if width > 20 {
-      let widthStr = String(format: "%.2f * %.2f = %.2f", titleWidth, 
correctForSize, titleWidth * correctForSize)
-      print("❗️  \(title)  \(widthStr)")
-  }
-            let fixWidth = round(CGFloat(Int(20 * titleWidth * 
correctForSize))) / 20
-            if fixWidth > maxTitleWidth {
-                maxTitleWidth = fixWidth
-            }
-            if fixWidth < minTitleWidth {
-                minTitleWidth = fixWidth
-            }
-            totalWidth += fixWidth
-        }
-
-        if sameSize {
-            let availableWidth = width - totalSpacing
-            let singleWidth = availableWidth / CGFloat(numViews)
-            let neededWidth = padding + maxTitleWidth
-            if width > 20 {
-                let width1Str = String(format: "%.2f -spacing %.2f = %.2f / %d 
= %.2f", width, totalSpacing,
-                                       availableWidth, numViews, singleWidth)
-                let width2Str = String(format: "%.2f +padding %.2f = %.2f", 
maxTitleWidth, padding, maxTitleWidth + padding)
-                print("❗️ available: \(width1Str)   needed: \(width2Str)")
-            }
-            return neededWidth > singleWidth
-        } else {
-            if width > 20 {
-                let totalStr = String(format: "%.2f -spacing %.2f = %.2f 
-padding %.2f = %.2f", totalWidth, totalSpacing,
-                                      totalWidth - totalSpacing, padding, 
totalWidth - totalSpacing - padding)
-                print("❗️ view width: \(width)   total: \(totalStr)")
-//                let (amount, font) = titles[1]
-//                print("❗️ view width: \(width)   total: \(totalStr)  min: 
\(minTitleWidth)  max: \(maxTitleWidth)  \(amount)")
-            }
-            return totalWidth > width
-        }
-    }
-
-    static func correctForSize(_ sizeCategory: ContentSizeCategory) -> CGFloat 
{
-        let corrValue = switch sizeCategory {
-            case .extraSmall: 0.7
-            case .small: 0.8
-            case .medium: 0.9
-//            case .large: 1.0
-            case .extraLarge: 1.15
-            case .extraExtraLarge: 1.25
-            case .extraExtraExtraLarge: 1.33
-            case .accessibilityMedium: 1.52
-            case .accessibilityLarge: 1.8
-            case .accessibilityExtraLarge: 2.0
-            case .accessibilityExtraExtraLarge: 2.2
-            case .accessibilityExtraExtraExtraLarge: 2.5
-            default: 1.0
-        }
-        if ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] 
== "1" {
-            // empirical values
-            return corrValue
-        } else {
-            // preview doesn't use ContentSizeCategory for 
widthOfString(usingUIFont)
-            // thus the empirical values are the square of what's really needed
-            return sqrt(corrValue)
-        }
-    }
-}
diff --git a/TalerWallet1/Views/Transactions/TransactionRowView.swift 
b/TalerWallet1/Views/Transactions/TransactionRowView.swift
index 0fb3e01..a2d2c0f 100644
--- a/TalerWallet1/Views/Transactions/TransactionRowView.swift
+++ b/TalerWallet1/Views/Transactions/TransactionRowView.swift
@@ -83,8 +83,8 @@ struct TransactionRowView: View {
                 let amountStr = amount.string(currencyInfo)
                 let amountWidth = amountStr.width(largeAmountFont: false)
 
-                let contentWidth = PendingRowContentV.width(titles: 
(transaction.localizedType, dateString),
-                                                            isHorizontal: true)
+                let contentWidth = TransactionRowContentV.width(titles: 
(transaction.localizedType, dateString),
+                                                            isHorizontal: 
false)
                 let needVStack = needVStack(available: width, contentWidth: 
contentWidth, valueWidth: amountWidth)
 
                 AmountRowV(amountStr: amountStr, amountColor: foreColor, 
largeAmountFont: false,

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]