Skip to content

Dims statement considered harmful / asteroid apps break when windows resized #44

@dodoradio

Description

@dodoradio

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions