Preamble
QML element sizing is generally expected to either be explicitly set, or hierarchical. This means that QML item size is generally set in one of four ways:
- Anchors: eg.
anchors.fill: parent, anchors.top: sibling.top
- as fraction of parent: eg.
width: parent.width, height: sibling.width*0.3
- as explicit virtual pixel values: eg.
x: 3, height: 20
- through explicit values set elsewhere: eg.
anchors.margins: theme.itemSpacingNarrow, height: iconSizeSmall
Dims doesn't align with any of the above.
The issue
Many asteroid apps use Dims as a means to ignore the QML hierarchy and directly get fractions of the size of the current window or the display. The window and display size are currently interchangeable because asteroid apps are always fullscreen, which allows this behaviour. Dims breaks in this usecase as soon as the window is resized, as on desktop platforms.
Solutions
The fantasy solution would be to have Dims give fractions of the current window, rather than the entire display size. This would easily fix all the current code.
Unfortunately, QML doesn't want to work this way. The Dims singleton would have to somehow be mapped to the root window of the application, and any implementation of this would also affect how Dims is used in code.
The distinction between h and w is also not clear. Generally apps are designed correctly, but it is possible to have applications behave in very strange ways in unconventional display geometries when h or w are incorrectly picked instead of l
The actual solution involves stopping the use of Dims to ignore the QML hierarchy. In most places, this will just mean replacing, for example, Dims.h(10) with windowID.height*0.1 (windowID being the id: which was assigned to the Application at the root of the app).
Flat tyres
Another current justification for Dims is that they provide a way to deal with flat tyres. I don't believe this should be used anywhere other than asteroid-launcher - and even there, it could be trivially replaced with Screen.desktopAvailableHeight+DeviceInfo.flatTireHeight.
I propose that a fractional value greater than one such as flatTireHeightFractional should be exposed through deviceInfo - this should make it far easier to deal with the flat tyre, without having to go through Dims or deal with the absolute display dimensions. This would be calculated as (Screen.desktopAvailableHeight+DeviceInfo.flatTireHeight)/Screen.desktopAvailableHeight, and would return a value such as 1.066667 on ayu. Dims.h(100) would be replaced with windowID.height*DeviceInfo.flatTireHeightFractional. This should eliminate the flat tyre usecase for Dims as well.
Perhaps some implementation details may differ for this, but the point is that Dims should not be used here either.
Does Dims still have uses?
The spirit of Dims does still have some value, as it provides an easy and consistent source of font and other element sizes. Asteroid is not currently DPI-aware, which makes the UI look very consistent across watches, but makes it weirdly massive on devices such as minnow and difficult to read on smaller devices such as sawfish. It may be desirable to add some interface for getting DPI-aware element sizes.
In its current form, Dims probably should not have a future. On desktop, it will always continue to break things; the lack of DPI awareness and assumption of fullscreen will always cause elements to be inappropriately oversized.
Dims will likely continue to be used internally in qml-asteroid to set the default element sizes. Provided that Dims is made DPI-aware, this should be fine on desktop as well.
Preamble
QML element sizing is generally expected to either be explicitly set, or hierarchical. This means that QML item size is generally set in one of four ways:
anchors.fill: parent,anchors.top: sibling.topwidth: parent.width,height: sibling.width*0.3x: 3,height: 20anchors.margins: theme.itemSpacingNarrow,height: iconSizeSmallDimsdoesn't align with any of the above.The issue
Many asteroid apps use
Dimsas a means to ignore the QML hierarchy and directly get fractions of the size of the current window or the display. The window and display size are currently interchangeable because asteroid apps are always fullscreen, which allows this behaviour.Dimsbreaks in this usecase as soon as the window is resized, as on desktop platforms.Solutions
The fantasy solution would be to have
Dimsgive fractions of the current window, rather than the entire display size. This would easily fix all the current code.Unfortunately, QML doesn't want to work this way. The
Dimssingleton would have to somehow be mapped to the root window of the application, and any implementation of this would also affect howDimsis used in code.The distinction between
handwis also not clear. Generally apps are designed correctly, but it is possible to have applications behave in very strange ways in unconventional display geometries whenhorware incorrectly picked instead oflThe actual solution involves stopping the use of
Dimsto ignore the QML hierarchy. In most places, this will just mean replacing, for example,Dims.h(10)withwindowID.height*0.1(windowIDbeing theid:which was assigned to theApplicationat the root of the app).Flat tyres
Another current justification for
Dimsis that they provide a way to deal with flat tyres. I don't believe this should be used anywhere other thanasteroid-launcher- and even there, it could be trivially replaced withScreen.desktopAvailableHeight+DeviceInfo.flatTireHeight.I propose that a fractional value greater than one such as
flatTireHeightFractionalshould be exposed throughdeviceInfo- this should make it far easier to deal with the flat tyre, without having to go throughDimsor deal with the absolute display dimensions. This would be calculated as(Screen.desktopAvailableHeight+DeviceInfo.flatTireHeight)/Screen.desktopAvailableHeight, and would return a value such as1.066667on ayu.Dims.h(100)would be replaced withwindowID.height*DeviceInfo.flatTireHeightFractional. This should eliminate the flat tyre usecase forDimsas well.Perhaps some implementation details may differ for this, but the point is that
Dimsshould not be used here either.Does
Dimsstill have uses?The spirit of Dims does still have some value, as it provides an easy and consistent source of font and other element sizes. Asteroid is not currently DPI-aware, which makes the UI look very consistent across watches, but makes it weirdly massive on devices such as
minnowand difficult to read on smaller devices such assawfish. It may be desirable to add some interface for getting DPI-aware element sizes.In its current form,
Dimsprobably should not have a future. On desktop, it will always continue to break things; the lack of DPI awareness and assumption of fullscreen will always cause elements to be inappropriately oversized.Dims will likely continue to be used internally in qml-asteroid to set the default element sizes. Provided that Dims is made DPI-aware, this should be fine on desktop as well.