Skip to content

Commit

Permalink
Fix Mixer and Instrument panel scroll when focus moves out of view
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham-shinde-442 committed Dec 5, 2024
1 parent 4da2002 commit ae4b04e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ Item {
TreeView {
id: instrumentsTreeView

readonly property real delegateHeight: 38

anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
Expand Down Expand Up @@ -183,6 +185,17 @@ Item {
flickable.returnToBounds();
}

function scrollToFocusedItem(focusedIndex) {
let targetScrollPosition = focusedIndex * instrumentsTreeView.delegateHeight
let visibleAreaEnd = flickable.contentY + flickable.height

if (targetScrollPosition + instrumentsTreeView.delegateHeight > visibleAreaEnd) {
flickable.contentY = Math.min(targetScrollPosition + instrumentsTreeView.delegateHeight - flickable.height, flickable.contentHeight - flickable.height)
} else if (targetScrollPosition < flickable.contentY) {
flickable.contentY = Math.max(targetScrollPosition, 0)
}
}

property NavigationPanel navigationTreePanel : NavigationPanel {
name: "InstrumentsTree"
section: root.navigationSection
Expand Down Expand Up @@ -219,7 +232,7 @@ Item {
backgroundColor: "transparent"

rowDelegate: Item {
height: 38
height: instrumentsTreeView.delegateHeight
width: parent.width
}
}
Expand Down Expand Up @@ -255,6 +268,7 @@ Item {
navigation.onActiveChanged: {
if (navigation.active) {
prv.currentItemNavigationName = navigation.name
instrumentsTreeView.scrollToFocusedItem(model.index)
}
}

Expand Down
17 changes: 15 additions & 2 deletions src/playback/qml/MuseScore/Playback/MixerPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ ColumnLayout {
}
}

function scrollToFocusedItem(focusedIndex) {
let targetScrollPosition = (focusedIndex) * (prv.channelItemWidth + 1) // + 1 for separators
let maxContentX = flickable.contentWidth - flickable.width

if (targetScrollPosition + prv.channelItemWidth > flickable.contentX + flickable.width) {
flickable.contentX = Math.min(targetScrollPosition + prv.channelItemWidth - flickable.width, maxContentX)
} else if (targetScrollPosition < flickable.contentX) {
flickable.contentX = Math.max(targetScrollPosition - prv.channelItemWidth, 0)
}
}

MixerPanelModel {
id: mixerPanelModel

Expand All @@ -82,8 +93,8 @@ ColumnLayout {
}

function setupConnections() {
for (var i = 0; i < mixerPanelModel.rowCount(); i++) {
var item = mixerPanelModel.get(i)
for (let i = 0; i < mixerPanelModel.rowCount(); i++) {
let item = mixerPanelModel.get(i)
item.channelItem.panel.navigationEvent.connect(function(event) {
if (event.type === NavigationEvent.AboutActive) {
if (Boolean(prv.currentNavigateControlIndex)) {
Expand All @@ -92,6 +103,8 @@ ColumnLayout {
}

prv.isPanelActivated = true
let focusedIndex = item.channelItem.panel.order - 1000
scrollToFocusedItem(focusedIndex)
}
})
}
Expand Down

0 comments on commit ae4b04e

Please sign in to comment.