forked from Shinonome/dots-hyprland
refractor text-with-fixed-width
This commit is contained in:
@@ -67,24 +67,12 @@ RowLayout {
|
|||||||
id: switchRow
|
id: switchRow
|
||||||
spacing: 12
|
spacing: 12
|
||||||
|
|
||||||
Item {
|
WTextWithFixedWidth {
|
||||||
implicitWidth: onOffTextMetrics.width
|
longestText: "Off" // The larger one
|
||||||
implicitHeight: onOffTextMetrics.height
|
text: switchWidget.checked ? Translation.tr("On") : Translation.tr("Off")
|
||||||
TextMetrics {
|
font.pixelSize: Looks.font.pixelSize.large
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WSwitch {
|
WSwitch {
|
||||||
id: switchWidget
|
id: switchWidget
|
||||||
Layout.alignment: Qt.AlignVCenter
|
Layout.alignment: Qt.AlignVCenter
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user