forked from Shinonome/dots-hyprland
ripple button: add pressed radius
This commit is contained in:
@@ -13,6 +13,7 @@ Button {
|
|||||||
property bool toggled
|
property bool toggled
|
||||||
property string buttonText
|
property string buttonText
|
||||||
property real buttonRadius: Appearance?.rounding?.small ?? 4
|
property real buttonRadius: Appearance?.rounding?.small ?? 4
|
||||||
|
property real buttonRadiusPressed: buttonRadius
|
||||||
property int rippleDuration: 1200
|
property int rippleDuration: 1200
|
||||||
|
|
||||||
property color colBackground: ColorUtils.transparentize(Appearance.colors.colLayer1Hover, 1)
|
property color colBackground: ColorUtils.transparentize(Appearance.colors.colLayer1Hover, 1)
|
||||||
@@ -29,6 +30,19 @@ Button {
|
|||||||
colBackground)) : colBackground
|
colBackground)) : colBackground
|
||||||
property color rippleColor: root.toggled ? colRippleToggled : colRipple
|
property color rippleColor: root.toggled ? colRippleToggled : colRipple
|
||||||
|
|
||||||
|
function startRipple(x, y) {
|
||||||
|
const stateY = buttonBackground.y;
|
||||||
|
rippleAnim.x = x;
|
||||||
|
rippleAnim.y = y - stateY;
|
||||||
|
|
||||||
|
const dist = (ox,oy) => ox*ox + oy*oy
|
||||||
|
const stateEndY = stateY + buttonBackground.height
|
||||||
|
rippleAnim.radius = Math.sqrt(Math.max(dist(0, stateY), dist(0, stateEndY), dist(width, stateY), dist(width, stateEndY)))
|
||||||
|
|
||||||
|
rippleFadeAnim.complete();
|
||||||
|
rippleAnim.restart();
|
||||||
|
}
|
||||||
|
|
||||||
component RippleAnim: NumberAnimation {
|
component RippleAnim: NumberAnimation {
|
||||||
duration: rippleDuration
|
duration: rippleDuration
|
||||||
easing.type: Appearance.animation.elementMoveEnter.type
|
easing.type: Appearance.animation.elementMoveEnter.type
|
||||||
@@ -39,23 +53,17 @@ Button {
|
|||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
onPressed: (event) => {
|
onPressed: (event) => {
|
||||||
|
root.down = true
|
||||||
const {x,y} = event
|
const {x,y} = event
|
||||||
const stateY = buttonBackground.y;
|
startRipple(x, y)
|
||||||
rippleAnim.x = x;
|
|
||||||
rippleAnim.y = y - stateY;
|
|
||||||
|
|
||||||
const dist = (ox,oy) => ox*ox + oy*oy
|
|
||||||
const stateEndY = stateY + buttonBackground.height
|
|
||||||
rippleAnim.radius = Math.sqrt(Math.max(dist(0, stateY), dist(0, stateEndY), dist(width, stateY), dist(width, stateEndY)))
|
|
||||||
|
|
||||||
rippleFadeAnim.complete();
|
|
||||||
rippleAnim.restart();
|
|
||||||
}
|
}
|
||||||
onReleased: (event) => {
|
onReleased: (event) => {
|
||||||
|
root.down = false
|
||||||
root.click() // Because the MouseArea already consumed the event
|
root.click() // Because the MouseArea already consumed the event
|
||||||
rippleFadeAnim.restart();
|
rippleFadeAnim.restart();
|
||||||
}
|
}
|
||||||
onCanceled: (event) => {
|
onCanceled: (event) => {
|
||||||
|
root.down = false
|
||||||
rippleFadeAnim.restart();
|
rippleFadeAnim.restart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -101,7 +109,7 @@ Button {
|
|||||||
|
|
||||||
background: Rectangle {
|
background: Rectangle {
|
||||||
id: buttonBackground
|
id: buttonBackground
|
||||||
radius: root.buttonRadius
|
radius: root.down ? root.buttonRadiusPressed : root.buttonRadius
|
||||||
implicitHeight: 50
|
implicitHeight: 50
|
||||||
|
|
||||||
color: root.buttonColor
|
color: root.buttonColor
|
||||||
|
|||||||
Reference in New Issue
Block a user