From d47a4eb0de285ccb49aa06babe303ef4c13c59f3 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Thu, 12 Feb 2026 20:03:05 -0500 Subject: [PATCH] Fix weird scrolling behavior in room list You may have noticed that the room list acts a bit... odd. You usually can't scroll all the way down with a scrollwheel, it just stops. It's possible to continue a little bit more with the scrollbar. And sometimes the scrollbar doesn't know how big it's actually supposed to be, commonly occuring when switching from a large room list to a smaller one. I narrowed it down the same usual problem with views in QtQuick: variable sized delegates! Using GammaRay I figured out that for the delegates currently in use they're slightly different: 46 pixels for regular room delegates, 42 pixels for section headers and the "Find your Friends" button was also different. *Technically* TableView (and by extension TreeView) is supposed to allow variable-sized delegates, and we should be able to advertise that with rowHeightProvider. I tried a bunch of different solutions and none of them worked reliably, so I took the usual sledgehammer approach of making all of the delegates the same size. This fixes all of the obvious bugs with the room list I could see, with the one visual downside of making the section headers slightly taller. But since I spent some time improving the tap targets, this is only a visual change and not a functional one. I also made sure to test it in compact mode, and everything shrinks as expected. --- src/rooms/RoomListPage.qml | 16 ++++++++++++++-- src/rooms/RoomTreeSection.qml | 19 ++++++++++++------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/rooms/RoomListPage.qml b/src/rooms/RoomListPage.qml index 190ee996e..ff12b82f7 100644 --- a/src/rooms/RoomListPage.qml +++ b/src/rooms/RoomListPage.qml @@ -139,6 +139,7 @@ Kirigami.Page { contentItem: TreeView { id: treeView topMargin: Math.round(Kirigami.Units.smallSpacing / 2) + bottomMargin: Math.round(Kirigami.Units.smallSpacing / 2) clip: true reuseItems: false @@ -147,6 +148,17 @@ Kirigami.Page { selectionModel: ItemSelectionModel {} + // This is somewhat of a hack. + // If we don't calculate this for TableView, then the content area doesn't quite scroll down far enough to cover the margins. + rowHeightProvider: row => { + // NOTE: This padding value should be kept in sync with the padding value of our delegates. + const padding = Kirigami.Units.mediumSpacing; + // NOTE: This calculation should be kept in sync with the height value of our delegates. + return Kirigami.Units.gridUnit + (NeoChatConfig.compactRoomList ? 0 : Kirigami.Units.largeSpacing * 2) + padding * 2; + } + + // NOTE: For any future delegate spelunkers, please *keep the delegate heights in sync*. + // If you fail to do so, weird scrolling behavior begins to manifest. delegate: DelegateChooser { role: "delegateType" @@ -181,8 +193,8 @@ Kirigami.Page { delegate: Delegates.RoundedItemDelegate { text: i18nc("@action:button", "Find your friends") icon.name: "list-add-user" - icon.width: Kirigami.Units.gridUnit * 2 - icon.height: Kirigami.Units.gridUnit * 2 + icon.width: Kirigami.Units.gridUnit + (NeoChatConfig.compactRoomList ? 0 : Kirigami.Units.largeSpacing * 2) + icon.height: Kirigami.Units.gridUnit + (NeoChatConfig.compactRoomList ? 0 : Kirigami.Units.largeSpacing * 2) onClicked: (Kirigami.PageStack.pageStack as Kirigami.PageRow).pushDialogLayer(Qt.createComponent('org.kde.neochat', 'UserSearchPage'), { connection: root.connection diff --git a/src/rooms/RoomTreeSection.qml b/src/rooms/RoomTreeSection.qml index 10b479da7..a3e08a4ac 100644 --- a/src/rooms/RoomTreeSection.qml +++ b/src/rooms/RoomTreeSection.qml @@ -6,8 +6,11 @@ import QtQuick.Controls as QQC2 import QtQuick.Layouts import org.kde.kirigami as Kirigami +import org.kde.kirigamiaddons.delegates as Delegates -QQC2.ItemDelegate { +import org.kde.neochat + +Delegates.RoundedItemDelegate { id: root required property TreeView treeView @@ -36,29 +39,31 @@ QQC2.ItemDelegate { Keys.onSpacePressed: root.treeView.toggleExpanded(row) contentItem: Item { - implicitWidth: layout.implicitWidth - implicitHeight: layout.implicitHeight + implicitHeight: Math.max(layout.implicitHeight, Kirigami.Units.gridUnit + (NeoChatConfig.compactRoomList ? 0 : Kirigami.Units.largeSpacing * 2)) RowLayout { id: layout - width: root.contentItem.width + anchors.fill: parent spacing: 0 Kirigami.ListSectionHeader { - Layout.fillWidth: true visible: !root.collapsed horizontalPadding: 0 topPadding: 0 bottomPadding: 0 text: root.collapsed ? "" : root.displayName - onClicked: root.treeView.toggleExpanded(row) + onClicked: root.treeView.toggleExpanded(root.row) + + Layout.fillWidth: true + Layout.alignment: Qt.AlignVCenter } QQC2.ToolButton { id: collapseButton - Layout.alignment: Qt.AlignHCenter + + Layout.alignment: Qt.AlignCenter icon { name: root.expanded ? "go-up" : "go-down"