ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
58.96k stars 10.06k forks source link

Correct way to Scale entire app? #6176

Open imgemmy opened 1 year ago

imgemmy commented 1 year ago

Hey,

I am currently stuck trying to figure out how to scale the UI of an entire app. Our beta testers really wanted an option to add some sort of slider for uniform scaling (the entire UI, since some users are on 4k and others on 1080p). Is this currently not possible? I've been reading answers for a few days but haven't found a solution that works.

We're using ImGui w/DX11, is there a DirectX function or ImGui function that can do this? I've tried some of the other suggestions such as io.FontGlobalScale, ImGuiStyle::ScaleAllSizes and none seem to retain the same layout (or uniformly scale).

Any help on this would be greatly appreciated.

nuuSolutions commented 1 year ago

We're in the same boat. 'Out of box' support for this would be really nice. Simple scaling is not possible because of pixel alignment, but one could surely figure something out here.

As for now I do the following On Init (or window resize) I calculate and store my own OverallScale. I then use it to load fonts (of the appropriate scale) and call ScaleAllSizes once. Whenever I need a Size e.g., I call my own Size( x ) function that returns a value scaled by OverallScale. It's a hassle but so far OK. One annoyance remains: the window positions saved as is and are not converted. I haven't gone through the pain to write my own load/save for those.

tsl0922 commented 1 year ago

From: https://github.com/ocornut/imgui/blob/master/docs/FAQ.md#qa-fonts-text

Your ui code should avoid using hardcoded constants for size and positioning. Prefer to express values as multiple of reference values such as ImGui::GetFontSize() or ImGui::GetFrameHeight(). So e.g. instead of seeing a hardcoded height of 500 for a given item/window, you may want to use 30*ImGui::GetFontSize() instead.