From 18a0fe3977175f3f7a945b300524fd2cd37fef28 Mon Sep 17 00:00:00 2001
From: Ariver <shanghai3168@gmail.com>
Date: Sat, 13 Jun 2026 15:15:47 +0800
Subject: [PATCH] Add app grid usage tips

---
 src/Apptag/AppGridCollectionView.swift |   63 +++++++++++++++++++++++++------
 1 files changed, 51 insertions(+), 12 deletions(-)

diff --git a/src/Apptag/AppGridCollectionView.swift b/src/Apptag/AppGridCollectionView.swift
index 68e508c..cfcd15d 100644
--- a/src/Apptag/AppGridCollectionView.swift
+++ b/src/Apptag/AppGridCollectionView.swift
@@ -38,6 +38,7 @@
     let bubbleDisabled: Bool
     let showUncommonAppBubbles: Bool
     let highlightedGroupName: String?
+    let bottomContentPadding: CGFloat
     let contentRevision: Int
     let scrollTargetID: String?
     let scrollRequestToken: Int
@@ -71,6 +72,7 @@
             bubbleDisabled: bubbleDisabled,
             showUncommonAppBubbles: showUncommonAppBubbles,
             highlightedGroupName: highlightedGroupName,
+            bottomContentPadding: bottomContentPadding,
             contentRevision: contentRevision,
             scrollTargetID: scrollTargetID,
             scrollRequestToken: scrollRequestToken,
@@ -97,6 +99,7 @@
         private var scrollBubbleDisabled = false
         var showUncommonAppBubbles = AppDefaults.showUncommonAppBubbles
         var highlightedGroupName: String?
+        var bottomContentPadding: CGFloat = 0
         var contentRevision = 0
         var scrollTargetID: String?
         var scrollRequestToken = 0
@@ -129,6 +132,7 @@
             bubbleDisabled: Bool,
             showUncommonAppBubbles: Bool,
             highlightedGroupName: String?,
+            bottomContentPadding: CGFloat,
             contentRevision: Int,
             scrollTargetID: String?,
             scrollRequestToken: Int,
@@ -150,6 +154,7 @@
             self.externalBubbleDisabled = bubbleDisabled
             self.showUncommonAppBubbles = showUncommonAppBubbles
             self.highlightedGroupName = highlightedGroupName
+            self.bottomContentPadding = max(0, bottomContentPadding)
             self.contentRevision = contentRevision
             self.scrollTargetID = scrollTargetID
             self.scrollRequestToken = scrollRequestToken
@@ -169,6 +174,7 @@
                 iconSize: iconSize,
                 showNames: showNames,
                 showUncommonAppBubbles: showUncommonAppBubbles,
+                bottomContentPadding: self.bottomContentPadding,
                 contentRevision: contentRevision
             )
             if nextSignature != contentSignature {
@@ -282,10 +288,16 @@
                 if activeReorderCard === card {
                     activeReorderCard = nil
                 }
+                if lastReorderContainerID == card.containerID {
+                    lastReorderContainerID = ""
+                    lastReorderScreenFrame = nil
+                }
                 return
             }
             activeReorderCard?.clearReorderInsertion()
             activeReorderCard = nil
+            lastReorderContainerID = ""
+            lastReorderScreenFrame = nil
         }
 
         fileprivate func activeReorderPath(in containerID: String, copy: Bool) -> String? {
@@ -308,7 +320,8 @@
                   let lastReorderScreenFrame
             else { return false }
 
-            return lastReorderScreenFrame.insetBy(dx: -44, dy: -44).contains(screenPoint)
+            let guardOutset = AppGridCollectionMetrics.reorderEmptyDropCancelOutset
+            return lastReorderScreenFrame.insetBy(dx: -guardOutset, dy: -guardOutset).contains(screenPoint)
         }
 
         private static func signature(
@@ -317,6 +330,7 @@
             iconSize: CGFloat,
             showNames: Bool,
             showUncommonAppBubbles: Bool,
+            bottomContentPadding: CGFloat,
             contentRevision: Int
         ) -> String {
             let colorPart = tagColors
@@ -328,6 +342,7 @@
                 "\(Int(iconSize.rounded()))",
                 showNames ? "names" : "nonames",
                 showUncommonAppBubbles ? "uncommon" : "allbubbles",
+                "bottom=\(Int(bottomContentPadding.rounded()))",
                 colorPart,
                 "rev=\(contentRevision)"
             ].joined(separator: "|")
@@ -560,7 +575,8 @@
             groups: visibleGroups,
             contentWidth: collectionView.bounds.width,
             iconSize: iconSize,
