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.

(cherry picked from commit d47a4eb0de)
This commit is contained in:
Joshua Goins
2026-02-12 20:03:05 -05:00
parent 76180ace07
commit 18a29bc46b
2 changed files with 26 additions and 9 deletions

View File

@@ -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

View File

@@ -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"