-
Notifications
You must be signed in to change notification settings - Fork 567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the resolution independence book chapter. #913
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Resolution independence | ||
|
||
## What is a pixel anyway? | ||
|
||
Pixel is short for *picture element* and although due to its popularity | ||
it has many meanings depending on context, when talking about pixels in the context of druid | ||
a pixel means always only one thing. It is **the smallest configurable area of color | ||
that the underlying platform allows `druid-shell` to manipulate**. | ||
|
||
The actual physical display might have a different resolution from what the platform knows or uses. | ||
Even if the display pixel resolution matches the platform resolution, | ||
the display itself can control even smaller elements than pixels - the sub-pixels. | ||
|
||
The shape of the physical pixel could be complex and definitely varies from display model to model. | ||
However for simplicity you can think of a pixel as a square which you can choose a color for. | ||
|
||
## Display pixel density | ||
|
||
As technology advances the physical size of pixels is getting smaller and smaller. | ||
This allows display manufacturers to put more and more pixels into the same sized screen. | ||
The **pixel densities of displays are increasing**. | ||
|
||
There is also an **increasing variety in the pixel density** of the displays used by people. | ||
Some might have a brand new *30" 8K UHD* (*7680px \* 4320px*) display, | ||
while others might still be rocking their *30" HD ready* (*1366px \* 768px*) display. | ||
It might even be the same person on the same computer with a multi-display setup. | ||
|
||
## The naive old school approach to UI | ||
|
||
For a very long time UIs have been designed without thinking about pixel density at all. | ||
People tended to have displays with roughly similar pixel densities, so it all kind of | ||
worked most of the time. However **it breaks down horribly** in a modern world. | ||
The *200px \* 200px* UI that looks decent on that *HD ready* display is barely visible | ||
on the *8K UHD* display. If you redesign it according to the *8K UHD* display then | ||
it won't even fit on the *HD ready* screen. | ||
|
||
## Platform specific band-aids | ||
|
||
Some platforms have mitigations in place where that small *200px \* 200px* UI | ||
will get scaled up by essentially **taking a screenshot of it and enlarging the image.** | ||
This will result in a blurry UI with diagonal and curved lines suffering the most. | ||
There is more hope with fonts where the vector information is still available to the platform, | ||
and instead of scaling up the image the text can be immediately drawn at the larger size. | ||
|
||
## A better solution | ||
|
||
The application should draw everything it can with **vector graphics**, | ||
and have **very large resolution image** assets available where vectors aren't viable. | ||
Then at runtime the application should identify the display pixel density | ||
and resize everything accordingly. The vector graphics are easy to resize and | ||
the large image assets would be scaled down to the size that makes sense for the specific display. | ||
|
||
## An even better way | ||
|
||
Druid aims to make all of this as **easy and automatic** as possible. | ||
Druid has expressive vector drawing capabilities that you should use whenever possible. | ||
Vector drawing is also used by the widgets that come included with druid. | ||
Handling different pixel densities is done at the `druid-shell` level already. | ||
In fact pixels mostly don't even enter the conversation at the `druid` level. | ||
The `druid` coordinate system is instead measured in **display points** (**dp**), | ||
e.g. you might say a widget has a width of **100dp**. | ||
*Display points* are conceptually similar to Microsoft's *device-independent pixels*, | ||
Google's *density-independent pixels*, Apple's *points*, and CSS's *pixel units*. | ||
|
||
You **describe the UI using display points and then druid will automatically | ||
translate that into pixels** based on the pixel density of the platform. | ||
Remember there might be multiple displays connected with different pixel densities, | ||
and your application might have multiple windows - with each window on a different display. | ||
It will all just work, because druid will adjust the actual pixel dimensions | ||
based on the display that the window is currently located on. | ||
|
||
## High pixel density images with druid | ||
|
||
*TODO: Write this section after it's more clear how this works and if its even solved.* |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure blurry is the right term. At least on a 200% display, Windows uses nearest-neighbour scaling rather than bilinear or such, so it’s just like you had half the resolution, rather than being blurry as such.
I’d tend to say it’s actually text that suffers the most. On Windows by default, either the app is DPI-aware, or the entire thing gets scaled. You can also override the app’s preference and opt into one of these modes (“application” and “system”) if you know how (right click on the executable or shortcut in Explorer, Properties, Compatibility, Change high DPI settings), and there’s a third mode you can choose these days, “system enhanced”, which tries to be clever, matching what you describe, so that sizes mostly get doubled, bitmaps get nearest-neighbour scaled, and GDI text gets rendered perfectly; it works fairly well on some apps (I run BPBible that way: it has minor issues and a few widgets end up half sized, but I’m OK with that), but badly on others (it made Audacity almost entirely half sized and too hard to use; and my experience is that DPI-unaware GTK apps are generally lousy in this mode).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Microsoft seems to use blurry and fuzzy to describe the situation. I think it's fine, but if you have specific suggestions for replacement terms, I'm open to considering them.