mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 11:48:09 +02:00
Add scrollbar
This commit is contained in:
parent
b539c55c02
commit
9291d272fe
1 changed files with 92 additions and 5 deletions
|
@ -42,8 +42,13 @@ Item {
|
||||||
|
|
||||||
ListView {
|
ListView {
|
||||||
id: listView
|
id: listView
|
||||||
anchors.fill: parent
|
anchors {
|
||||||
anchors.margins: 4
|
top: parent.top
|
||||||
|
left: parent.left
|
||||||
|
right: scrollBar.left
|
||||||
|
bottom: parent.bottom
|
||||||
|
margins: 4
|
||||||
|
}
|
||||||
clip: true
|
clip: true
|
||||||
snapMode: ListView.SnapToItem
|
snapMode: ListView.SnapToItem
|
||||||
|
|
||||||
|
@ -81,15 +86,97 @@ Item {
|
||||||
|
|
||||||
onCountChanged: MyAvatar.setAttachmentsVariant(attachments);
|
onCountChanged: MyAvatar.setAttachmentsVariant(attachments);
|
||||||
|
|
||||||
/* */
|
/*
|
||||||
// DEBUG
|
// DEBUG
|
||||||
highlight: Rectangle { color: "#40ffff00" }
|
highlight: Rectangle { color: "#40ffff00" }
|
||||||
highlightFollowsCurrentItem: true
|
highlightFollowsCurrentItem: true
|
||||||
/* */
|
*/
|
||||||
|
|
||||||
onHeightChanged: {
|
onHeightChanged: {
|
||||||
// Keyboard has been raised / lowered.
|
// Keyboard has been raised / lowered.
|
||||||
positionViewAtIndex(currentIndex, ListView.SnapPosition);
|
positionViewAtIndex(listView.currentIndex, ListView.SnapPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
onCurrentIndexChanged: {
|
||||||
|
scrollSlider.y = currentIndex * (scrollBar.height - scrollSlider.height) / (listView.count - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
onContentYChanged: {
|
||||||
|
// User may have dragged content up/down.
|
||||||
|
yScrollTimer.restart();
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
id: yScrollTimer
|
||||||
|
interval: 50
|
||||||
|
repeat: false
|
||||||
|
running: false
|
||||||
|
onTriggered: {
|
||||||
|
var index = listView.contentY / (scrollBar.height - scrollSlider.height);
|
||||||
|
index = Math.round(index);
|
||||||
|
listView.currentIndex = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
id: scrollBar
|
||||||
|
|
||||||
|
property bool scrolling: listView.contentHeight > listView.height
|
||||||
|
|
||||||
|
anchors {
|
||||||
|
top: parent.top
|
||||||
|
right: parent.right
|
||||||
|
bottom: parent.bottom
|
||||||
|
topMargin: 4
|
||||||
|
bottomMargin: 4
|
||||||
|
}
|
||||||
|
width: scrolling ? 18 : 0
|
||||||
|
radius: attachmentsBackground.radius
|
||||||
|
color: hifi.colors.baseGrayShadow
|
||||||
|
|
||||||
|
MouseArea {
|
||||||
|
anchors.fill: parent
|
||||||
|
|
||||||
|
onClicked: {
|
||||||
|
var index = listView.currentIndex;
|
||||||
|
index = index + (mouse.y <= scrollSlider.y ? -1 : 1);
|
||||||
|
if (index < 0) {
|
||||||
|
index = 0;
|
||||||
|
}
|
||||||
|
if (index > listView.count - 1) {
|
||||||
|
index = listView.count - 1;
|
||||||
|
}
|
||||||
|
listView.currentIndex = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
id: scrollSlider
|
||||||
|
anchors {
|
||||||
|
right: parent.right
|
||||||
|
rightMargin: 3
|
||||||
|
}
|
||||||
|
width: 16
|
||||||
|
height: (listView.height / listView.contentHeight) * listView.height
|
||||||
|
radius: width / 2
|
||||||
|
color: hifi.colors.lightGray
|
||||||
|
|
||||||
|
visible: scrollBar.scrolling;
|
||||||
|
|
||||||
|
onYChanged: {
|
||||||
|
var index = y * (listView.count - 1) / (scrollBar.height - scrollSlider.height);
|
||||||
|
index = Math.round(index);
|
||||||
|
listView.currentIndex = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
MouseArea {
|
||||||
|
anchors.fill: parent
|
||||||
|
drag.target: scrollSlider
|
||||||
|
drag.axis: Drag.YAxis
|
||||||
|
drag.minimumY: 0
|
||||||
|
drag.maximumY: scrollBar.height - scrollSlider.height
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue