Implement UI scaling in Derma UIs
Currently, only the HUD is scaled. This is rather annoying for those with high DPI displays, as much of the text is too small to be readable. Instead, we want to present as much of our UI according to the user's specified UI scale as possible, which this PR does.
This unfortunately means threading * scale through a bunch of layout and skin code, and it also means that non-default skins will not work until updated (This is particularly onerous with the role debugger and embedded legacy VGUI menus). I tried, at first, implementing a fully-general system that would automatically attempt to scale things which are not hidpi-aware, but that NOT ONLY had terrible performance, but ALSO didn't work.
In the process of doing this, I also discovered that draw.AdvancedText was implemented fundamentally incorrectly, and have fixed it.
Some limitations:
- For some reason, I cannot convince
Panel:DrawTextEntryText()to use a different font set dynamically or be scaled. IsPanel:SetFont()frame-delayed? - Body search result items have their description currently hard-coded to
DermaDefault, which doesn't have scaled variants and so looks bad (though it is scaled! I spent 3 whole days on this!)
Currently unchanged:
- Scoreboard
- Buy menu
- Round start popup
- Spectator timeout popup
I intend to continue this and apply scaling to the scoreboard as well, but I don't think the buy menu is reasonably possible without giving it a whole UI overhaul.
Before:
After: (1.5x UI scale)
Wow, you're really doing the heavy lifting here. I'm impressed. Another point on my todo list I thought I'd never get around to.
This is particularly onerous with the role debugger
This addon is broken anyway since a while. This is the reason I started adding lots of features of that addon to TTT2. The actual role debugging is missing though. The dev of that addon said they wanted to contribute to TTT2 and add that stuff, but I guess they didn't have the time so far.
A few things I want to add:
- font scaling is currently very basic. I spent some time in summer 2024 digging deeper and I have an idea how to vastly improve the performance and visual fidelity of fonts. Didn't have the time and motivation yet though
- Right now, for vgui all sizes are recalculated and all strings are translated every frame; this could be cached which would improve the performance quite a lot
There's quite a lot of VGUI which makes this painful. Honestly, I'm tempted to try to make another layer above VGUI which enables UI code to not have to care about scaling or translation caching, and have all of that handled automatically. That would require a LOT more work, but may wind up being more worthwhile long-term.
There's quite a lot of VGUI which makes this painful. Honestly, I'm tempted to try to make another layer above VGUI which enables UI code to not have to care about scaling or translation caching, and have all of that handled automatically. That would require a LOT more work, but may wind up being more worthwhile long-term.
I tried this at one point with the drawsc library. And while this improved a lot of things for the HUD code, in the end it was way too basic to make a different.
VGUI right now is awful, mostly due to me. VGUI is built on top of inheritance, but I hacked quite a lot of features in it which breaks the inheritance. Moreover vgui by itself is designed to be cached and only updated when changes happen, but at the time I wasn't aware, so my code completely ignores it.
If one would want to exted it, it probably needs a partial rewrite.
Ah, and here's the issue about the font stuff. Some of my investigation results are in there, but I guess most of them are just in my head and on paper: https://github.com/TTT-2/TTT2/issues/1402
In #1752 I'm currently rebuilding how the color caching works. Once this is done I can show you how I did this and you can use the same system to rescale alle UIs.
It basically works by using GMod's proper systems of invalidating layouts.