Big improvements on sidepane auto/manual sizing

See gui-tests.md for the expected sidepane behaviors.
This commit is contained in:
miruka
2019-07-17 13:34:02 -04:00
parent e173253f74
commit 332b6f1c0d
9 changed files with 108 additions and 36 deletions

View File

@@ -27,11 +27,9 @@ SwipeView {
interactive: sidePane.reduce
SidePane {
canAutoSize: false
autoWidthRatio: 1.0
implicitWidth: swipeView.width
collapse: false
reduce: false
currentSpacing: theme.spacing
visible: swipeView.interactive
onVisibleChanged: if (currentIndex != 1) swipeView.setCurrentIndex(1)
}

View File

@@ -12,8 +12,8 @@ Controls1.SplitView {
property bool anyPressed: false
property bool anyResizing: false
property bool canAutoSize: true
onAnyPressedChanged: canAutoSize = false
property bool manuallyResized: false
onAnyResizingChanged: manuallyResized = true
handleDelegate: Item {
readonly property bool hovered: styleData.hovered

View File

@@ -116,8 +116,8 @@ HPage {
property bool wasSnapped: false
property int referenceWidth: roomHeader.buttonsWidth
onReferenceWidthChanged: {
if (chatSplitView.canAutoSize || wasSnapped) {
if (wasSnapped) { chatSplitView.canAutoSize = true }
if (! chatSplitView.manuallyResized || wasSnapped) {
if (wasSnapped) { chatSplitView.manuallyResized = false }
width = referenceWidth
}
}
@@ -141,7 +141,8 @@ HPage {
width: referenceWidth // Initial width
Layout.minimumWidth: theme.avatar.size
Layout.maximumWidth: parent.width
Layout.maximumWidth:
parent.width - theme.minimumSupportedWidthPlusSpacing
}
}
}

View File

@@ -13,7 +13,10 @@ HRectangle {
property int buttonsWidth: viewButtons.Layout.preferredWidth
property var activeButton: "members"
property bool collapseButtons: width < 400
property bool collapseButtons:
viewButtons.implicitWidth > width * 0.33 ||
width - viewButtons.implicitWidth <
theme.minimumSupportedWidthPlusSpacing
id: roomHeader
color: theme.chat.roomHeader.background

View File

@@ -8,27 +8,34 @@ import "../Base"
HRectangle {
id: sidePane
clip: true // Avoid artifacts when collapsed
// opacity: mainUI.accountsPresent && ! reduce ? 1 : 0
// visible: opacity > 0
opacity: mainUI.accountsPresent && ! reduce ? 1 : 0
visible: opacity > 0
property bool canAutoSize: true
property int parentWidth: parent.width
property real autoWidthRatio: theme.sidePane.autoWidthRatio
property bool manuallyResizing: false
property bool manuallyResized: false
property int manualWidth: 0
// Needed for SplitView because it breaks the binding on collapse
onParentWidthChanged: if (canAutoSize) {
width = Qt.binding(() => implicitWidth)
}
property int maximumCalculatedWidth: Math.min(
manuallyResized ? manualWidth : theme.sidePane.maximumAutoWidth,
window.width - theme.minimumSupportedWidthPlusSpacing
)
property int parentWidth: parent.width
// Needed for SplitView since it breaks the binding when user manual sizes
onParentWidthChanged: width = Qt.binding(() => implicitWidth)
property int autoWidth:
Math.min(parentWidth * autoWidthRatio, theme.sidePane.maximumAutoWidth)
property int calculatedWidth: Math.min(
manuallyResized ? manualWidth: parentWidth * autoWidthRatio,
maximumCalculatedWidth
)
property bool collapse:
canAutoSize ?
autoWidth < theme.sidePane.autoCollapseBelowWidth :
width <= theme.sidePane.collapsedWidth
(manuallyResizing ? width : calculatedWidth) <
(manuallyResized ?
(theme.sidePane.collapsedWidth + theme.spacing * 2) :
theme.sidePane.autoCollapseBelowWidth)
property bool reduce:
window.width < theme.sidePane.autoReduceBelowWindowWidth
@@ -36,10 +43,11 @@ HRectangle {
property int implicitWidth:
reduce ? 0 :
collapse ? theme.sidePane.collapsedWidth :
autoWidth
calculatedWidth
property int currentSpacing:
collapse || reduce ? 0 : theme.spacing
width <= theme.sidePane.collapsedWidth + theme.spacing * 2 ?
0 : theme.spacing
Behavior on currentSpacing { HNumberAnimation {} }
Behavior on implicitWidth { HNumberAnimation {} }

View File

@@ -9,6 +9,9 @@ QtObject {
property int minimumSupportedWidth: 240
property int minimumSupportedHeight: 120
property int minimumSupportedWidthPlusSpacing: 240 + spacing * 2
property int minimumSupportedHeightPlusSpacing: 120 + spacing * 2
property int baseElementsHeight: 36
property int spacing: 8
property int animationDuration: 100
@@ -66,14 +69,14 @@ QtObject {
}
property QtObject sidePane: QtObject {
property real autoWidthRatio: 0.3
property int maximumAutoWidth: 300
property real autoWidthRatio: 0.33
property int maximumAutoWidth: 320
property int autoCollapseBelowWidth: 120
property int autoCollapseBelowWidth: 128
property int collapsedWidth: avatar.size
property int autoReduceBelowWindowWidth:
minimumSupportedWidth + collapsedWidth
minimumSupportedWidthPlusSpacing + collapsedWidth
property color background: colors.background2

View File

@@ -36,20 +36,24 @@ Item {
id: uiSplitView
anchors.fill: parent
onAnyResizingChanged: if (anyResizing) {
sidePane.manuallyResizing = true
} else {
sidePane.manuallyResizing = false
sidePane.manuallyResized = true
sidePane.manualWidth = sidePane.width
}
SidePane {
id: sidePane
canAutoSize: uiSplitView.canAutoSize
// Initial width until user manually resizes
width: implicitWidth
Layout.minimumWidth: reduce ? 0 : theme.sidePane.collapsedWidth
// -1: avoid making swipeview stuff disappear when dragged to max
Layout.maximumWidth: parent.width - 1
Layout.maximumWidth:
window.width -theme.minimumSupportedWidthPlusSpacing
Behavior on Layout.minimumWidth {
// Must run faster than SidePane implicitWidth anim
HNumberAnimation { duration: theme.animationDuration / 2 }
}
Behavior on Layout.minimumWidth { HNumberAnimation {} }
}
StackView {