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

Implement UI scaling in Derma UIs #1719

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft

Conversation

nike4613
Copy link
Contributor

@nike4613 nike4613 commented Jan 18, 2025

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. Is Panel: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:
Screenshot_20250118_024453
Screenshot_20250118_024459
Screenshot_20250118_024507
Screenshot_20250118_024548

After: (1.5x UI scale)
Screenshot_20250118_025243
Screenshot_20250118_025245
Screenshot_20250118_025250
Screenshot_20250118_025410

@nike4613 nike4613 marked this pull request as draft January 18, 2025 09:05
@TimGoll
Copy link
Member

TimGoll commented Jan 19, 2025

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

@nike4613
Copy link
Contributor Author

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.

@TimGoll
Copy link
Member

TimGoll commented Jan 19, 2025

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.

@TimGoll
Copy link
Member

TimGoll commented Jan 19, 2025

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: #1402

@TimGoll TimGoll self-assigned this Jan 21, 2025
@TimGoll TimGoll added the type/enhancement Enhancement or simple change to existing functionality label Jan 21, 2025
@TimGoll
Copy link
Member

TimGoll commented Feb 1, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement Enhancement or simple change to existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants