Skip to content

Commit ed9f7ac

Browse files
committed
Code fix.
1 parent adb25ed commit ed9f7ac

File tree

1 file changed

+96
-102
lines changed

1 file changed

+96
-102
lines changed

AxisTooltipExample/Shared/ContentView.swift

Lines changed: 96 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -18,125 +18,119 @@ struct ContentView: View {
1818
@State private var alignmentIndex: Int = 0
1919

2020
var body: some View {
21-
22-
NavigationView {
23-
NavigationLink("Show") {
24-
VStack {
25-
ZStack {
26-
Text("AxisTooltip")
27-
.bold()
28-
.padding()
29-
.background(Color.pink)
30-
.cornerRadius(10)
31-
.onTapGesture {
32-
isPresented.toggle()
33-
}
34-
.axisToolTip(isPresented: $isPresented, alignment: alignments[alignmentIndex], constant: constant, foreground: {
35-
Label("Contrary to popular belief, Lorem Ipsum is not simply random text.", systemImage: "heart")
36-
.padding()
37-
.frame(width: 200)
38-
})
21+
VStack {
22+
ZStack {
23+
Text("AxisTooltip")
24+
.bold()
25+
.padding()
26+
.background(Color.pink)
27+
.cornerRadius(10)
28+
.onTapGesture {
29+
isPresented.toggle()
3930
}
40-
.background(Color.blue.opacity(0.2))
41-
Spacer()
42-
VStack {
43-
VStack(alignment: .leading, spacing: 5) {
44-
Text("● Border").foregroundColor(Color.accentColor).opacity(0.5)
45-
HStack {
46-
HStack {
47-
Text(" color :").opacity(0.5)
48-
ColorPicker("", selection: $constant.border.color).labelsHidden()
49-
}
50-
Divider().frame(maxHeight: 40)
51-
HStack {
52-
Text(" style :").opacity(0.5)
53-
Button {
54-
if constant.border.style == nil {
55-
constant.border.style = StrokeStyle(lineWidth: 2, dash: [5])
56-
}else {
57-
constant.border.style = nil
58-
}
59-
} label: {
60-
Text(constant.border.style == nil ? "Off" : "On")
61-
.padding(7)
62-
.background(constant.border.style == nil ? Color.gray.opacity(0.2) : Color.accentColor)
63-
.cornerRadius(8)
64-
}
65-
.buttonStyle((PlainButtonStyle()))
66-
}
67-
}
68-
HStack {
69-
Text(" radius :").opacity(0.5)
70-
Slider(value: $constant.border.radius, in: 0...26)
71-
Text("\(constant.border.radius, specifier: "%.2f")")
72-
}
73-
HStack {
74-
Text(" lineWidth :").opacity(0.5)
75-
Slider(value: $constant.border.lineWidth, in: 0...26)
76-
Text("\(constant.border.lineWidth, specifier: "%.2f")")
77-
}
78-
.disabled(constant.border.style != nil)
79-
.opacity(constant.border.style != nil ? 0.5 : 1)
31+
.axisToolTip(isPresented: $isPresented, alignment: alignments[alignmentIndex], constant: constant, foreground: {
32+
Label("Contrary to popular belief, Lorem Ipsum is not simply random text.", systemImage: "heart")
33+
.padding()
34+
.frame(width: 200)
35+
})
36+
}
37+
.background(Color.blue.opacity(0.2))
38+
Spacer()
39+
VStack {
40+
VStack(alignment: .leading, spacing: 5) {
41+
Text("● Border").foregroundColor(Color.accentColor).opacity(0.5)
42+
HStack {
43+
HStack {
44+
Text(" color :").opacity(0.5)
45+
ColorPicker("", selection: $constant.border.color).labelsHidden()
8046
}
81-
82-
VStack(alignment: .leading, spacing: 5) {
83-
Text("● Arrow").foregroundColor(Color.accentColor).opacity(0.5)
84-
HStack {
85-
VStack {
86-
HStack {
87-
Text(" width : ").opacity(0.5)
88-
Spacer()
89-
Text("\(constant.arrow.width, specifier: "%.2f")")
90-
}
91-
Slider(value: $constant.arrow.width, in: 0...26)
92-
}
93-
Divider().frame(maxHeight: 40)
94-
VStack {
95-
HStack {
96-
Text(" height : ").opacity(0.5)
97-
Spacer()
98-
Text("\(constant.arrow.height, specifier: "%.2f")")
99-
}
100-
Slider(value: $constant.arrow.height, in: 0...26)
47+
Divider().frame(maxHeight: 40)
48+
HStack {
49+
Text(" style :").opacity(0.5)
50+
Button {
51+
if constant.border.style == nil {
52+
constant.border.style = StrokeStyle(lineWidth: 2, dash: [5])
53+
}else {
54+
constant.border.style = nil
10155
}
56+
} label: {
57+
Text(constant.border.style == nil ? "Off" : "On")
58+
.padding(7)
59+
.background(constant.border.style == nil ? Color.gray.opacity(0.2) : Color.accentColor)
60+
.cornerRadius(8)
10261
}
62+
.buttonStyle((PlainButtonStyle()))
10363
}
104-
VStack(alignment: .leading, spacing: 5) {
105-
Text("● distance").foregroundColor(Color.accentColor).opacity(0.5)
64+
}
65+
HStack {
66+
Text(" radius :").opacity(0.5)
67+
Slider(value: $constant.border.radius, in: 0...26)
68+
Text("\(constant.border.radius, specifier: "%.2f")")
69+
}
70+
HStack {
71+
Text(" lineWidth :").opacity(0.5)
72+
Slider(value: $constant.border.lineWidth, in: 0...26)
73+
Text("\(constant.border.lineWidth, specifier: "%.2f")")
74+
}
75+
.disabled(constant.border.style != nil)
76+
.opacity(constant.border.style != nil ? 0.5 : 1)
77+
}
78+
79+
VStack(alignment: .leading, spacing: 5) {
80+
Text("● Arrow").foregroundColor(Color.accentColor).opacity(0.5)
81+
HStack {
82+
VStack {
10683
HStack {
107-
Slider(value: $constant.distance, in: 0...26)
108-
Text("\(constant.distance, specifier: "%.2f")")
84+
Text(" width : ").opacity(0.5)
85+
Spacer()
86+
Text("\(constant.arrow.width, specifier: "%.2f")")
10987
}
88+
Slider(value: $constant.arrow.width, in: 0...26)
11089
}
111-
VStack(alignment: .leading, spacing: 5) {
112-
Text("● AxisMode").foregroundColor(Color.accentColor).opacity(0.5)
90+
Divider().frame(maxHeight: 40)
91+
VStack {
11392
HStack {
114-
Picker("", selection: $constant.axisMode) {
115-
Text("Top").tag(ATAxisMode.top)
116-
Text("Bottom").tag(ATAxisMode.bottom)
117-
Text("Leading").tag(ATAxisMode.leading)
118-
Text("Trailing").tag(ATAxisMode.trailing)
119-
}
120-
.pickerStyle(SegmentedPickerStyle())
121-
Toggle("", isOn: $isPresented).labelsHidden()
93+
Text(" height : ").opacity(0.5)
94+
Spacer()
95+
Text("\(constant.arrow.height, specifier: "%.2f")")
12296
}
97+
Slider(value: $constant.arrow.height, in: 0...26)
12398
}
124-
Picker("", selection: $alignmentIndex) {
125-
ForEach(Array(alignments.enumerated()), id:\.offset) { index, align in
126-
Image(systemName: getAlignmentIcon(alignments[index])).tag(index)
127-
}
99+
}
100+
}
101+
VStack(alignment: .leading, spacing: 5) {
102+
Text("● distance").foregroundColor(Color.accentColor).opacity(0.5)
103+
HStack {
104+
Slider(value: $constant.distance, in: 0...26)
105+
Text("\(constant.distance, specifier: "%.2f")")
106+
}
107+
}
108+
VStack(alignment: .leading, spacing: 5) {
109+
Text("● AxisMode").foregroundColor(Color.accentColor).opacity(0.5)
110+
HStack {
111+
Picker("", selection: $constant.axisMode) {
112+
Text("Top").tag(ATAxisMode.top)
113+
Text("Bottom").tag(ATAxisMode.bottom)
114+
Text("Leading").tag(ATAxisMode.leading)
115+
Text("Trailing").tag(ATAxisMode.trailing)
128116
}
129117
.pickerStyle(SegmentedPickerStyle())
118+
Toggle("", isOn: $isPresented).labelsHidden()
119+
}
120+
}
121+
Picker("", selection: $alignmentIndex) {
122+
ForEach(Array(alignments.enumerated()), id:\.offset) { index, align in
123+
Image(systemName: getAlignmentIcon(alignments[index])).tag(index)
130124
}
131-
.zIndex(-1)
132125
}
133-
.font(.callout)
134-
.animation(.easeInOut, value: constant)
135-
.animation(.easeInOut, value: alignmentIndex)
136-
.padding()
137-
.navigationBarTitleDisplayMode(.inline)
126+
.pickerStyle(SegmentedPickerStyle())
138127
}
128+
.zIndex(-1)
139129
}
130+
.font(.callout)
131+
.animation(.easeInOut, value: constant)
132+
.animation(.easeInOut, value: alignmentIndex)
133+
.padding()
140134
}
141135

142136
private func getAlignmentIcon(_ alignment: Alignment) -> String {

0 commit comments

Comments
 (0)