Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panels scroll when focus moves out of view #25664

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
16 changes: 14 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,7 @@ ColumnLayout {
}

prv.isPanelActivated = true
scrollToFocusedItem(i)
}
})
}
Expand Down