mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-26 14:32:52 -05:00
ControlCenter: Implement edit mode for customizing widgets
This commit is contained in:
@@ -37,93 +37,7 @@ Rectangle {
|
||||
spacing: SettingsData.topBarNoBackground ? 1 : 2
|
||||
|
||||
DankIcon {
|
||||
name: {
|
||||
if (!BatteryService.batteryAvailable) {
|
||||
return "power";
|
||||
}
|
||||
|
||||
if (BatteryService.isCharging) {
|
||||
if (BatteryService.batteryLevel >= 90) {
|
||||
return "battery_charging_full";
|
||||
}
|
||||
|
||||
if (BatteryService.batteryLevel >= 80) {
|
||||
return "battery_charging_90";
|
||||
}
|
||||
|
||||
if (BatteryService.batteryLevel >= 60) {
|
||||
return "battery_charging_80";
|
||||
}
|
||||
|
||||
if (BatteryService.batteryLevel >= 50) {
|
||||
return "battery_charging_60";
|
||||
}
|
||||
|
||||
if (BatteryService.batteryLevel >= 30) {
|
||||
return "battery_charging_50";
|
||||
}
|
||||
|
||||
if (BatteryService.batteryLevel >= 20) {
|
||||
return "battery_charging_30";
|
||||
}
|
||||
|
||||
return "battery_charging_20";
|
||||
}
|
||||
// Check if plugged in but not charging (like at 80% charge limit)
|
||||
if (BatteryService.isPluggedIn) {
|
||||
if (BatteryService.batteryLevel >= 90) {
|
||||
return "battery_charging_full";
|
||||
}
|
||||
|
||||
if (BatteryService.batteryLevel >= 80) {
|
||||
return "battery_charging_90";
|
||||
}
|
||||
|
||||
if (BatteryService.batteryLevel >= 60) {
|
||||
return "battery_charging_80";
|
||||
}
|
||||
|
||||
if (BatteryService.batteryLevel >= 50) {
|
||||
return "battery_charging_60";
|
||||
}
|
||||
|
||||
if (BatteryService.batteryLevel >= 30) {
|
||||
return "battery_charging_50";
|
||||
}
|
||||
|
||||
if (BatteryService.batteryLevel >= 20) {
|
||||
return "battery_charging_30";
|
||||
}
|
||||
|
||||
return "battery_charging_20";
|
||||
}
|
||||
// On battery power
|
||||
if (BatteryService.batteryLevel >= 95) {
|
||||
return "battery_full";
|
||||
}
|
||||
|
||||
if (BatteryService.batteryLevel >= 85) {
|
||||
return "battery_6_bar";
|
||||
}
|
||||
|
||||
if (BatteryService.batteryLevel >= 70) {
|
||||
return "battery_5_bar";
|
||||
}
|
||||
|
||||
if (BatteryService.batteryLevel >= 55) {
|
||||
return "battery_4_bar";
|
||||
}
|
||||
|
||||
if (BatteryService.batteryLevel >= 40) {
|
||||
return "battery_3_bar";
|
||||
}
|
||||
|
||||
if (BatteryService.batteryLevel >= 25) {
|
||||
return "battery_2_bar";
|
||||
}
|
||||
|
||||
return "battery_1_bar";
|
||||
}
|
||||
name: BatteryService.getBatteryIcon()
|
||||
size: Theme.iconSize - 6
|
||||
color: {
|
||||
if (!BatteryService.batteryAvailable) {
|
||||
|
||||
@@ -546,47 +546,82 @@ PanelWindow {
|
||||
totalWidgets = 0
|
||||
totalWidth = 0
|
||||
|
||||
let configuredWidgets = 0
|
||||
for (var i = 0; i < centerRepeater.count; i++) {
|
||||
const item = centerRepeater.itemAt(i)
|
||||
if (item?.active && item.item) {
|
||||
centerWidgets.push(item.item)
|
||||
totalWidgets++
|
||||
totalWidth += item.item.width
|
||||
if (item && topBarContent.getWidgetVisible(item.widgetId)) {
|
||||
configuredWidgets++
|
||||
if (item.active && item.item) {
|
||||
centerWidgets.push(item.item)
|
||||
totalWidgets++
|
||||
totalWidth += item.item.width
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (totalWidgets > 1) {
|
||||
totalWidth += spacing * (totalWidgets - 1)
|
||||
}
|
||||
positionWidgets()
|
||||
positionWidgets(configuredWidgets)
|
||||
}
|
||||
|
||||
function positionWidgets() {
|
||||
function positionWidgets(configuredWidgets) {
|
||||
if (totalWidgets === 0 || width <= 0) {
|
||||
return
|
||||
}
|
||||
|
||||
const parentCenterX = width / 2
|
||||
const isOdd = totalWidgets % 2 === 1
|
||||
const isOdd = configuredWidgets % 2 === 1
|
||||
|
||||
centerWidgets.forEach(widget => widget.anchors.horizontalCenter = undefined)
|
||||
|
||||
if (isOdd) {
|
||||
const middleIndex = Math.floor(totalWidgets / 2)
|
||||
const middleWidget = centerWidgets[middleIndex]
|
||||
middleWidget.x = parentCenterX - (middleWidget.width / 2)
|
||||
const middleIndex = Math.floor(configuredWidgets / 2)
|
||||
let currentActiveIndex = 0
|
||||
let middleWidget = null
|
||||
|
||||
let currentX = middleWidget.x
|
||||
for (var i = middleIndex - 1; i >= 0; i--) {
|
||||
currentX -= (spacing + centerWidgets[i].width)
|
||||
centerWidgets[i].x = currentX
|
||||
for (var i = 0; i < centerRepeater.count; i++) {
|
||||
const item = centerRepeater.itemAt(i)
|
||||
if (item && topBarContent.getWidgetVisible(item.widgetId)) {
|
||||
if (currentActiveIndex === middleIndex && item.active && item.item) {
|
||||
middleWidget = item.item
|
||||
break
|
||||
}
|
||||
currentActiveIndex++
|
||||
}
|
||||
}
|
||||
|
||||
currentX = middleWidget.x + middleWidget.width
|
||||
for (var i = middleIndex + 1; i < totalWidgets; i++) {
|
||||
currentX += spacing
|
||||
centerWidgets[i].x = currentX
|
||||
currentX += centerWidgets[i].width
|
||||
if (middleWidget) {
|
||||
middleWidget.x = parentCenterX - (middleWidget.width / 2)
|
||||
|
||||
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 currentX = middleWidget.x
|
||||
for (var i = leftWidgets.length - 1; i >= 0; i--) {
|
||||
currentX -= (spacing + leftWidgets[i].width)
|
||||
leftWidgets[i].x = currentX
|
||||
}
|
||||
|
||||
currentX = middleWidget.x + middleWidget.width
|
||||
for (var i = 0; i < rightWidgets.length; i++) {
|
||||
currentX += spacing
|
||||
rightWidgets[i].x = currentX
|
||||
currentX += rightWidgets[i].width
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const leftIndex = (totalWidgets / 2) - 1
|
||||
|
||||
Reference in New Issue
Block a user