From 2a714378c9f379361561e766f3f36032d87fa783 Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Sun, 8 Mar 2026 18:15:00 +0100 Subject: [PATCH] refactor fixed width text --- .../widgets/FixedWidthTextContainer.qml | 16 ++++++++++++++ .../waffle/looks/WTextWithFixedWidth.qml | 22 ++++++------------- 2 files changed, 23 insertions(+), 15 deletions(-) create mode 100644 dots/.config/quickshell/ii/modules/common/widgets/FixedWidthTextContainer.qml diff --git a/dots/.config/quickshell/ii/modules/common/widgets/FixedWidthTextContainer.qml b/dots/.config/quickshell/ii/modules/common/widgets/FixedWidthTextContainer.qml new file mode 100644 index 000000000..4033bc092 --- /dev/null +++ b/dots/.config/quickshell/ii/modules/common/widgets/FixedWidthTextContainer.qml @@ -0,0 +1,16 @@ +import QtQuick + +Item { + id: root + + property alias longestText: longestTextMetrics.text + property alias font: longestTextMetrics.font + + implicitWidth: longestTextMetrics.width + implicitHeight: longestTextMetrics.height + + TextMetrics { + id: longestTextMetrics + text: root.longestText + } +} diff --git a/dots/.config/quickshell/ii/modules/waffle/looks/WTextWithFixedWidth.qml b/dots/.config/quickshell/ii/modules/waffle/looks/WTextWithFixedWidth.qml index 935878dc4..e0727eb0e 100644 --- a/dots/.config/quickshell/ii/modules/waffle/looks/WTextWithFixedWidth.qml +++ b/dots/.config/quickshell/ii/modules/waffle/looks/WTextWithFixedWidth.qml @@ -1,31 +1,23 @@ import QtQuick +import qs.modules.common.widgets as W -Item { +W.FixedWidthTextContainer { 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 - } + 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 + font: root.font } }