mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-29 07:52:50 -05:00
Fix again widget positioning logic.
- This is complicated because widgets unload, and we already want to respect positioning even when unloaded. - Plus in center section we want odd number for the center one to always be centered, etc, etc.
This commit is contained in:
@@ -144,7 +144,8 @@ Card {
|
|||||||
|
|
||||||
property real availableWidth: parent.parent.parent.parent.width - avatarContainer.width - Theme.spacingM * 3 - 16 - Theme.spacingS
|
property real availableWidth: parent.parent.parent.parent.width - avatarContainer.width - Theme.spacingM * 3 - 16 - Theme.spacingS
|
||||||
property real longTextWidth: {
|
property real longTextWidth: {
|
||||||
const testMetrics = Qt.createQmlObject('import QtQuick; TextMetrics { font.pixelSize: ' + Theme.fontSizeSmall + ' }', uptimeText)
|
const fontSize = Math.round(Theme.fontSizeSmall || 12)
|
||||||
|
const testMetrics = Qt.createQmlObject('import QtQuick; TextMetrics { font.pixelSize: ' + fontSize + ' }', uptimeText)
|
||||||
testMetrics.text = UserInfoService.uptime || "up 1 hour, 23 minutes"
|
testMetrics.text = UserInfoService.uptime || "up 1 hour, 23 minutes"
|
||||||
const result = testMetrics.width
|
const result = testMetrics.width
|
||||||
testMetrics.destroy()
|
testMetrics.destroy()
|
||||||
|
|||||||
@@ -624,31 +624,80 @@ PanelWindow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (totalWidgets >= 2) {
|
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
|
|
||||||
|
|
||||||
if (centerWidgets[leftIndex] && centerWidgets[rightIndex]) {
|
let leftWidget = null
|
||||||
centerWidgets[leftIndex].x = parentCenterX - halfSpacing - centerWidgets[leftIndex].width
|
let rightWidget = null
|
||||||
centerWidgets[rightIndex].x = parentCenterX + halfSpacing
|
let leftWidgets = []
|
||||||
|
let rightWidgets = []
|
||||||
|
|
||||||
let currentX = centerWidgets[leftIndex].x
|
let currentConfigIndex = 0
|
||||||
for (var i = leftIndex - 1; i >= 0; i--) {
|
for (var i = 0; i < centerRepeater.count; i++) {
|
||||||
if (centerWidgets[i]) {
|
const item = centerRepeater.itemAt(i)
|
||||||
currentX -= (spacing + centerWidgets[i].width)
|
if (item && topBarContent.getWidgetVisible(item.widgetId)) {
|
||||||
centerWidgets[i].x = currentX
|
if (item.active && item.item) {
|
||||||
|
if (currentConfigIndex < configuredLeftIndex) {
|
||||||
|
leftWidgets.push(item.item)
|
||||||
|
} else if (currentConfigIndex === configuredLeftIndex) {
|
||||||
|
leftWidget = item.item
|
||||||
|
} else if (currentConfigIndex === configuredRightIndex) {
|
||||||
|
rightWidget = item.item
|
||||||
|
} else {
|
||||||
|
rightWidgets.push(item.item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
currentConfigIndex++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
currentX = centerWidgets[rightIndex].x + centerWidgets[rightIndex].width
|
if (leftWidget && rightWidget) {
|
||||||
for (var i = rightIndex + 1; i < totalWidgets; i++) {
|
leftWidget.x = parentCenterX - halfSpacing - leftWidget.width
|
||||||
if (centerWidgets[i]) {
|
rightWidget.x = parentCenterX + halfSpacing
|
||||||
currentX += spacing
|
|
||||||
centerWidgets[i].x = currentX
|
let currentX = leftWidget.x
|
||||||
currentX += centerWidgets[i].width
|
for (var i = leftWidgets.length - 1; i >= 0; i--) {
|
||||||
}
|
currentX -= (spacing + leftWidgets[i].width)
|
||||||
}
|
leftWidgets[i].x = currentX
|
||||||
|
}
|
||||||
|
|
||||||
|
currentX = rightWidget.x + rightWidget.width
|
||||||
|
for (var i = 0; i < rightWidgets.length; i++) {
|
||||||
|
currentX += spacing
|
||||||
|
rightWidgets[i].x = currentX
|
||||||
|
currentX += rightWidgets[i].width
|
||||||
|
}
|
||||||
|
} else if (leftWidget && !rightWidget) {
|
||||||
|
leftWidget.x = parentCenterX - halfSpacing - leftWidget.width
|
||||||
|
|
||||||
|
let currentX = leftWidget.x
|
||||||
|
for (var i = leftWidgets.length - 1; i >= 0; i--) {
|
||||||
|
currentX -= (spacing + leftWidgets[i].width)
|
||||||
|
leftWidgets[i].x = currentX
|
||||||
|
}
|
||||||
|
|
||||||
|
currentX = leftWidget.x + leftWidget.width + spacing
|
||||||
|
for (var i = 0; i < rightWidgets.length; i++) {
|
||||||
|
currentX += spacing
|
||||||
|
rightWidgets[i].x = currentX
|
||||||
|
currentX += rightWidgets[i].width
|
||||||
|
}
|
||||||
|
} else if (!leftWidget && rightWidget) {
|
||||||
|
rightWidget.x = parentCenterX + halfSpacing
|
||||||
|
|
||||||
|
let currentX = rightWidget.x - spacing
|
||||||
|
for (var i = leftWidgets.length - 1; i >= 0; i--) {
|
||||||
|
currentX -= leftWidgets[i].width
|
||||||
|
leftWidgets[i].x = currentX
|
||||||
|
currentX -= spacing
|
||||||
|
}
|
||||||
|
|
||||||
|
currentX = rightWidget.x + rightWidget.width
|
||||||
|
for (var i = 0; i < rightWidgets.length; i++) {
|
||||||
|
currentX += spacing
|
||||||
|
rightWidgets[i].x = currentX
|
||||||
|
currentX += rightWidgets[i].width
|
||||||
}
|
}
|
||||||
} else if (totalWidgets === 1 && centerWidgets[0]) {
|
} else if (totalWidgets === 1 && centerWidgets[0]) {
|
||||||
centerWidgets[0].x = parentCenterX - (centerWidgets[0].width / 2)
|
centerWidgets[0].x = parentCenterX - (centerWidgets[0].width / 2)
|
||||||
|
|||||||
Reference in New Issue
Block a user