Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
parent
4e02cb1336
commit
4ea684cbda
@ -125,16 +125,14 @@ struct FontUtils {
|
||||
design: Font.Design,
|
||||
size: CGFloat
|
||||
) -> Font {
|
||||
let fontName = weightedFontName(
|
||||
name: name.rawValue,
|
||||
weight: weight,
|
||||
design: design
|
||||
)
|
||||
print(fontName)
|
||||
if name == .system {
|
||||
return .system(size: size, weight: weight, design: design)
|
||||
} else {
|
||||
return .custom(fontName, size: size)
|
||||
return .custom(weightedFontName(
|
||||
name: name.rawValue,
|
||||
weight: weight,
|
||||
design: design
|
||||
), size: size)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,6 +20,9 @@ struct DigitView: View {
|
||||
@State var glowIntensity: Double
|
||||
@Binding var fontSize: CGFloat
|
||||
|
||||
@State private var lastCalculatedSize: CGSize = .zero
|
||||
@State private var isCalculating: Bool = false
|
||||
|
||||
init(digit: String,
|
||||
fontName: FontFamily,
|
||||
weight: Font.Weight = .regular,
|
||||
@ -85,35 +88,41 @@ struct DigitView: View {
|
||||
.padding(.horizontal, 0)
|
||||
.baselineOffset(0)
|
||||
.onAppear {
|
||||
let optimalSize = FontUtils.calculateOptimalFontSize(digit: digit,
|
||||
fontName: fontName,
|
||||
weight: weight,
|
||||
design: design,
|
||||
for: geometry.size)
|
||||
if optimalSize != fontSize {
|
||||
fontSize = optimalSize
|
||||
}
|
||||
calculateOptimalFontSize(for: geometry.size)
|
||||
}
|
||||
.onChange(of: geometry.size) { _, newSize in
|
||||
let optimalSize = FontUtils.calculateOptimalFontSize(digit: digit,
|
||||
fontName: fontName,
|
||||
weight: weight,
|
||||
design: design,
|
||||
for: newSize)
|
||||
if optimalSize != fontSize {
|
||||
fontSize = optimalSize
|
||||
}
|
||||
calculateOptimalFontSize(for: newSize)
|
||||
}
|
||||
.onChange(of: sizeCategory) { _, _ in
|
||||
calculateOptimalFontSize(for: geometry.size)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func calculateOptimalFontSize(for size: CGSize) {
|
||||
// Prevent multiple calculations for the same size
|
||||
guard size != lastCalculatedSize && !isCalculating else { return }
|
||||
|
||||
// Prevent multiple updates per frame
|
||||
guard !isCalculating else { return }
|
||||
isCalculating = true
|
||||
|
||||
let optimalSize = FontUtils.calculateOptimalFontSize(digit: digit,
|
||||
fontName: fontName,
|
||||
weight: weight,
|
||||
design: design,
|
||||
for: geometry.size)
|
||||
if optimalSize != fontSize {
|
||||
for: size)
|
||||
|
||||
// Only update if the size is significantly different to prevent micro-adjustments
|
||||
if abs(optimalSize - fontSize) > 0.1 {
|
||||
fontSize = optimalSize
|
||||
}
|
||||
}
|
||||
|
||||
lastCalculatedSize = size
|
||||
|
||||
// Reset calculation flag after a brief delay to allow for frame completion
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.016) { // ~60fps
|
||||
isCalculating = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -107,7 +107,7 @@ struct TimeDisplayView: View {
|
||||
.minimumScaleFactor(0.1)
|
||||
.clipped() // Prevent overflow beyond bounds
|
||||
}
|
||||
.border(.yellow, width: 1)
|
||||
//.border(.yellow, width: 1)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.onOrientationChange() // Force updates on orientation changes
|
||||
}
|
||||
@ -135,5 +135,6 @@ struct TimeDisplayView: View {
|
||||
fontWeight: style.fontWeight,
|
||||
fontDesign: style.fontDesign,
|
||||
forceHorizontalMode: style.forceHorizontalMode
|
||||
) .background(Color.black)
|
||||
)
|
||||
.background(Color.black)
|
||||
}
|
||||
|
||||
@ -32,10 +32,10 @@ struct TimeSegment: View {
|
||||
glowIntensity: glowIntensity,
|
||||
fontSize: $fontSize
|
||||
)
|
||||
.border(.red, width: 1)
|
||||
//.border(.red, width: 1)
|
||||
}
|
||||
}
|
||||
.border(Color.green, width: 1)
|
||||
//.border(Color.green, width: 1)
|
||||
.frame(maxHeight: .infinity)
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user