Add setting for UI scale (#2326)

This commit is contained in:
doop
2026-08-22 01:29:43 -04:00
committed by GitHub
parent 44e02a9d53
commit 14f9b6c762
6 changed files with 26 additions and 0 deletions
+4
View File
@@ -1,6 +1,7 @@
#include "dusk/settings.h"
#include <aurora/aurora.h>
#include "dusk/config.hpp"
#include "dusk/ui/ui.hpp"
#include "dusk/game_mode.hpp"
namespace dusk {
@@ -16,6 +17,7 @@ UserSettings g_userSettings = {
.rememberWindowSize {"video.rememberWindowSize", false},
.lastWindowWidth {"video.lastWindowWidth", 0},
.lastWindowHeight {"video.lastWindowHeight", 0},
.uiScale {"video.uiScale", 100},
},
.audio = {
@@ -228,6 +230,8 @@ void registerSettings() {
Register(g_userSettings.video.rememberWindowSize);
Register(g_userSettings.video.lastWindowWidth);
Register(g_userSettings.video.lastWindowHeight);
Register(g_userSettings.video.uiScale,
[](const int&, const int&) { dusk::ui::apply_scale(); });
// Audio
Register(g_userSettings.audio.masterVolume);
+1
View File
@@ -145,6 +145,7 @@ struct UserSettings {
ConfigVar<bool> rememberWindowSize;
ConfigVar<int> lastWindowWidth;
ConfigVar<int> lastWindowHeight;
ConfigVar<int> uiScale;
} video;
struct {
+6
View File
@@ -770,6 +770,12 @@ SettingsWindow::SettingsWindow(bool prelaunch) : mPrelaunch(prelaunch) {
},
.isDisabled = [] { return IsMobile; },
});
config_int_select(leftPane, rightPane, getSettings().video.uiScale,
"UI Scale",
"Scales the Dusklight interface relative to the display's DPI scale. Has no effect on the game's UI and HUD.",
50, 200, 25, {}, {}, "%");
leftPane.add_section("Resolution");
graphics_tuner_control(*this, leftPane, rightPane,
getSettings().game.internalResolutionScale,
+12
View File
@@ -214,6 +214,8 @@ void handle_event(const SDL_Event& event) noexcept {
});
}
sConnectedGamepads.erase(event.gdevice.which);
} else if (event.type == SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED) {
apply_scale();
}
input::handle_event(event);
}
@@ -491,4 +493,14 @@ bool consume_menu_notification_request() noexcept {
return requested;
}
void apply_scale() noexcept {
const auto userScale = getSettings().video.uiScale.getValue();
auto scale = 0.0f;
if (userScale != 0) {
const auto displayScale = aurora::window::get_window_size().scale;
scale = static_cast<float>(userScale) / 100.0f * (displayScale > 0.0f ? displayScale : 1.0f);
}
aurora::rmlui::set_ui_scale(scale);
}
} // namespace dusk::ui
+2
View File
@@ -114,4 +114,6 @@ bool consume_menu_notification_request() noexcept;
const char* battery_icon(SDL_PowerState state, int level) noexcept;
const char* connection_state_icon(SDL_JoystickConnectionState state) noexcept;
void apply_scale() noexcept;
} // namespace dusk::ui
+1
View File
@@ -776,6 +776,7 @@ int game_main(int argc, char* argv[]) {
dusk::texture_replacements::reload();
dusk::ui::initialize();
dusk::ui::apply_scale();
dusk::ui::push_document(std::make_unique<dusk::ui::Overlay>(), true, true);
dusk::ui::push_document(std::make_unique<dusk::ui::TouchControls>(), false, true);
dusk::ui::push_document(std::make_unique<dusk::ui::MenuBar>(), false);