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 + } } } }