From f778335600383776c8f9c8810880ecc52a5fa03d Mon Sep 17 00:00:00 2001 From: zach Date: Tue, 18 Aug 2026 22:31:12 +0200 Subject: [PATCH] fix switch style --- Components/CustomSwitch.qml | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/Components/CustomSwitch.qml b/Components/CustomSwitch.qml index 6e7c68a..bb25a54 100644 --- a/Components/CustomSwitch.qml +++ b/Components/CustomSwitch.qml @@ -13,8 +13,12 @@ Switch { implicitWidth: implicitIndicatorWidth indicator: CustomRect { - color: root.checked && root.enabled ? Colors.palette.m3primary : Colors.layer(Colors.palette.m3surfaceContainerHighest, root.cLayer) - implicitHeight: Tokens.font.size.larger + Tokens.padding.small * 2 + color: { + if (!root.enabled) + return root.checked ? Qt.alpha(Colors.palette.m3onSurface, 0.12) : Qt.alpha(Colors.palette.m3surfaceContainerHighest, 0.38); + return root.checked ? Colors.palette.m3primary : Colors.layer(Colors.palette.m3surfaceContainerHighest, root.cLayer); + } + implicitHeight: 14 + Tokens.padding.small * 2 implicitWidth: implicitHeight * 1.7 radius: Tokens.rounding.full @@ -22,7 +26,11 @@ Switch { readonly property real nonAnimWidth: root.pressed ? implicitHeight * 1.2 : implicitHeight anchors.verticalCenter: parent.verticalCenter - color: root.checked && root.enabled ? Colors.palette.m3onPrimary : Colors.layer(Colors.palette.m3outline, root.cLayer + 1) + color: { + if (!root.enabled) + return root.checked ? Qt.alpha(Colors.palette.m3surface, 0.7) : Qt.alpha(Colors.palette.m3onSurface, 0.12); + return root.checked ? Colors.palette.m3onPrimary : Colors.layer(Colors.palette.m3outline, root.cLayer + 1); + } implicitHeight: parent.implicitHeight - Tokens.padding.extraSmall implicitWidth: nonAnimWidth radius: Tokens.rounding.full @@ -92,7 +100,7 @@ Switch { anchors.centerIn: parent asynchronous: true - height: parent.implicitHeight - Tokens.padding.small + height: parent.implicitHeight - Tokens.padding.medium preferredRendererType: Shape.CurveRenderer width: height @@ -114,12 +122,16 @@ Switch { } ShapePath { - capStyle: ShapePath.RoundCap + capStyle: Tokens.rounding.scale === 0 ? ShapePath.SquareCap : ShapePath.RoundCap fillColor: "transparent" startX: icon.start1.x startY: icon.start1.y - strokeColor: root.checked && root.enabled ? Colors.palette.m3primary : Colors.palette.m3surfaceContainerHighest - strokeWidth: Tokens.font.size.larger * 0.15 + strokeColor: { + if (!root.enabled) + return root.checked ? Colors.palette.m3outline : Colors.palette.m3surfaceContainer; + return root.checked ? Colors.palette.m3primary : Colors.palette.m3surfaceContainerHighest; + } + strokeWidth: 16 * 0.15 Behavior on strokeColor { CAnim {