From e9efca76d4020679fbb9fbe62f6ff94bb0aac16e Mon Sep 17 00:00:00 2001 From: miruka Date: Sat, 21 Dec 2019 13:05:12 -0400 Subject: [PATCH] HDrawer: snap around default size when resize-drag --- TODO.md | 1 - src/gui/Base/HDrawer.qml | 14 ++++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/TODO.md b/TODO.md index 66929b5f..1913569d 100644 --- a/TODO.md +++ b/TODO.md @@ -86,7 +86,6 @@ - Drop the `buttonModel`/`buttonCallbacks` HBox approach - Scrollable popups and room settings - Improve when HDrawer should collapse when the ui is zoomed -- HDrawer snapping - Make theme error/etc text colors more like name colors - In account settings, display name field text should be colored - Way to open context menus without a right mouse button diff --git a/src/gui/Base/HDrawer.qml b/src/gui/Base/HDrawer.qml index f1105036..6911cc04 100644 --- a/src/gui/Base/HDrawer.qml +++ b/src/gui/Base/HDrawer.qml @@ -46,6 +46,9 @@ Drawer { property int maximumSize: horizontal ? referenceSizeParent.width : referenceSizeParent.height + property int snapAt: defaultSize + property int snapZone: theme.spacing * 2 + // property Item referenceSizeParent: parent @@ -105,19 +108,26 @@ Drawer { onMouseXChanged: if (horizontal && pressed) { - drawer.preferredSize = + drawer.preferredSize = snapSize( drawer.calculatedSize + (drawer.edge === Qt.RightEdge ? -mouseX : mouseX) + ) } onMouseYChanged: if (vertical && pressed) { - drawer.preferredSize = + drawer.preferredSize = snapSize( drawer.calculatedSize + (drawer.edge === Qt.BottomEdge ? -mouseY : mouseY) + ) } onReleased: window.saveState(drawer) + + function snapSize(num) { + return num < snapAt + snapZone && num > snapAt - snapZone ? + snapAt : num + } } } }