Skip to content
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

Support display pixel (dp) as a unit for Controls (maybe also in other places) #2868

Closed
ModProg opened this issue Jun 15, 2021 · 3 comments
Closed

Comments

@ModProg
Copy link

ModProg commented Jun 15, 2021

Describe the project you are working on

A Cross Platform Graphical Notetaking Application

Describe the problem or limitation you are having in your project

Writing the UI I currently fall back to manually scale UI elements using the dpi value of OS.get_screen_dpi(OS.get_current_screen()). but this leads to a lot of complication due to resulting in me needing to set all the theme values (eg. margin) in code and not being able to use Themes for that.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Adding (for example to a theme) the option to use dp instead of normal pixels (1 dp = 160 / screen density) or another resolution independent unit.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

  1. When applying the theme to Controls apply the StyleBox sizes not as pixels but as dp's.
  2. (Better in my opinion) Change all Pixels to DP for controls (If enabled), this would also make it possible to use the DPs for other UI values like size.

If this enhancement will not be used often, can it be worked around with a few lines of script?

It can be worked around by adding a function that for each value in a theme calculates the correct value (dp->pixel) and applies that new theme.

Is there a reason why this should be core and not an add-on in the asset library?

This could be done as an addon but this would not be easily integreted (would only work if the addon reexports every Control as a DPControl).

@Calinou
Copy link
Member

Calinou commented Jun 15, 2021

For games, Godot's multiple resolutions support should suffice as you want 2D elements to scale automatically to match the display resolution in games. If you have no reason to use anything else, use the 2d stretch mode, expand stretch aspect and configure your UI nodes' anchors to support multiple aspect ratios.

For non-game applications, the best way to solve this is to add a 2D scale factor property which can be adjusted at run-time. Unlike stretch shrink, this property doesn't affect the viewport size. It only affects the scale at which 2D elements are rendered.

Until a 2D scale factor property is merged, you can use this workaround which works well enough to make the app usable for integer scale factors. You can make it work better for fractional scale factors by using a viewport that has filtering enabled. Note that enabling filtering on the root Viewport will only have an effect when using GLES2, not GLES3.

@Calinou
Copy link
Member

Calinou commented Nov 3, 2021

This was addressed by godotengine/godot#52137 in 3.x and is being addressed by godotengine/godot#52170 in master. (See my comment above about the current lack of a display scale factor for context.)

@Calinou Calinou added this to the 4.0 milestone Nov 3, 2021
@Calinou
Copy link
Member

Calinou commented Jan 11, 2022

Closing, as godotengine/godot#52170 was recently merged 🙂

@Calinou Calinou closed this as completed Jan 11, 2022
@Calinou Calinou modified the milestones: 4.0, 3.x Jan 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants