refactor(Turnips): remove useless custom Alignment Guide
* After better understanding of how Aligment Guide works, it's useless
to create a custom one for ZStack, I can directly use .topTrailing +
.top as custom explicit Alignment
MODIFY
ACHNBrowserUI/ACHNBrowserUI/views/turnips/charts/TurnipsChartGrid.swift
ACHNBrowserUI/ACHNBrowserUI/views/turnips/charts/TurnipsChartGrid.swift
@@ -46,16 +46,3 @@ struct TurnipsChartGrid: Shape {
extension TurnipsChartGrid {
enum Display { case vertical, horizontal }
}
-
-extension VerticalAlignment {
- private enum VerticalLegendAlignment: AlignmentID {
- static func defaultValue(in context: ViewDimensions) -> CGFloat {
- context[VerticalAlignment.center]
- }
- }
- static let verticalLegendAlignment = VerticalAlignment(VerticalLegendAlignment.self)
-}
-
-extension Alignment {
- static let verticalLegendAlignment = Alignment(horizontal: .trailing, vertical: .verticalLegendAlignment)
-}

MODIFY
ACHNBrowserUI/ACHNBrowserUI/views/turnips/charts/TurnipsChartVerticalLegend.swift
ACHNBrowserUI/ACHNBrowserUI/views/turnips/charts/TurnipsChartVerticalLegend.swift
@@ -11,27 +11,29 @@ import Backend
struct TurnipsChartVerticalLegend: View {
let predictions: TurnipPredictions
-
var body: some View {
- GeometryReader(content: texts)
+ GeometryReader(content: computeTexts)
}
- func texts(geometry: GeometryProxy) -> some View {
+ func computeTexts(geometry: GeometryProxy) -> some View {
let frame = geometry.frame(in: .local)
let (minY, maxY, ratioY, _) = predictions.minMax?.roundedMinMaxAndRatios(rect: frame) ?? (0, 0, 0, 0)
let min = Int(minY)
let max = Int(maxY) + TurnipsChart.steps
let values = Array(stride(from: min, to: max, by: TurnipsChart.steps))
+ return texts(values: values, ratioY: ratioY)
+ }
- return ZStack(alignment: .verticalLegendAlignment) {
+ func texts(values: [Int], ratioY: CGFloat) -> some View {
+ ZStack(alignment: .topTrailing) {
ForEach(values, id: \.self) { value in
Text("\(value)")
.font(.footnote)
.fontWeight(.semibold)
.foregroundColor(.text)
- .alignmentGuide(.verticalLegendAlignment) { d in CGFloat(value) * ratioY }
- }.background(Color.red)
- }.background(Color.blue)
+ .alignmentGuide(.top) { d in CGFloat(value) * ratioY }
+ }
+ }
}
}

refactor(Turnips): remove useless custom Alignment Guide

* After better understanding of how Aligment Guide works, it's useless
to create a custom one for ZStack, I can directly use .topTrailing +
.top as custom explicit Alignment