From adfc7a15e8ec7a32f56ca4e7eeee982173b36440 Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Sun, 23 Nov 2025 11:38:21 +0100 Subject: [PATCH] refractor text-with-fixed-width --- .../waffle/actionCenter/ToggleItem.qml | 22 +++---------- .../waffle/looks/WTextWithFixedWidth.qml | 31 +++++++++++++++++++ 2 files changed, 36 insertions(+), 17 deletions(-) create mode 100644 dots/.config/quickshell/ii/modules/waffle/looks/WTextWithFixedWidth.qml diff --git a/dots/.config/quickshell/ii/modules/waffle/actionCenter/ToggleItem.qml b/dots/.config/quickshell/ii/modules/waffle/actionCenter/ToggleItem.qml index 68ecfdcf6..dd4c1b9dd 100644 --- a/dots/.config/quickshell/ii/modules/waffle/actionCenter/ToggleItem.qml +++ b/dots/.config/quickshell/ii/modules/waffle/actionCenter/ToggleItem.qml @@ -67,24 +67,12 @@ RowLayout { id: switchRow spacing: 12 - Item { - implicitWidth: onOffTextMetrics.width - implicitHeight: onOffTextMetrics.height - TextMetrics { - id: onOffTextMetrics - text: "Off" // The larger one - font { - family: Looks.font.family.ui - pixelSize: Looks.font.pixelSize.large - weight: Looks.font.weight.regular - } - } - WText { - anchors.centerIn: parent - text: switchWidget.checked ? Translation.tr("On") : Translation.tr("Off") - font.pixelSize: Looks.font.pixelSize.large - } + WTextWithFixedWidth { + longestText: "Off" // The larger one + text: switchWidget.checked ? Translation.tr("On") : Translation.tr("Off") + font.pixelSize: Looks.font.pixelSize.large } + WSwitch { id: switchWidget Layout.alignment: Qt.AlignVCenter diff --git a/dots/.config/quickshell/ii/modules/waffle/looks/WTextWithFixedWidth.qml b/dots/.config/quickshell/ii/modules/waffle/looks/WTextWithFixedWidth.qml new file mode 100644 index 000000000..935878dc4 --- /dev/null +++ b/dots/.config/quickshell/ii/modules/waffle/looks/WTextWithFixedWidth.qml @@ -0,0 +1,31 @@ +import QtQuick + +Item { + id: root + + property string longestText + property alias text: textItem.text + property alias font: textItem.font + property alias horizontalAlignment: textItem.horizontalAlignment + property alias verticalAlignment: textItem.verticalAlignment + property alias color: textItem.color + + implicitWidth: longestTextMetrics.width + implicitHeight: longestTextMetrics.height + + TextMetrics { + id: longestTextMetrics + text: root.longestText + font { + family: Looks.font.family.ui + pixelSize: Looks.font.pixelSize.large + weight: Looks.font.weight.regular + } + } + + WText { + id: textItem + anchors.fill: parent + font.pixelSize: Looks.font.pixelSize.large + } +}