From 3bb9b08f330f2657f09e71b8ff495c788a773436 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 8 Feb 2020 11:11:45 -0800 Subject: mobile UI: correctly determine the number of columns when screen size changes This also deals with a bug we had before where we didn't re-start the calculation for the various sizes from the assumption of 'at least 21 grid units'. Now you can rotate the device and the right thing will happen. Small warning - this checks the orientation of the screen, which is exactly what you want it to do on your device. When running mobile on desktop this may not be what you expect. Even if the window has a portrait aspect ratio, your screen is likely still landscape... so testing this feature in mobile on desktop mode is a bit harder... Signed-off-by: Dirk Hohndel --- mobile-widgets/qml/main.qml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'mobile-widgets') diff --git a/mobile-widgets/qml/main.qml b/mobile-widgets/qml/main.qml index 752fc0c56..679e54131 100644 --- a/mobile-widgets/qml/main.qml +++ b/mobile-widgets/qml/main.qml @@ -571,7 +571,12 @@ if you have network connectivity and want to sync your data to cloud storage."), function setupUnits() { // some screens are too narrow for Subsurface-mobile to render well // try to hack around that by making sure that we can fit at least 21 gridUnits in a row - var numColumns = Math.floor(rootItem.width/pageStack.defaultColumnWidth) + var numColumns = Math.max(Math.floor(rootItem.width / (21 * Kirigami.Units.gridUnit)), 1) + if (Screen.primaryOrientation === Qt.PortraitOrientation && PrefDisplay.singleColumnPortrait) { + manager.appendTextToLog("show only one column in portrait mode"); + numColumns = 1; + } + rootItem.colWidth = numColumns > 1 ? Math.floor(rootItem.width / numColumns) : rootItem.width; var kirigamiGridUnit = Kirigami.Units.gridUnit var widthInGridUnits = Math.floor(rootItem.colWidth / kirigamiGridUnit) @@ -587,6 +592,7 @@ if you have network connectivity and want to sync your data to cloud storage."), // change our glabal grid unit Kirigami.Units.gridUnit = kirigamiGridUnit } + pageStack.defaultColumnWidth = rootItem.colWidth manager.appendTextToLog("Done setting up sizes") } -- cgit v1.2.3-70-g09d2