mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
settings: improved auto-nav to subtabs and highlight focus
This commit is contained in:
@@ -231,11 +231,12 @@ Item {
|
||||
}
|
||||
}
|
||||
|
||||
// Set sub-tab on the currently loaded tab content
|
||||
// Set sub-tab on the currently loaded tab content. Returns true if an NTabBar was found.
|
||||
function setSubTabIndex(subTabIndex) {
|
||||
if (activeTabContent) {
|
||||
setSubTabRecursive(activeTabContent, subTabIndex);
|
||||
return setSubTabRecursive(activeTabContent, subTabIndex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function setSubTabRecursive(item, subTabIndex) {
|
||||
@@ -243,6 +244,16 @@ Item {
|
||||
return false;
|
||||
|
||||
if (item.objectName === "NTabBar") {
|
||||
// Prepare the sibling NTabView so the index change doesn't animate
|
||||
if (item.parent) {
|
||||
for (let j = 0; j < item.parent.children.length; j++) {
|
||||
const sibling = item.parent.children[j];
|
||||
if (sibling.objectName === "NTabView" && sibling.setIndexWithoutAnimation) {
|
||||
sibling.setIndexWithoutAnimation(subTabIndex);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
item.currentIndex = subTabIndex;
|
||||
return true;
|
||||
}
|
||||
@@ -346,21 +357,21 @@ Item {
|
||||
if (root.activeTabContent && targetKey) {
|
||||
const widget = root.findAndHighlightWidget(root.activeTabContent, targetKey);
|
||||
if (widget && root.activeScrollView) {
|
||||
// Scroll widget into view
|
||||
const mapped = widget.mapToItem(root.activeScrollView.contentItem, 0, 0);
|
||||
const scrollBar = root.activeScrollView.ScrollBar.vertical;
|
||||
if (scrollBar) {
|
||||
const targetPos = (mapped.y - root.activeScrollView.height / 3) / root.activeScrollView.contentHeight;
|
||||
scrollBar.position = Math.max(0, Math.min(targetPos, 1.0 - scrollBar.size));
|
||||
}
|
||||
// Scroll widget into view using the Flickable directly
|
||||
const flickable = root.activeScrollView.contentItem;
|
||||
const mapped = widget.mapToItem(flickable.contentItem, 0, 0);
|
||||
const targetY = mapped.y - flickable.height / 3;
|
||||
flickable.contentY = Math.max(0, Math.min(targetY, flickable.contentHeight - flickable.height));
|
||||
|
||||
// Position highlight overlay
|
||||
const overlayPos = widget.mapToItem(tabContentArea, 0, 0);
|
||||
highlightOverlay.x = overlayPos.x - Style.marginM;
|
||||
highlightOverlay.y = overlayPos.y - Style.marginM;
|
||||
highlightOverlay.width = widget.width + Style.marginM * 2;
|
||||
highlightOverlay.height = widget.height + Style.marginM * 2;
|
||||
highlightAnimation.restart();
|
||||
// Position highlight overlay after scroll layout has settled
|
||||
Qt.callLater(function () {
|
||||
const overlayPos = widget.mapToItem(tabContentArea, 0, 0);
|
||||
highlightOverlay.x = overlayPos.x - Style.marginM;
|
||||
highlightOverlay.y = overlayPos.y - Style.marginM;
|
||||
highlightOverlay.width = widget.width + Style.marginM * 2;
|
||||
highlightOverlay.height = widget.height + Style.marginM * 2;
|
||||
highlightAnimation.restart();
|
||||
});
|
||||
}
|
||||
}
|
||||
targetKey = "";
|
||||
@@ -1226,13 +1237,13 @@ Item {
|
||||
item.screen = root.screen;
|
||||
}
|
||||
root.activeTabContent = item;
|
||||
if (root.highlightLabelKey) {
|
||||
if (root._pendingSubTab >= 0) {
|
||||
root.navigatingFromSearch = true;
|
||||
root.setSubTabIndex(root._pendingSubTab);
|
||||
root.navigatingFromSearch = false;
|
||||
if (root._pendingSubTab >= 0) {
|
||||
root.navigatingFromSearch = true;
|
||||
if (root.setSubTabIndex(root._pendingSubTab))
|
||||
root._pendingSubTab = -1;
|
||||
}
|
||||
root.navigatingFromSearch = false;
|
||||
}
|
||||
if (root.highlightLabelKey) {
|
||||
highlightScrollTimer.targetKey = root.highlightLabelKey;
|
||||
highlightScrollTimer.restart();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user