C
Qt Quick Ultralite swipe_game Demo
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial
import QtQuick 2.0
import StyleModule 1.0
/*
This component displays visual feedback about the content height and the
scroll position of an assigned flickable.
*/
Rectangle {
id: root
// NOTE: overwrite the Style value assignments if you want to use the component outside of this project
// the indicator is sized in relation to the height ratio of the flickable. The minimum height makes sure
// that the indicator remains visible if it would be otherwise unrecognizable small.
property int indicatorMinimumHeight: Style.buttonHeight
property color indicatorColor: Style.colorHighlight
property alias showIndicator: indicator.visible
// assign a flickable to the ScrollIndicator so it can read its properties for positioning and sizing
property Flickable flickable
implicitHeight: Style.lineSize
implicitWidth: Style.lineSize
color: Style.colorLines
QtObject {
id: internal
// relation of flickable height to flickable content height
property real flickableHeightRatio: flickable ? flickable.visibleArea.heightRatio : 1
}
Rectangle {
id: indicator
y: flickable ? Math.max(0, Math.min(root.height - height, (flickable.visibleArea.yPosition / (1.0 - internal.flickableHeightRatio)) * (root.height - height))) : 0
width: root.width
height: Math.max(root.indicatorMinimumHeight, root.height * internal.flickableHeightRatio)
color: root.indicatorColor
}
}