diff --git a/Mlem/Models/Settings/LayoutWidgets/LayoutWidgetCollection.swift b/Mlem/Models/Settings/LayoutWidgets/LayoutWidgetCollection.swift index 51e7a9a0c..db570f3ef 100644 --- a/Mlem/Models/Settings/LayoutWidgets/LayoutWidgetCollection.swift +++ b/Mlem/Models/Settings/LayoutWidgets/LayoutWidgetCollection.swift @@ -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 {} @@ -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) { diff --git a/Mlem/Views/Tabs/Settings/Components/Views/Appearance/Shared/LayoutWidgetEditView.swift b/Mlem/Views/Tabs/Settings/Components/Views/Appearance/Shared/LayoutWidgetEditView.swift index ee90b0084..7d43b5e6c 100644 --- a/Mlem/Views/Tabs/Settings/Components/Views/Appearance/Shared/LayoutWidgetEditView.swift +++ b/Mlem/Views/Tabs/Settings/Components/Views/Appearance/Shared/LayoutWidgetEditView.swift @@ -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 @@ -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) @@ -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)) } @@ -179,7 +187,7 @@ 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 @@ -187,8 +195,12 @@ struct LayoutWidgetEditView: View { .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 } } }