From 22bd059642c5e59eeb012792c7b09fe5ded1ea30 Mon Sep 17 00:00:00 2001 From: wjyrich Date: Thu, 12 Mar 2026 10:56:51 +0800 Subject: [PATCH] fix: prevent negative margins in dock center alignment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed dock layout calculation to prevent negative margins when centering dock items. Changed Layout.leftMargin and Layout.topMargin calculations to use Math.max(0, ...) to ensure margins are never negative. This prevents layout issues when dock items are larger than available space. The issue occurred when the dock center part's implicit width/height was larger than the available dock space, causing negative margins that could break the layout. The fix ensures margins are clamped to zero minimum, maintaining proper visual alignment even in constrained space conditions. Influence: 1. Test dock with various item counts and sizes to verify centering works correctly 2. Verify dock layout when items exceed available space 3. Test both horizontal and vertical dock orientations 4. Check that dragging and resizing behaviors remain smooth 5. Validate center alignment with different panel sizes fix: 修复任务栏居中布局负边距问题 修复了任务栏居中布局计算,防止在居中任务栏项目时出现负边距。将 Layout.leftMargin和Layout.topMargin计算改为使用Math.max(0, ...),确保边 距永远不会为负值。这解决了当任务栏项目大于可用空间时的布局问题。 问题发生在任务栏中心部分的隐式宽度/高度大于可用任务栏空间时,导致负边距 可能破坏布局。修复确保边距被限制在最小零值,即使在空间受限的情况下也能保 持正确的视觉对齐。 Influence: 1. 测试不同项目数量和大小下任务栏的居中功能 2. 验证项目超过可用空间时的任务栏布局 3. 测试水平和垂直两种任务栏方向 4. 检查拖拽和调整大小行为是否保持流畅 5. 验证不同面板大小下的居中对齐效果 PMS: BUG-351805 --- panels/dock/package/main.qml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/panels/dock/package/main.qml b/panels/dock/package/main.qml index 17263de63..5067170da 100644 --- a/panels/dock/package/main.qml +++ b/panels/dock/package/main.qml @@ -516,9 +516,9 @@ Window { onXChanged: dockCenterPartPosChanged() onYChanged: dockCenterPartPosChanged() Layout.leftMargin: !useColumnLayout && Panel.itemAlignment === Dock.CenterAlignment ? - (dock.width - dockCenterPart.implicitWidth) / 2 - (dockLeftPart.implicitWidth + 20) + Math.min((dock.width - dockCenterPart.implicitWidth) / 2 - (dockRightPart.implicitWidth + 20), 0) : 0 + Math.max(0, (dock.width - dockCenterPart.implicitWidth) / 2 - (dockLeftPart.implicitWidth + 20) + Math.min((dock.width - dockCenterPart.implicitWidth) / 2 - (dockRightPart.implicitWidth + 20), 0)) : 0 Layout.topMargin: useColumnLayout && Panel.itemAlignment === Dock.CenterAlignment ? - (dock.height - dockCenterPart.implicitHeight) / 2 - (dockLeftPart.implicitHeight + 20) + Math.min((dock.height - dockCenterPart.implicitHeight) / 2 - (dockRightPart.implicitHeight + 20), 0) : 0 + Math.max(0, (dock.height - dockCenterPart.implicitHeight) / 2 - (dockLeftPart.implicitHeight + 20) + Math.min((dock.height - dockCenterPart.implicitHeight) / 2 - (dockRightPart.implicitHeight + 20), 0)) : 0 Behavior on Layout.leftMargin { enabled: !dock.isDragging && !Applet.isResizing