mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-25 05:52:50 -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:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user