Hold power actions to confirm instead of a confirm row
Logout, reboot and shut down now fill with accent liquid while held and run once full; letting go early drains it. A tap hints to hold. Replaces the Confirm/Cancel rows in the control center tile and dashboard tab. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1e918414d1
commit
d37f9b7121
10 files changed
+350
-102
No files matched your search
@@ -0,0 +1,123 @@
|
||||
import QtQuick
|
||||
import "../theme"
|
||||
|
||||
// Hold-to-confirm overlay: accent liquid fills the parent shape while
|
||||
// `holding` is true and emits completed() once full. Let go early and it
|
||||
// drains. The glyph (or `inkSource`) turns the accent text colour where the
|
||||
// liquid covers it, so the overlay sits on top of the button's own glyph.
|
||||
Item {
|
||||
id: root
|
||||
property bool holding: false
|
||||
property int duration: 800
|
||||
property real radius: Math.min(width, height) / 2
|
||||
property color color: Theme.accent
|
||||
property color inkColor: Theme.accentText
|
||||
// The default ink is a centred glyph matching the button's own.
|
||||
property string glyph
|
||||
property string fallback
|
||||
property int glyphSize: Math.round(Math.min(width, height) * 0.5)
|
||||
property int glyphWeight: Font.Normal
|
||||
// Any transparent item the size of this one, e.g. a row of labels.
|
||||
property Item inkSource: defaultInk
|
||||
property real progress: 0
|
||||
property real time: 0
|
||||
// Stays full for a moment after completing, in case the action fails.
|
||||
property bool latched: false
|
||||
readonly property bool active: progress > 0
|
||||
signal completed
|
||||
// Let go before full.
|
||||
signal cancelled
|
||||
|
||||
onHoldingChanged: {
|
||||
if (latched)
|
||||
return;
|
||||
if (holding) {
|
||||
drain.stop();
|
||||
rise.from = progress;
|
||||
rise.duration = Math.max(1, (1 - progress) * duration);
|
||||
rise.start();
|
||||
} else if (rise.running || progress > 0) {
|
||||
rise.stop();
|
||||
if (progress < 1)
|
||||
cancelled();
|
||||
root.empty();
|
||||
}
|
||||
}
|
||||
function empty() {
|
||||
drain.from = progress;
|
||||
drain.duration = Theme.duration * 2.2 * progress;
|
||||
drain.start();
|
||||
}
|
||||
|
||||
NumberAnimation {
|
||||
id: rise
|
||||
target: root
|
||||
property: "progress"
|
||||
to: 1
|
||||
easing.type: Easing.InOutSine
|
||||
onFinished: if (root.progress >= 1) {
|
||||
root.latched = true;
|
||||
hold.restart();
|
||||
root.completed();
|
||||
}
|
||||
}
|
||||
NumberAnimation {
|
||||
id: drain
|
||||
target: root
|
||||
property: "progress"
|
||||
to: 0
|
||||
easing.type: Easing.OutCubic
|
||||
}
|
||||
Timer {
|
||||
id: hold
|
||||
interval: 900
|
||||
onTriggered: {
|
||||
root.latched = false;
|
||||
if (!root.holding)
|
||||
root.empty();
|
||||
}
|
||||
}
|
||||
FrameAnimation {
|
||||
running: root.active && Theme.intensity > 0
|
||||
onTriggered: root.time += frameTime
|
||||
}
|
||||
|
||||
Text {
|
||||
id: defaultInk
|
||||
width: root.width
|
||||
height: root.height
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: Icons.available && root.glyph ? root.glyph : root.fallback
|
||||
font.family: Icons.available && root.glyph ? Icons.family : ""
|
||||
font.pixelSize: root.glyphSize
|
||||
font.weight: root.glyphWeight
|
||||
color: "white"
|
||||
}
|
||||
ShaderEffectSource {
|
||||
id: inkTexture
|
||||
sourceItem: root.inkSource
|
||||
hideSource: root.inkSource === defaultInk
|
||||
live: true
|
||||
visible: false
|
||||
}
|
||||
ShaderEffect {
|
||||
anchors.fill: parent
|
||||
visible: root.active
|
||||
property point size: Qt.point(width, height)
|
||||
property real radius: root.radius
|
||||
property real level: root.progress
|
||||
property real time: root.time
|
||||
// Sloshes more while draining than while filling.
|
||||
property real slosh: Math.max(1.2, root.height * 0.06) * Math.min(1, Theme.intensity) * (root.holding ? 1 : 1.6)
|
||||
property vector4d fill: Qt.vector4d(root.color.r * root.color.a, root.color.g * root.color.a, root.color.b * root.color.a, root.color.a)
|
||||
property vector4d ink: Qt.vector4d(root.inkColor.r * root.inkColor.a, root.inkColor.g * root.inkColor.a, root.inkColor.b * root.inkColor.a, root.inkColor.a)
|
||||
property var glyph: inkTexture
|
||||
fragmentShader: Qt.resolvedUrl("shaders/holdfill.frag.qsb")
|
||||
Behavior on slosh {
|
||||
NumberAnimation {
|
||||
duration: Theme.duration
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
#version 440
|
||||
// Hold-to-confirm fill (HoldFill.qml): accent liquid rises inside a rounded
|
||||
// shape while a button is held, with a wavy surface, a paler back wave and a
|
||||
// lit meniscus. The glyph texture is inked in the accent text colour where the
|
||||
// liquid covers it. Output is premultiplied.
|
||||
// Rebuild holdfill.frag.qsb with scripts/build-shaders after editing.
|
||||
layout(location = 0) in vec2 qt_TexCoord0;
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
|
||||
layout(std140, binding = 0) uniform buf {
|
||||
mat4 qt_Matrix;
|
||||
float qt_Opacity;
|
||||
vec2 size; // item size, px
|
||||
float radius; // corner radius, px
|
||||
float level; // 0 empty .. 1 full
|
||||
float time; // seconds, drives the waves
|
||||
float slosh; // wave amplitude, px
|
||||
vec4 fill; // premultiplied liquid colour
|
||||
vec4 ink; // premultiplied glyph colour under the liquid
|
||||
};
|
||||
|
||||
layout(binding = 1) uniform sampler2D glyph;
|
||||
|
||||
float sdBox(vec2 p, vec2 h, float r) {
|
||||
r = min(r, min(h.x, h.y));
|
||||
vec2 q = abs(p) - h + r;
|
||||
return length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) - r;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 p = qt_TexCoord0 * size;
|
||||
float shape = clamp(0.5 - sdBox(p - size * 0.5, size * 0.5, radius), 0.0, 1.0);
|
||||
if (shape <= 0.0 || level <= 0.0) {
|
||||
fragColor = vec4(0.0);
|
||||
return;
|
||||
}
|
||||
// Waves calm down at the very bottom and top so it starts and ends flat.
|
||||
float amp = slosh * smoothstep(0.0, 0.18, level) * (1.0 - smoothstep(0.82, 1.0, level));
|
||||
float x = p.x / max(size.x, 1.0) * 6.2831853;
|
||||
float base = mix(size.y + amp * 2.0, -amp * 2.0, level);
|
||||
float front = base + amp * (sin(x * 1.3 + time * 4.2) * 0.65 + sin(x * 2.1 - time * 2.9) * 0.35);
|
||||
float back = base - amp * 0.6 + amp * sin(x * 1.1 - time * 3.4 + 1.7);
|
||||
|
||||
float aFront = clamp(p.y - front + 0.5, 0.0, 1.0);
|
||||
float aBack = clamp(p.y - back + 0.5, 0.0, 1.0) * 0.42;
|
||||
|
||||
// Deeper liquid is a touch darker; a bright band sits under the surface.
|
||||
float depth = clamp((p.y - front) / max(size.y, 1.0), 0.0, 1.0);
|
||||
vec3 col = fill.rgb * (1.0 - 0.16 * depth);
|
||||
float meniscus = exp(-max(p.y - front, 0.0) / 1.6) * aFront;
|
||||
col = mix(col, vec3(fill.a), 0.28 * meniscus);
|
||||
|
||||
vec4 c = vec4(fill.rgb, fill.a) * aBack;
|
||||
c = c * (1.0 - aFront) + vec4(col, fill.a) * aFront;
|
||||
float g = texture(glyph, qt_TexCoord0).a * aFront;
|
||||
c = c * (1.0 - g * ink.a) + ink * g;
|
||||
fragColor = c * shape * qt_Opacity;
|
||||
}
|
||||
Binary file not shown.
Reference in new issue
Block a user