commit d08570f07472d4426a5642ad00ed5860eb24e995
parent 24c7eb4c48b16c56f7f7160783bc45c0c90f7afa
Author: Marc Stibane <marc@taler.net>
Date: Sat, 12 Apr 2025 08:19:44 +0200
get sizes from images
Diffstat:
4 files changed, 63 insertions(+), 134 deletions(-)
diff --git a/TalerWallet1/Views/OIM/OIMcurrency.swift b/TalerWallet1/Views/OIM/OIMcurrency.swift
@@ -12,20 +12,12 @@ public typealias OIMnotesCoins = (OIMdenominations, OIMdenominations) // n
// 6 banknotes, 8 coins of which 6 are fractionals < 100
public let OIMeuros = OIMcurrency(bankNotes: [20000, 10000, 5000, 2000, 1000, 500],
- noteWidth: 384,
- noteHeight: 352,
- noteWidths: [ 384, 384, 384, 384, 384, 384],
- noteHeights: [ 352, 352, 352, 352, 352, 352],
bankCoins: [200, 100, 50, 20, 10, 5, 2, 1],
coinSizes: [258, 232, 242, 222, 198, 212, 188, 162],
noteBase: "EUR", coinBase: "eur")
// 5 banknotes, 5 coins (all fractionals)
public let OIMleones = OIMcurrency(bankNotes: [20000, 10000, 5000, 2000, 1000, 500, 200, 100],
- noteWidth: 400,
- noteHeight: 296,
- noteWidths: [ 620, 600, 590, 400, 400, 400, 400, 400],
- noteHeights: [ 310, 320, 310, 296, 296, 296, 296, 296],
bankCoins: [ 50, 25, 10, 5, 1],
coinSizes: [270, 250, 240, 228, 208],
// [ 260mm 270px, 240mm 250px, 230mm 240px, 225mm 228px, 200mm 208px]
@@ -33,22 +25,14 @@ public let OIMleones = OIMcurrency(bankNotes: [20000, 10000, 5000, 2000, 1000, 5
// 6 banknotes, 6 coins of which 5 are fractionals < 100
public let OIMdollars = OIMcurrency(bankNotes: [10000, 5000, 2000, 1000, 500, 200], // XXX x 265
- noteWidth: 400,
- noteHeight: 265,
- noteWidths: [ 384, 361, 380, 364, 349, 413],
- noteHeights: [ 265, 265, 265, 265, 265, 265],
bankCoins: [100, 50, 25, 10, 5, 1],
coinSizes: [265, 306, 243, 180, 212, 190],
noteBase: "USD", coinBase: "usd")
// MARK: -
public struct OIMcurrency: Sendable {
- let bankNotes: OIMdenominations // values of each banknote, in cents
- let noteWidth: CGFloat
- let noteHeight: CGFloat
- let noteWidths: OIMdenominations
- let noteHeights: OIMdenominations
- let bankCoins: OIMdenominations // values of each coin, decending
- let coinSizes: [CGFloat] // coin sizes in points
+ let bankNotes: OIMdenominations // values of each banknote, in cents, descending
+ let bankCoins: OIMdenominations // values of each coin
+ let coinSizes: [CGFloat] // coin sizes
let noteBase: String
let coinBase: String
diff --git a/TalerWallet1/Views/OIM/OIMcurrencyScroller.swift b/TalerWallet1/Views/OIM/OIMcurrencyScroller.swift
@@ -51,24 +51,24 @@ struct OIMcurrencyScroller: View {
}
var body: some View {
ScrollView(.horizontal) {
- HStack(spacing: 10) {
+ HStack(alignment: .bottom, spacing: 10) {
ForEach(currency.bankNotes, id: \.self) { value in
- OIMnoteV(value: value,
- currency: currency,
- availableVal: availableVal,
- canEdit: true,
- pct: 0.0,
- action: { tap(value: value) }
+ OIMcurrencyView(value: value,
+ currency: currency,
+ availableVal: availableVal,
+ canEdit: true,
+ pct: 0.0,
+ action: { tap(value: value) }
)
.matchedGeometryEffect(id: value, in: wrapper.namespace, isSource: true)
}
ForEach(currency.bankCoins, id: \.self) { value in
- OIMcoinV(value: value,
- currency: currency,
- availableVal: availableVal,
- canEdit: true,
- pct: 0.0,
- action: { tap(value: value) }
+ OIMcurrencyView(value: value,
+ currency: currency,
+ availableVal: availableVal,
+ canEdit: true,
+ pct: 0.0,
+ action: { tap(value: value) }
)
.matchedGeometryEffect(id: value, in: wrapper.namespace, isSource: true)
}
diff --git a/TalerWallet1/Views/OIM/OIMcurrencyViews.swift b/TalerWallet1/Views/OIM/OIMcurrencyViews.swift
@@ -17,36 +17,32 @@ struct OIMbuttonStyle: ButtonStyle {
// .background(RoundedRectangle(cornerRadius: 5).fill(color))
// .compositingGroup()
// .shadow(color: .black, radius: 3)
- .opacity(configuration.isPressed ? 0.5 : 1.0)
+ .opacity(configuration.isPressed ? 0.7 : 1.0)
.scaleEffect(configuration.isPressed ? 0.9 : 1.0)
}
}
-/// renders 1 banknote from a currency with size/4
-struct OIMnoteV: View {
- let value: Int
- let currency: OIMcurrency
- let availableVal: Int
- let canEdit: Bool
- var pct: CGFloat
- let action: () -> Void
+struct OIMcurrencyImage {
+ let image: Image
+ let oWidth: CGFloat
+ let oHeight: CGFloat
- var body: some View {
-// let _ = Self._printChanges()
- // Use EmptyView, because the modifier actually ignores
- // the value passed to its body() function.
- EmptyView().modifier(OIMmod(value: value,
- currency: currency,
- availableVal: availableVal,
- canEdit: canEdit,
- pct: pct,
- action: action))
+ init(_ name: String?) {
+ if let name, let uiImage = UIImage(named: name) {
+ self.oWidth = uiImage.size.width
+ self.oHeight = uiImage.size.height
+ self.image = Image(uiImage: uiImage)
+ } else {
+ self.image = Image(systemName: "exclamationmark.triangle")
+ self.oWidth = 300
+ self.oHeight = 300
+ }
}
}
struct OIMmod: AnimatableModifier {
let value: Int
- let currency: OIMcurrency
+ let name: String?
let availableVal: Int
let canEdit: Bool
var pct: CGFloat
@@ -60,46 +56,10 @@ struct OIMmod: AnimatableModifier {
func body(content: Content) -> some View {
let shadow = (3 - 8) * pct + 8
return Group {
- if let name = currency.noteName(value) {
- let image = Image(name)
- .resizable()
- .scaledToFit()
- Group {
- if canEdit && availableVal >= value {
- Button(action: action) {
- image
- }
- .buttonStyle(OIMbuttonStyle())
- } else {
- image
- .opacity(canEdit ? 0.5 : 1.0)
- }
- }
- .frame(width: currency.noteWidth / 4, height: currency.noteHeight / 4)
- .shadow(radius: shadow)
- .accessibilityLabel(Text("\(value)", comment: "VoiceOver"))
- } else {
- EmptyView()
- }
- }
- }
-}
-
-/// renders 1 coin from a currency with size/4
-struct OIMcoinV: View {
- let value: Int
- let currency: OIMcurrency
- let availableVal: Int
- let canEdit: Bool
- var pct: CGFloat
- let action: () -> Void
-
- var body: some View {
- let shadow = (3 - 8) * pct + 8
- if let name = currency.coinName(value), let size = currency.coinSize(value) {
- let image = Image(name)
- .resizable()
- .scaledToFit()
+ let currencyImage = OIMcurrencyImage(name)
+ let image = currencyImage.image
+ .resizable()
+ .scaledToFit()
Group {
if canEdit && availableVal >= value {
Button(action: action) {
@@ -111,17 +71,15 @@ struct OIMcoinV: View {
.opacity(canEdit ? 0.5 : 1.0)
}
}
- .frame(width: size / 4, height: size / 4)
+ .frame(width: currencyImage.oWidth / 4, height: currencyImage.oHeight / 4)
.shadow(radius: shadow)
.accessibilityLabel(Text("\(value)", comment: "VoiceOver"))
- } else {
- EmptyView()
}
}
}
/// renders 1 denomination from a currency
-struct OIMsingleV: View {
+struct OIMcurrencyView: View {
let value: Int
let currency: OIMcurrency
let availableVal: Int
@@ -130,11 +88,16 @@ struct OIMsingleV: View {
let action: () -> Void
var body: some View {
- if value > currency.bankCoins[0] {
- OIMnoteV(value: value, currency: currency, availableVal: availableVal, canEdit: canEdit, pct: pct, action: action)
- } else {
- OIMcoinV(value: value, currency: currency, availableVal: availableVal, canEdit: canEdit, pct: pct, action: action)
- }
+ let name = value > currency.bankCoins[0] ? currency.noteName(value)
+ : currency.coinName(value)
+ // Use EmptyView, because the modifier actually ignores
+ // the value passed to its body() function.
+ EmptyView().modifier(OIMmod(value: value,
+ name: name,
+ availableVal: availableVal,
+ canEdit: canEdit,
+ pct: pct,
+ action: action))
}
}
@@ -166,12 +129,12 @@ struct OIMnoteStackV: View {
: .zero
let direction = value < tappedVal
// let _ = print("id \(id), flying \(flying), shaking \(shakeOffset)")
- OIMnoteV(value: value,
- currency: currency,
- availableVal: value,
- canEdit: canEdit,
- pct: match ? 0.0 : 1.0,
- action: action)
+ OIMcurrencyView(value: value,
+ currency: currency,
+ availableVal: value,
+ canEdit: canEdit,
+ pct: match ? 0.0 : 1.0,
+ action: action)
.offset(x: xOffset + (direction ? shakeOffset : -shakeOffset),
y: yOffset)
.matchedGeometryEffect(id: id, in: wrapper.namespace, isSource: false)
@@ -215,12 +178,12 @@ struct OIMcoinStackV: View {
let shakeOffset: CGFloat = shake && !match ? .random(in: 5...10)
: .zero
let direction = value < tappedVal
- OIMcoinV(value: value,
- currency: currency,
- availableVal: value,
- canEdit: canEdit,
- pct: match ? 0.0 : 1.0,
- action: action)
+ OIMcurrencyView(value: value,
+ currency: currency,
+ availableVal: value,
+ canEdit: canEdit,
+ pct: match ? 0.0 : 1.0,
+ action: action)
.offset(x: xOffset + (direction ? shakeOffset : -shakeOffset),
y: yOffset)
.matchedGeometryEffect(id: id, in: wrapper.namespace, isSource: false)
@@ -237,24 +200,6 @@ struct OIMcoinStackV: View {
}
}
}
-
-// renders a stack of 1 denomination
-//struct OIMstackV: View {
-// let value: Int
-// let count: Int
-// let currency: OIMcurrency
-// let canEdit: Bool
-// var pct: CGFloat
-// let action: () -> Void
-//
-// var body: some View {
-// if value > currency.bankCoins[0] {
-// OIMnoteStackV(value: value, count: count, currency: currency, canEdit: canEdit, pct: pct, action: action)
-// } else {
-// OIMcoinStackV(value: value, count: count, currency: currency, canEdit: canEdit, pct: pct, action: action)
-// }
-// }
-//}
// MARK: -
//#Preview {
// OIMstackV()
diff --git a/TalerWallet1/Views/OIM/OIMlineViews.swift b/TalerWallet1/Views/OIM/OIMlineViews.swift
@@ -21,7 +21,7 @@ struct OIMnotesView1: View {
var body: some View {
// let _ = Self._printChanges()
let nrOfNotes = currency.bankNotes.count - 1
- HStack(alignment: .top, spacing: 10) {
+ HStack(alignment: .center, spacing: 10) {
ForEach(0...nrOfNotes, id: \.self) { index in
let value = currency.bankNotes[index]
let shouldFly = tappedVal == value
@@ -129,7 +129,7 @@ struct OIMlineView: View {
.border(red)
#endif
- let oneLine = HStack(spacing: horzSpacing) {
+ let oneLine = HStack(alignment: .center, spacing: horzSpacing) {
notes
coins
}
@@ -173,7 +173,7 @@ struct OIMlineView: View {
}
}
} else {
- LayoutThatFits([HStackLayout(alignment: .top), VStackLayout()]) {
+ LayoutThatFits([HStackLayout(alignment: .center), VStackLayout()]) {
notes
#if DEBUG
.padding(1)