Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widget Wizard "Reset" button #725

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ class FiniteWidgetCollection: LayoutWidgetCollection {
accumulator + element.type.cost
} + (widgetDragging?.type.cost ?? 0)
}

func replaceItems(with widgets: [LayoutWidgetType]) {
self.items = widgets.map { LayoutWidget($0) }
}
}

class UnorderedWidgetCollection: FiniteWidgetCollection {}
Expand All @@ -95,6 +99,11 @@ class OrderedWidgetCollection: FiniteWidgetCollection {
self.itemsWithPlaceholder = self.items
}

override func replaceItems(with widgets: [LayoutWidgetType]) {
self.items = widgets.map { LayoutWidget($0) }
self.itemsWithPlaceholder = self.items
}

override func update(isHovered: Bool, value: DragGesture.Value, widgetDragging: LayoutWidget) {
if isHovered {
if value.translation.width == 0, items.contains(widgetDragging) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ struct LayoutWidgetEditView: View {
var onSave: (_ widgets: [LayoutWidgetType]) -> Void

@Namespace var animation
@EnvironmentObject var layoutWidgetTracker: LayoutWidgetTracker

@StateObject var barCollection: OrderedWidgetCollection
@StateObject var trayCollection: InfiniteWidgetCollection
Expand Down Expand Up @@ -69,7 +68,17 @@ struct LayoutWidgetEditView: View {
.padding(.vertical, 40)
.zIndex(1)
Spacer()
Button("Reset") {
barCollection.replaceItems(with: [.scoreCounter, .infoStack, .save, .reply])
Task {
onSave(barCollection.items.map(\.type))
}

}
.foregroundStyle(.tertiary)
.padding(.bottom, 20)
}
.fancyTabScrollCompatible()
}
.gesture(
DragGesture(minimumDistance: 0)
Expand Down Expand Up @@ -99,7 +108,6 @@ struct LayoutWidgetEditView: View {
.background(Color(UIColor.systemGroupedBackground))
.onChange(of: isPresented) { newValue in
if newValue == false {
print("SAVING")
Task {
onSave(barCollection.items.map(\.type))
}
Expand Down Expand Up @@ -179,16 +187,20 @@ struct LayoutWidgetEditView: View {
Spacer()
}
.frame(maxWidth: .infinity)
.frame(height: 300)
.frame(height: 130)
.overlay {
// little hack to determine the frame after rendering and update the collection
GeometryReader { geo in
Color.clear
.frame(maxWidth: .infinity, maxHeight: .infinity)
.onAppear {

trayCollection.rect = geo.frame(in: .global)
.offsetBy(dx: -outerFrame.origin.x, dy: -outerFrame.origin.y - 90)
var rect = geo.frame(in: .global)
.offsetBy(dx: -outerFrame.origin.x, dy: -outerFrame.origin.y)
// Extend the rect into the infoText area a little
rect.origin.y -= 130
rect.size.height += 130
trayCollection.rect = rect
}
}
}
Expand Down