Skip to content

Commit 20edc75

Browse files
committed
qml: add NavButton interaction color animations
1 parent d0a5296 commit 20edc75

File tree

1 file changed

+44
-4
lines changed

1 file changed

+44
-4
lines changed

src/qml/controls/NavButton.qml

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,32 @@ AbstractButton {
1414
property url iconSource: ""
1515

1616
padding: 0
17-
background: null
17+
background: Rectangle {
18+
id: bg
19+
height: root.height
20+
width: root.width
21+
radius: 5
22+
state:"DEFAULT"
23+
24+
states: [
25+
State {
26+
name: "DEFAULT"
27+
PropertyChanges { target: bg; color: Theme.color.background }
28+
},
29+
State {
30+
name: "HOVER"
31+
PropertyChanges { target: bg; color: Theme.color.neutral2 }
32+
},
33+
State {
34+
name: "PRESSED"
35+
PropertyChanges { target: bg; color: Theme.color.neutral3 }
36+
}
37+
]
38+
39+
Behavior on color {
40+
ColorAnimation { duration: 150 }
41+
}
42+
}
1843
contentItem: RowLayout {
1944
anchors.fill: parent
2045
spacing: 0
@@ -33,7 +58,6 @@ AbstractButton {
3358
icon.height: root.iconHeight
3459
icon.width: root.iconWidth
3560
background: null
36-
onClicked: root.clicked()
3761
}
3862
}
3963
Loader {
@@ -52,8 +76,24 @@ AbstractButton {
5276
color: Theme.color.neutral9
5377
text: root.text
5478
}
55-
onClicked: root.clicked()
5679
}
57-
}
80+
}
81+
}
82+
MouseArea {
83+
anchors.fill: parent
84+
hoverEnabled: true
85+
onEntered: {
86+
root.background.state = "HOVER"
87+
}
88+
onExited: {
89+
root.background.state = "DEFAULT"
90+
}
91+
onPressed: {
92+
root.background.state = "PRESSED"
93+
}
94+
onReleased: {
95+
root.background.state = "DEFAULT"
96+
root.clicked()
97+
}
5898
}
5999
}

0 commit comments

Comments
 (0)