mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2026-04-23 08:29:09 +00:00
Automatically scroll the SettingsView to ensure the focused item is visible
Also removed old manual scrolling code from SdlGamepadKeyNavigation as it was broken on Qt 6 anyway.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import QtQuick 2.9
|
||||
import QtQuick.Controls 2.2
|
||||
import QtQuick.Layouts 1.2
|
||||
import QtQuick.Window 2.2
|
||||
|
||||
import StreamingPreferences 1.0
|
||||
import ComputerManager 1.0
|
||||
@@ -25,6 +26,49 @@ Flickable {
|
||||
}
|
||||
}
|
||||
|
||||
function isChildOfFlickable(item) {
|
||||
while (item) {
|
||||
if (item.parent === contentItem) {
|
||||
return true
|
||||
}
|
||||
|
||||
item = item.parent
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
NumberAnimation on contentY {
|
||||
id: autoScrollAnimation
|
||||
duration: 100
|
||||
}
|
||||
|
||||
Window.onActiveFocusItemChanged: {
|
||||
var item = Window.activeFocusItem
|
||||
if (item) {
|
||||
// Ignore non-child elements like the toolbar buttons
|
||||
if (!isChildOfFlickable(item)) {
|
||||
return
|
||||
}
|
||||
|
||||
// Map the focus item's position into our content item's coordinate space
|
||||
var pos = item.mapToItem(contentItem, 0, 0)
|
||||
|
||||
// Ensure some extra space is visible around the element we're scrolling to
|
||||
var scrollMargin = height > 100 ? 50 : 0
|
||||
|
||||
if (pos.y - scrollMargin < contentY) {
|
||||
autoScrollAnimation.from = contentY
|
||||
autoScrollAnimation.to = Math.max(pos.y - scrollMargin, 0)
|
||||
autoScrollAnimation.start()
|
||||
}
|
||||
else if (pos.y + item.height + scrollMargin > contentY + height) {
|
||||
autoScrollAnimation.from = contentY
|
||||
autoScrollAnimation.to = Math.min(pos.y + item.height + scrollMargin - height, contentHeight - height)
|
||||
autoScrollAnimation.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
StackView.onActivated: {
|
||||
// This enables Tab and BackTab based navigation rather than arrow keys.
|
||||
// It is required to shift focus between controls on the settings page.
|
||||
|
||||
Reference in New Issue
Block a user