diff options
| author | Soramane <61896496+soramanew@users.noreply.github.com> | 2025-07-16 17:32:27 +1000 |
|---|---|---|
| committer | Soramane <61896496+soramanew@users.noreply.github.com> | 2025-07-16 17:32:27 +1000 |
| commit | 01f724800f27a7de63c33b72717456940daa4905 (patch) | |
| tree | ec973a603efb5df3ea0c177091c649e73ee91584 /modules/notifications | |
| parent | nix: add direnv support (diff) | |
| download | caelestia-shell-01f724800f27a7de63c33b72717456940daa4905.tar.gz caelestia-shell-01f724800f27a7de63c33b72717456940daa4905.tar.bz2 caelestia-shell-01f724800f27a7de63c33b72717456940daa4905.zip | |
notifs: add close button
Closes #220
Diffstat (limited to 'modules/notifications')
| -rw-r--r-- | modules/notifications/Notification.qml | 83 |
1 files changed, 48 insertions, 35 deletions
diff --git a/modules/notifications/Notification.qml b/modules/notifications/Notification.qml index 1a520c8..6022e9d 100644 --- a/modules/notifications/Notification.qml +++ b/modules/notifications/Notification.qml @@ -413,53 +413,66 @@ StyledRect { Anim {} } + Action { + modelData: QtObject { + readonly property string text: qsTr("Close") + function invoke(): void { + root.modelData.notification.dismiss(); + } + } + } + Repeater { model: root.modelData.actions - delegate: StyledRect { - id: action + delegate: Component { + Action {} + } + } + } + } - required property NotificationAction modelData + component Action: StyledRect { + id: action - radius: Appearance.rounding.full - color: root.modelData.urgency === NotificationUrgency.Critical ? Colours.palette.m3secondary : Colours.palette.m3surfaceContainerHigh + required property var modelData - Layout.preferredWidth: actionText.width + Appearance.padding.normal * 2 - Layout.preferredHeight: actionText.height + Appearance.padding.small * 2 - implicitWidth: actionText.width + Appearance.padding.normal * 2 - implicitHeight: actionText.height + Appearance.padding.small * 2 + radius: Appearance.rounding.full + color: root.modelData.urgency === NotificationUrgency.Critical ? Colours.palette.m3secondary : Colours.palette.m3surfaceContainerHigh - StateLayer { - radius: Appearance.rounding.full - color: root.modelData.urgency === NotificationUrgency.Critical ? Colours.palette.m3onSecondary : Colours.palette.m3onSurface + Layout.preferredWidth: actionText.width + Appearance.padding.normal * 2 + Layout.preferredHeight: actionText.height + Appearance.padding.small * 2 + implicitWidth: actionText.width + Appearance.padding.normal * 2 + implicitHeight: actionText.height + Appearance.padding.small * 2 - function onClicked(): void { - action.modelData.invoke(); - } - } + StateLayer { + radius: Appearance.rounding.full + color: root.modelData.urgency === NotificationUrgency.Critical ? Colours.palette.m3onSecondary : Colours.palette.m3onSurface + + function onClicked(): void { + action.modelData.invoke(); + } + } - StyledText { - id: actionText + StyledText { + id: actionText - anchors.centerIn: parent - text: actionTextMetrics.elidedText - color: root.modelData.urgency === NotificationUrgency.Critical ? Colours.palette.m3onSecondary : Colours.palette.m3onSurfaceVariant - font.pointSize: Appearance.font.size.small - } + anchors.centerIn: parent + text: actionTextMetrics.elidedText + color: root.modelData.urgency === NotificationUrgency.Critical ? Colours.palette.m3onSecondary : Colours.palette.m3onSurfaceVariant + font.pointSize: Appearance.font.size.small + } - TextMetrics { - id: actionTextMetrics + TextMetrics { + id: actionTextMetrics - text: modelData.text - font.family: actionText.font.family - font.pointSize: actionText.font.pointSize - elide: Text.ElideRight - elideWidth: { - const numActions = root.modelData.actions.length; - return (inner.width - actions.spacing * (numActions - 1)) / numActions - Appearance.padding.normal * 2; - } - } - } + text: action.modelData.text + font.family: actionText.font.family + font.pointSize: actionText.font.pointSize + elide: Text.ElideRight + elideWidth: { + const numActions = root.modelData.actions.length + 1; + return (inner.width - actions.spacing * (numActions - 1)) / numActions - Appearance.padding.normal * 2; } } } |