SmartPanel: improved snapping behavior

This commit is contained in:
ItsLemmy
2025-11-11 07:22:48 -05:00
parent afcadb86d7
commit 3c8a49d7c0
2 changed files with 16 additions and 6 deletions

View File

@@ -1555,8 +1555,8 @@
"label": "Appearance"
},
"settings-panel-attached-to-bar": {
"description": "Keep the Settings window aligned with the bar for a unified look.",
"label": "Snap Settings window to bar"
"description": "Keep the settings window aligned with the bar for a unified look.",
"label": "Snap settings window to bar"
},
"shadows": {
"description": "Enables drop shadows under bars and panels.",

View File

@@ -382,9 +382,14 @@ Item {
rightEdgePos = root.width - root.barMarginH - Style.barHeight - panelWidth
}
if (Math.abs(calculatedX - leftEdgePos) <= root.edgeSnapDistance) {
// Only snap to left edge if panel is actually meant to be at left (or no explicit anchor)
var shouldSnapToLeft = root.effectivePanelAnchorLeft || (!root.hasExplicitHorizontalAnchor && root.barPosition === "left")
// Only snap to right edge if panel is actually meant to be at right (or no explicit anchor)
var shouldSnapToRight = root.effectivePanelAnchorRight || (!root.hasExplicitHorizontalAnchor && root.barPosition === "right")
if (shouldSnapToLeft && Math.abs(calculatedX - leftEdgePos) <= root.edgeSnapDistance) {
calculatedX = leftEdgePos
} else if (Math.abs(calculatedX - rightEdgePos) <= root.edgeSnapDistance) {
} else if (shouldSnapToRight && Math.abs(calculatedX - rightEdgePos) <= root.edgeSnapDistance) {
calculatedX = rightEdgePos
}
}
@@ -515,9 +520,14 @@ Item {
bottomEdgePos = root.height - root.barMarginV - Style.barHeight - panelHeight
}
if (Math.abs(calculatedY - topEdgePos) <= root.edgeSnapDistance) {
// Only snap to top edge if panel is actually meant to be at top (or no explicit anchor)
var shouldSnapToTop = root.effectivePanelAnchorTop || (!root.hasExplicitVerticalAnchor && root.barPosition === "top")
// Only snap to bottom edge if panel is actually meant to be at bottom (or no explicit anchor)
var shouldSnapToBottom = root.effectivePanelAnchorBottom || (!root.hasExplicitVerticalAnchor && root.barPosition === "bottom")
if (shouldSnapToTop && Math.abs(calculatedY - topEdgePos) <= root.edgeSnapDistance) {
calculatedY = topEdgePos
} else if (Math.abs(calculatedY - bottomEdgePos) <= root.edgeSnapDistance) {
} else if (shouldSnapToBottom && Math.abs(calculatedY - bottomEdgePos) <= root.edgeSnapDistance) {
calculatedY = bottomEdgePos
}
}