1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-24 21:42:51 -05:00

feat: add support for geometric centering (#856)

Introduces a configurable centering mode.
- Adds 'geometric' option.
- Retains 'index' as the default value to preserve existing behavior.
This commit is contained in:
Guilherme Pagano
2025-12-02 16:43:51 -03:00
committed by GitHub
parent 2e3f330058
commit db3610fcdb
4 changed files with 117 additions and 6 deletions

View File

@@ -30,6 +30,64 @@ Item {
property real totalSize: 0
function updateLayout() {
if (SettingsData.centeringMode === "geometric") {
applyGeometricLayout();
} else {
// Default to index layout or if value is not 'geometric'
applyIndexLayout();
}
}
function applyGeometricLayout() {
if ((isVertical ? height : width) <= 0 || !visible) {
return;
}
centerWidgets = [];
totalWidgets = 0;
totalSize = 0;
for (var i = 0; i < centerRepeater.count; i++) {
const item = centerRepeater.itemAt(i);
if (item && item.active && item.item && getWidgetVisible(item.widgetId)) {
centerWidgets.push(item.item);
totalWidgets++;
totalSize += isVertical ? item.item.height : item.item.width;
}
}
if (totalWidgets === 0) {
return;
}
if (totalWidgets > 1) {
totalSize += spacing * (totalWidgets - 1);
}
positionWidgetsGeometric();
}
function positionWidgetsGeometric() {
const parentLength = isVertical ? height : width;
const parentCenter = parentLength / 2;
let currentPos = parentCenter - (totalSize / 2);
centerWidgets.forEach(widget => {
if (isVertical) {
widget.anchors.verticalCenter = undefined;
widget.y = currentPos;
} else {
widget.anchors.horizontalCenter = undefined;
widget.x = currentPos;
}
const widgetSize = isVertical ? widget.height : widget.width;
currentPos += widgetSize + spacing;
});
}
function applyIndexLayout() {
if ((isVertical ? height : width) <= 0 || !visible) {
return;
}
@@ -85,10 +143,10 @@ Item {
totalSize += spacing * (totalWidgets - 1);
}
positionWidgets(configuredWidgets, configuredMiddleWidget, configuredLeftWidget, configuredRightWidget);
positionWidgetsByIndex(configuredWidgets, configuredMiddleWidget, configuredLeftWidget, configuredRightWidget);
}
function positionWidgets(configuredWidgets, configuredMiddleWidget, configuredLeftWidget, configuredRightWidget) {
function positionWidgetsByIndex(configuredWidgets, configuredMiddleWidget, configuredLeftWidget, configuredRightWidget) {
const parentCenter = (isVertical ? height : width) / 2;
const isOddConfigured = configuredWidgets % 2 === 1;
@@ -508,4 +566,11 @@ Item {
}
}
}
Connections {
target: SettingsData
function onCenteringModeChanged() {
layoutTimer.restart();
}
}
}