mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
NScrollView: properly disable horizontal scrrol when setting proper horizontalPolicy
This commit is contained in:
@@ -14,10 +14,44 @@ T.ScrollView {
|
||||
property real handleRadius: Style.radiusM * scaling
|
||||
property int verticalPolicy: ScrollBar.AsNeeded
|
||||
property int horizontalPolicy: ScrollBar.AsNeeded
|
||||
property bool preventHorizontalScroll: horizontalPolicy === ScrollBar.AlwaysOff
|
||||
property int boundsBehavior: Flickable.StopAtBounds
|
||||
property int flickableDirection: Flickable.VerticalFlick
|
||||
|
||||
implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, contentWidth + leftPadding + rightPadding)
|
||||
implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, contentHeight + topPadding + bottomPadding)
|
||||
|
||||
// Configure the internal flickable when it becomes available
|
||||
Component.onCompleted: {
|
||||
configureFlickable()
|
||||
}
|
||||
|
||||
// Function to configure the underlying Flickable
|
||||
function configureFlickable() {
|
||||
// Find the internal Flickable (it's usually the first child)
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
var child = children[i]
|
||||
if (child.toString().indexOf("Flickable") !== -1) {
|
||||
// Configure the flickable to prevent horizontal scrolling
|
||||
child.boundsBehavior = root.boundsBehavior
|
||||
|
||||
if (root.preventHorizontalScroll) {
|
||||
child.flickableDirection = Flickable.VerticalFlick
|
||||
child.contentWidth = Qt.binding(() => child.width)
|
||||
} else {
|
||||
child.flickableDirection = root.flickableDirection
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Watch for changes in horizontalPolicy
|
||||
onHorizontalPolicyChanged: {
|
||||
preventHorizontalScroll = (horizontalPolicy === ScrollBar.AlwaysOff)
|
||||
configureFlickable()
|
||||
}
|
||||
|
||||
ScrollBar.vertical: ScrollBar {
|
||||
parent: root
|
||||
x: root.mirrored ? 0 : root.width - width
|
||||
|
||||
Reference in New Issue
Block a user