-            displayMode: coordinator?.displayMode ?? AppDefaults.displayMode
+            displayMode: coordinator?.displayMode ?? AppDefaults.displayMode,
+            bottomContentPadding: coordinator?.bottomContentPadding ?? 0
         )
 
         var nextAttributes: [IndexPath: NSCollectionViewLayoutAttributes] = [:]
@@ -606,22 +622,39 @@
         groups: [TagGroup],
         contentWidth: CGFloat,
         iconSize: CGFloat,
-        displayMode: String
+        displayMode: String,
+        bottomContentPadding: CGFloat
     ) -> LayoutPlan {
         switch AppGridCollectionDisplayMode(displayMode) {
         case .flat:
-            return makeFlatPlan(groups: groups, contentWidth: contentWidth, iconSize: iconSize)
+            return makeFlatPlan(
+                groups: groups,
+                contentWidth: contentWidth,
+                iconSize: iconSize,
+                bottomContentPadding: bottomContentPadding
+            )
         case .masonryContainer:
-            return makeMasonryPlan(groups: groups, contentWidth: contentWidth, iconSize: iconSize)
+            return makeMasonryPlan(
+                groups: groups,
+                contentWidth: contentWidth,
+                iconSize: iconSize,
+                bottomContentPadding: bottomContentPadding
+            )
         case .gridContainer:
-            return makeGridPlan(groups: groups, contentWidth: contentWidth, iconSize: iconSize)
+            return makeGridPlan(
+                groups: groups,
+                contentWidth: contentWidth,
+                iconSize: iconSize,
+                bottomContentPadding: bottomContentPadding
+            )
         }
     }
 
     private static func makeGridPlan(
         groups: [TagGroup],
         contentWidth: CGFloat,
-        iconSize: CGFloat
+        iconSize: CGFloat,
+        bottomContentPadding: CGFloat
     ) -> LayoutPlan {
         let boundedContentWidth = max(1, contentWidth)
         let outerPadding = AppGridCollectionMetrics.outerPadding
@@ -651,7 +684,8 @@
             y += height + gap
         }
 
-        let contentHeight = rows.isEmpty ? outerPadding * 2 : y - gap + outerPadding
+        let contentHeight = (rows.isEmpty ? outerPadding * 2 : y - gap + outerPadding)
+            + max(0, bottomContentPadding)
         return LayoutPlan(
             items: items,
             contentSize: NSSize(width: boundedContentWidth, height: max(1, contentHeight))
@@ -661,7 +695,8 @@
     private static func makeFlatPlan(
         groups: [TagGroup],
         contentWidth: CGFloat,
-        iconSize: CGFloat
+        iconSize: CGFloat,
+        bottomContentPadding: CGFloat
     ) -> LayoutPlan {
         let boundedContentWidth = max(1, contentWidth)
         let outerPadding = AppGridCollectionMetrics.outerPadding
@@ -684,7 +719,8 @@
             y += height + AppGridCollectionMetrics.flatGroupGap
         }
 
-        let contentHeight = groups.isEmpty ? outerPadding * 2 : y - AppGridCollectionMetrics.flatGroupGap + outerPadding
+        let contentHeight = (groups.isEmpty ? outerPadding * 2 : y - AppGridCollectionMetrics.flatGroupGap + outerPadding)
+            + max(0, bottomContentPadding)
         return LayoutPlan(
             items: items,
             contentSize: NSSize(width: boundedContentWidth, height: max(1, contentHeight))
@@ -694,7 +730,8 @@
     private static func makeMasonryPlan(
         groups: [TagGroup],
         contentWidth: CGFloat,
-        iconSize: CGFloat
+        iconSize: CGFloat,
+        bottomContentPadding: CGFloat
     ) -> LayoutPlan {
         let boundedContentWidth = max(1, contentWidth)
         let outerPadding = AppGridCollectionMetrics.outerPadding
@@ -724,7 +761,8 @@
         }
 
         let tallest = columnHeights.max() ?? outerPadding
-        let contentHeight = groups.isEmpty ? outerPadding * 2 : tallest - gap + outerPadding
+        let contentHeight = (groups.isEmpty ? outerPadding * 2 : tallest - gap + outerPadding)
+            + max(0, bottomContentPadding)
         return LayoutPlan(
             items: items,
             contentSize: NSSize(width: boundedContentWidth, height: max(1, contentHeight))
@@ -860,6 +898,7 @@
     static let headerBottomGap: CGFloat = 6
     static let iconColumnGap: CGFloat = 6
     static let iconRowGap: CGFloat = 2
+    static let reorderEmptyDropCancelOutset: CGFloat = 4
     static let hoverScale: CGFloat = 1.22
     static let labelHeight: CGFloat = 14
 

--
Gitblit v1.9.3