diff --git a/src/gui/Base/HBox.qml b/src/gui/Base/HBox.qml index c36711d6..888c59b4 100644 --- a/src/gui/Base/HBox.qml +++ b/src/gui/Base/HBox.qml @@ -59,7 +59,7 @@ Rectangle { HGridLayout { id: buttonGrid visible: buttonModel.length > 0 - flow: width >= buttonRepeater.childrenImplicitWidth ? + flow: width >= buttonRepeater.summedImplicitWidth ? GridLayout.LeftToRight : GridLayout.TopToBottom HRepeater { diff --git a/src/gui/Base/HRepeater.qml b/src/gui/Base/HRepeater.qml index 393dec94..49d63390 100644 --- a/src/gui/Base/HRepeater.qml +++ b/src/gui/Base/HRepeater.qml @@ -7,25 +7,34 @@ import QtQuick 2.12 Repeater { id: repeater - readonly property int childrenImplicitWidth: { - let total = 0 - for (let i = 0; i < repeater.count; i++) { - let item = repeater.itemAt(i) - if (item && item.implicitWidth) total += item.implicitWidth + readonly property var childrenImplicitWidth: { + const widths = [] + + for (let i = 0; i < repeater.count; i++) { + const item = repeater.itemAt(i) + + if (item) + widths.push(item.implicitWidth > 0 ? item.implicitWidth : 0) } - return total + return widths } - readonly property int childrenWidth: { - let total = 0 + readonly property var childrenWidth: { + const widths = [] - for (let i = 0; i < repeater.count; i++) { - let item = repeater.itemAt(i) - if (item && item.width) total += item.width + for (let i = 0; i < repeater.count; i++) { + const item = repeater.itemAt(i) + if (item) widths.push(item.width > 0 ? item.width : 0) } - return total + return widths } + + readonly property real summedWidth: utils.sum(childrenWidth) + readonly property real summedImplicitWidth:utils.sum(childrenImplicitWidth) + + readonly property real thinestChild: Math.min(...childrenWidth) + readonly property real widestChild: Math.max(...childrenWidth) } diff --git a/src/gui/Pages/Chat/RoomPane/RoomPane.qml b/src/gui/Pages/Chat/RoomPane/RoomPane.qml index 17e72549..15ebd457 100644 --- a/src/gui/Pages/Chat/RoomPane/RoomPane.qml +++ b/src/gui/Pages/Chat/RoomPane/RoomPane.qml @@ -10,7 +10,7 @@ HDrawer { saveName: "roomPane" edge: Qt.RightEdge - defaultSize: buttonRepeater.childrenImplicitWidth + defaultSize: buttonRepeater.summedImplicitWidth minimumSize: buttonRepeater.count > 0 ? buttonRepeater.itemAt(0).implicitWidth : 0 diff --git a/src/gui/Pages/Chat/Timeline/EventContent.qml b/src/gui/Pages/Chat/Timeline/EventContent.qml index c49f4ed0..14bf3425 100644 --- a/src/gui/Pages/Chat/Timeline/EventContent.qml +++ b/src/gui/Pages/Chat/Timeline/EventContent.qml @@ -143,7 +143,7 @@ HRowLayout { parent.paintedWidth + parent.leftPadding + parent.rightPadding, - linksRepeater.childrenWidth + + linksRepeater.summedWidth + (pureMedia ? 0 : parent.leftPadding + parent.rightPadding), ) height: contentColumn.height diff --git a/src/gui/Utils.qml b/src/gui/Utils.qml index 602b1742..82049829 100644 --- a/src/gui/Utils.qml +++ b/src/gui/Utils.qml @@ -57,6 +57,12 @@ QtObject { } + function sum(array) { + if (array.length < 1) return 0 + return array.reduce((a, b) => (isNaN(a) ? 0 : a) + (isNaN(b) ? 0 : b)) + } + + function isEmptyObject(obj) { return Object.entries(obj).length === 0 && obj.constructor === Object }