What Changes are Needed to Change DPI at Run-time?

Description

My project is on the Nintendo Switch, which switches seamlessly between a docked, HDMI-enabled 1080p display and a handheld, on-console 720p touch screen. Thus my project would need to change the display DPI at run-time as the console is docked and undocked.

What MCU/Processor/Board and compiler are you using?

I’m using a Nintendo Switch homebrew environment with libnx and compiling with DevkitA64.

What do you want to achieve?

Change the DPI at runtime so my display can adapt to a changed resolution and screen size/DPI. Docked 1080p resolution should use a lower DPI and handheld mode 720p should use a higher DPI.

Thus, I’m trying to ask about what things I should watch out/look for to refactor DPI into the display driver if I were to modify it in my lvgl fork?

What have you tried so far?

So far I have to use 2 different builds and the user has to restart the program if they are switching between docked mode and handheld mode, and this is not ideal.

Screenshot and/or video

Docked Mode: Smaller UI for the bigger 1080p screen, so it doesn’t cover up much of the game

Handheld Mode: Bigger UI for the smaller 720p screen, more friendly to touch controls as well

It’s currently impossible to change LV_DPI at runtime, so I would suggest just adjusting the sizes of objects and switching to larger fonts dynamically.

I know it’s impossible. I was asking if there is anything to look out for, like unintended consequences or something for refactoring the references of LV_DPI in my own fork before I go on and try it.

If you really want to change LV_DPI itself, I think this would be safe, because we never assign LV_DPI to a constant variable (as far as I know):

extern lv_coord_t my_custom_get_dpi_func(void);
#define LV_DPI (my_custom_get_dpi_func())

That way you can avoid making changes to LittlevGL itself.

Please note, however, that changing the DPI value like this won’t dynamically resize objects. LV_DPI is frequently used merely as a way to set a reasonable default size for an object, so you would also have to call lv_obj_set_size(obj, LV_DPI * x_factor, LV_DPI * y_factor) for each object you wanted to be resized.

It also won’t change the visual size of fonts, because fonts are bitmaps (not vectors). You would, again, have to switch between differently sized fonts depending on which screen you’re using.

Hi @3096
that is a really interesting topic.
can you share what is it you are doing using LVGL on nintendo switch?
I just want to know to widen my scope of thinking about this library and its potential.
Thanks