1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-28 15:32:50 -05:00

Update Dankbar center widget positioning

This commit is contained in:
purian23
2025-11-09 19:46:21 -05:00
parent 2714c0f4ad
commit c52483da2c

View File

@@ -24,8 +24,7 @@ Item {
property real totalSize: 0 property real totalSize: 0
function updateLayout() { function updateLayout() {
const containerSize = isVertical ? height : width if ((isVertical ? height : width) <= 0 || !visible) {
if (containerSize <= 0 || !visible) {
return return
} }
@@ -33,33 +32,29 @@ Item {
totalWidgets = 0 totalWidgets = 0
totalSize = 0 totalSize = 0
let configuredWidgets = 0
for (var i = 0; i < centerRepeater.count; i++) { for (var i = 0; i < centerRepeater.count; i++) {
const item = centerRepeater.itemAt(i) const item = centerRepeater.itemAt(i)
if (item && getWidgetVisible(item.widgetId)) { if (item && getWidgetVisible(item.widgetId) && item.active && item.item) {
configuredWidgets++ centerWidgets.push(item.item)
if (item.active && item.item) { totalWidgets++
centerWidgets.push(item.item) totalSize += isVertical ? item.item.height : item.item.width
totalWidgets++
totalSize += isVertical ? item.item.height : item.item.width
}
} }
} }
if (totalWidgets === 0) {
return
}
if (totalWidgets > 1) { if (totalWidgets > 1) {
totalSize += spacing * (totalWidgets - 1) totalSize += spacing * (totalWidgets - 1)
} }
positionWidgets(configuredWidgets) positionWidgets()
} }
function positionWidgets(configuredWidgets) { function positionWidgets() {
if (totalWidgets === 0 || (isVertical ? height : width) <= 0) {
return
}
const parentCenter = (isVertical ? height : width) / 2 const parentCenter = (isVertical ? height : width) / 2
const isOdd = configuredWidgets % 2 === 1 const isOdd = totalWidgets % 2 === 1
centerWidgets.forEach(widget => { centerWidgets.forEach(widget => {
if (isVertical) { if (isVertical) {
@@ -70,192 +65,74 @@ Item {
}) })
if (isOdd) { if (isOdd) {
const middleIndex = Math.floor(configuredWidgets / 2) const middleIndex = Math.floor(totalWidgets / 2)
let currentActiveIndex = 0 const middleWidget = centerWidgets[middleIndex]
let middleWidget = null const middleSize = isVertical ? middleWidget.height : middleWidget.width
for (var i = 0; i < centerRepeater.count; i++) { if (isVertical) {
const item = centerRepeater.itemAt(i) middleWidget.y = parentCenter - (middleSize / 2)
if (item && getWidgetVisible(item.widgetId)) { } else {
if (currentActiveIndex === middleIndex && item.active && item.item) { middleWidget.x = parentCenter - (middleSize / 2)
middleWidget = item.item }
break
} let currentPos = isVertical ? middleWidget.y : middleWidget.x
currentActiveIndex++ for (var i = middleIndex - 1; i >= 0; i--) {
const size = isVertical ? centerWidgets[i].height : centerWidgets[i].width
currentPos -= (spacing + size)
if (isVertical) {
centerWidgets[i].y = currentPos
} else {
centerWidgets[i].x = currentPos
} }
} }
if (middleWidget) { currentPos = (isVertical ? middleWidget.y : middleWidget.x) + middleSize
const middleSize = isVertical ? middleWidget.height : middleWidget.width for (var i = middleIndex + 1; i < totalWidgets; i++) {
currentPos += spacing
if (isVertical) { if (isVertical) {
middleWidget.y = parentCenter - (middleSize / 2) centerWidgets[i].y = currentPos
} else { } else {
middleWidget.x = parentCenter - (middleSize / 2) centerWidgets[i].x = currentPos
}
let leftWidgets = []
let rightWidgets = []
let foundMiddle = false
for (var i = 0; i < centerWidgets.length; i++) {
if (centerWidgets[i] === middleWidget) {
foundMiddle = true
continue
}
if (!foundMiddle) {
leftWidgets.push(centerWidgets[i])
} else {
rightWidgets.push(centerWidgets[i])
}
}
let currentPos = isVertical ? middleWidget.y : middleWidget.x
for (var i = leftWidgets.length - 1; i >= 0; i--) {
const size = isVertical ? leftWidgets[i].height : leftWidgets[i].width
currentPos -= (spacing + size)
if (isVertical) {
leftWidgets[i].y = currentPos
} else {
leftWidgets[i].x = currentPos
}
}
currentPos = (isVertical ? middleWidget.y : middleWidget.x) + middleSize
for (var i = 0; i < rightWidgets.length; i++) {
currentPos += spacing
if (isVertical) {
rightWidgets[i].y = currentPos
} else {
rightWidgets[i].x = currentPos
}
currentPos += isVertical ? rightWidgets[i].height : rightWidgets[i].width
} }
currentPos += isVertical ? centerWidgets[i].height : centerWidgets[i].width
} }
} else { } else {
let configuredLeftIndex = (configuredWidgets / 2) - 1 const leftIndex = (totalWidgets / 2) - 1
let configuredRightIndex = configuredWidgets / 2 const rightIndex = totalWidgets / 2
const halfSpacing = spacing / 2 const halfSpacing = spacing / 2
let leftWidget = null const leftWidget = centerWidgets[leftIndex]
let rightWidget = null const rightWidget = centerWidgets[rightIndex]
let leftWidgets = [] const leftSize = isVertical ? leftWidget.height : leftWidget.width
let rightWidgets = []
let currentConfigIndex = 0 if (isVertical) {
for (var i = 0; i < centerRepeater.count; i++) { leftWidget.y = parentCenter - halfSpacing - leftSize
const item = centerRepeater.itemAt(i) rightWidget.y = parentCenter + halfSpacing
if (item && getWidgetVisible(item.widgetId)) { } else {
if (item.active && item.item) { leftWidget.x = parentCenter - halfSpacing - leftSize
if (currentConfigIndex < configuredLeftIndex) { rightWidget.x = parentCenter + halfSpacing
leftWidgets.push(item.item) }
} else if (currentConfigIndex === configuredLeftIndex) {
leftWidget = item.item let currentPos = isVertical ? leftWidget.y : leftWidget.x
} else if (currentConfigIndex === configuredRightIndex) { for (var i = leftIndex - 1; i >= 0; i--) {
rightWidget = item.item const size = isVertical ? centerWidgets[i].height : centerWidgets[i].width
} else { currentPos -= (spacing + size)
rightWidgets.push(item.item) if (isVertical) {
} centerWidgets[i].y = currentPos
} } else {
currentConfigIndex++ centerWidgets[i].x = currentPos
} }
} }
if (leftWidget && rightWidget) { currentPos = (isVertical ? rightWidget.y + rightWidget.height : rightWidget.x + rightWidget.width)
const leftSize = isVertical ? leftWidget.height : leftWidget.width for (var i = rightIndex + 1; i < totalWidgets; i++) {
currentPos += spacing
if (isVertical) { if (isVertical) {
leftWidget.y = parentCenter - halfSpacing - leftSize centerWidgets[i].y = currentPos
rightWidget.y = parentCenter + halfSpacing
} else { } else {
leftWidget.x = parentCenter - halfSpacing - leftSize centerWidgets[i].x = currentPos
rightWidget.x = parentCenter + halfSpacing
}
let currentPos = isVertical ? leftWidget.y : leftWidget.x
for (var i = leftWidgets.length - 1; i >= 0; i--) {
const size = isVertical ? leftWidgets[i].height : leftWidgets[i].width
currentPos -= (spacing + size)
if (isVertical) {
leftWidgets[i].y = currentPos
} else {
leftWidgets[i].x = currentPos
}
}
currentPos = (isVertical ? rightWidget.y + rightWidget.height : rightWidget.x + rightWidget.width)
for (var i = 0; i < rightWidgets.length; i++) {
currentPos += spacing
if (isVertical) {
rightWidgets[i].y = currentPos
} else {
rightWidgets[i].x = currentPos
}
currentPos += isVertical ? rightWidgets[i].height : rightWidgets[i].width
}
} else if (leftWidget && !rightWidget) {
const leftSize = isVertical ? leftWidget.height : leftWidget.width
if (isVertical) {
leftWidget.y = parentCenter - halfSpacing - leftSize
} else {
leftWidget.x = parentCenter - halfSpacing - leftSize
}
let currentPos = isVertical ? leftWidget.y : leftWidget.x
for (var i = leftWidgets.length - 1; i >= 0; i--) {
const size = isVertical ? leftWidgets[i].height : leftWidgets[i].width
currentPos -= (spacing + size)
if (isVertical) {
leftWidgets[i].y = currentPos
} else {
leftWidgets[i].x = currentPos
}
}
currentPos = (isVertical ? leftWidget.y + leftWidget.height : leftWidget.x + leftWidget.width) + spacing
for (var i = 0; i < rightWidgets.length; i++) {
currentPos += spacing
if (isVertical) {
rightWidgets[i].y = currentPos
} else {
rightWidgets[i].x = currentPos
}
currentPos += isVertical ? rightWidgets[i].height : rightWidgets[i].width
}
} else if (!leftWidget && rightWidget) {
if (isVertical) {
rightWidget.y = parentCenter + halfSpacing
} else {
rightWidget.x = parentCenter + halfSpacing
}
let currentPos = (isVertical ? rightWidget.y : rightWidget.x) - spacing
for (var i = leftWidgets.length - 1; i >= 0; i--) {
const size = isVertical ? leftWidgets[i].height : leftWidgets[i].width
currentPos -= size
if (isVertical) {
leftWidgets[i].y = currentPos
} else {
leftWidgets[i].x = currentPos
}
currentPos -= spacing
}
currentPos = (isVertical ? rightWidget.y + rightWidget.height : rightWidget.x + rightWidget.width)
for (var i = 0; i < rightWidgets.length; i++) {
currentPos += spacing
if (isVertical) {
rightWidgets[i].y = currentPos
} else {
rightWidgets[i].x = currentPos
}
currentPos += isVertical ? rightWidgets[i].height : rightWidgets[i].width
}
} else if (totalWidgets === 1 && centerWidgets[0]) {
const size = isVertical ? centerWidgets[0].height : centerWidgets[0].width
if (isVertical) {
centerWidgets[0].y = parentCenter - (size / 2)
} else {
centerWidgets[0].x = parentCenter - (size / 2)
} }
currentPos += isVertical ? centerWidgets[i].height : centerWidgets[i].width
} }
} }
} }