ActiveWindow: Converted to Layout

This commit is contained in:
LemmyCook 2025-09-05 19:06:15 -04:00
parent 0a48e5f34f
commit 1efa1f4aa3

View file

@ -7,7 +7,7 @@ import qs.Commons
import qs.Services import qs.Services
import qs.Widgets import qs.Widgets
Row { RowLayout {
id: root id: root
property ShellScreen screen property ShellScreen screen
@ -15,7 +15,7 @@ Row {
readonly property real minWidth: 160 readonly property real minWidth: 160
readonly property real maxWidth: 400 readonly property real maxWidth: 400
anchors.verticalCenter: parent.verticalCenter Layout.alignment: Qt.AlignVCenter
spacing: Style.marginS * scaling spacing: Style.marginS * scaling
visible: getTitle() !== "" visible: getTitle() !== ""
@ -33,7 +33,7 @@ Row {
return Icons.iconForAppId(focusedWindow.appId) return Icons.iconForAppId(focusedWindow.appId)
} }
// A hidden text element to safely measure the full title width // A hidden text element to safely measure the full title width
NText { NText {
id: fullTitleMetrics id: fullTitleMetrics
visible: false visible: false
@ -43,15 +43,13 @@ Row {
} }
Rectangle { Rectangle {
// Let the Rectangle size itself based on its content (the Row) id: windowTitleRect
visible: root.visible visible: root.visible
width: row.width + Style.marginM * 2 * scaling Layout.preferredWidth: contentLayout.implicitWidth + Style.marginM * 2 * scaling
height: Math.round(Style.capsuleHeight * scaling) Layout.preferredHeight: Math.round(Style.capsuleHeight * scaling)
radius: Math.round(Style.radiusM * scaling) radius: Math.round(Style.radiusM * scaling)
color: Color.mSurfaceVariant color: Color.mSurfaceVariant
anchors.verticalCenter: parent.verticalCenter
Item { Item {
id: mainContainer id: mainContainer
anchors.fill: parent anchors.fill: parent
@ -59,16 +57,16 @@ Row {
anchors.rightMargin: Style.marginS * scaling anchors.rightMargin: Style.marginS * scaling
clip: true clip: true
Row { RowLayout {
id: row id: contentLayout
anchors.verticalCenter: parent.verticalCenter anchors.centerIn: parent
spacing: Style.marginS * scaling spacing: Style.marginS * scaling
// Window icon // Window icon
Item { Item {
width: Style.fontSizeL * scaling * 1.2 Layout.preferredWidth: Style.fontSizeL * scaling * 1.2
height: Style.fontSizeL * scaling * 1.2 Layout.preferredHeight: Style.fontSizeL * scaling * 1.2
anchors.verticalCenter: parent.verticalCenter Layout.alignment: Qt.AlignVCenter
visible: getTitle() !== "" && Settings.data.bar.showActiveWindowIcon visible: getTitle() !== "" && Settings.data.bar.showActiveWindowIcon
IconImage { IconImage {
@ -85,24 +83,25 @@ Row {
id: titleText id: titleText
// For short titles, show full. For long titles, truncate and expand on hover // For short titles, show full. For long titles, truncate and expand on hover
width: { Layout.preferredWidth: {
if (mouseArea.containsMouse) { if (mouseArea.containsMouse) {
return Math.round(Math.min(fullTitleMetrics.contentWidth, root.maxWidth * scaling)) return Math.round(Math.min(fullTitleMetrics.contentWidth, root.maxWidth * scaling))
} else { } else {
return Math.round(Math.min(fullTitleMetrics.contentWidth, root.minWidth * scaling)) return Math.round(Math.min(fullTitleMetrics.contentWidth, root.minWidth * scaling))
} }
} }
Layout.alignment: Qt.AlignVCenter
horizontalAlignment: Text.AlignLeft horizontalAlignment: Text.AlignLeft
text: getTitle() text: getTitle()
font.pointSize: Style.fontSizeS * scaling font.pointSize: Style.fontSizeS * scaling
font.weight: Style.fontWeightMedium font.weight: Style.fontWeightMedium
elide: mouseArea.containsMouse ? Text.ElideNone : Text.ElideRight elide: mouseArea.containsMouse ? Text.ElideNone : Text.ElideRight
anchors.verticalCenter: parent.verticalCenter
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
color: Color.mSecondary color: Color.mSecondary
clip: true clip: true
Behavior on width { Behavior on Layout.preferredWidth {
NumberAnimation { NumberAnimation {
duration: Style.animationSlow duration: Style.animationSlow
easing.type: Easing.InOutCubic easing.type: Easing.InOutCubic