Skip to content

Commit 80f9eb5

Browse files
committed
Single 'UI Scale' option
1 parent 131fa93 commit 80f9eb5

7 files changed

Lines changed: 81 additions & 40 deletions

File tree

Sources/OvEditor/include/OvEditor/Settings/EditorSettings.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ namespace OvEditor::Settings
9898
inline static Property<float> ScalingSnapUnit = { 1.0f };
9999
inline static Property<int> ColorTheme = { static_cast<int>(OvUI::Styling::EStyle::DEFAULT_DARK) };
100100
inline static Property<int> ConsoleMaxLogs = { 500 };
101-
inline static Property<int> FontScale = { 100 };
102-
inline static Property<bool> FontDpiScaling = true;
101+
inline static Property<int> UIScale = { 0 };
103102
inline static Property<std::string> CodeEditorCommand = { "code {workdir} --goto {path}" };
104103
inline static Property<bool> RegenerateScriptingProjectFilesOnStartup = { true };
105104
};

Sources/OvEditor/src/OvEditor/Core/Context.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,16 @@ OvEditor::Core::Context::Context(const std::filesystem::path& p_projectFolder) :
130130
const auto fontPath = editorAssetsPath / "Fonts" / "Ruda-Bold.ttf";
131131
uiManager->LoadFont("Ruda-Bold", fontPath.string(), 15);
132132
uiManager->UseFont("Ruda-Bold");
133-
uiManager->SetFontScale(Settings::EditorSettings::FontScale / 100.0f);
134-
uiManager->EnableDPIScaling(Settings::EditorSettings::FontDpiScaling.Get());
133+
134+
const int uiScale = Settings::EditorSettings::UIScale.Get();
135+
if (uiScale == 0)
136+
{
137+
uiManager->DpiScaleUI();
138+
}
139+
else
140+
{
141+
uiManager->SetUIScale(uiScale / 100.0f);
142+
}
135143

136144
uiManager->SetEditorLayoutSaveFilename(OvEditor::Utils::FileSystem::kLayoutFilePath.string());
137145
uiManager->SetEditorLayoutAutosaveFrequency(60.0f);

Sources/OvEditor/src/OvEditor/Core/ProjectHub.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,16 @@ void OvEditor::Core::ProjectHub::SetupContext()
289289

290290
m_uiManager->LoadFont("Ruda-Bold", fontPath.string(), 18);
291291
m_uiManager->UseFont("Ruda-Bold");
292-
m_uiManager->SetFontScale(Settings::EditorSettings::FontScale / 100.0f);
293-
m_uiManager->EnableDPIScaling(Settings::EditorSettings::FontDpiScaling.Get());
292+
293+
const int uiScale = Settings::EditorSettings::UIScale.Get();
294+
if (uiScale == 0)
295+
{
296+
m_uiManager->DpiScaleUI();
297+
}
298+
else
299+
{
300+
m_uiManager->SetUIScale(uiScale / 100.0f);
301+
}
294302

295303
m_uiManager->EnableEditorLayoutSave(false);
296304
m_uiManager->EnableDocking(false);

Sources/OvEditor/src/OvEditor/Panels/MenuBar.cpp

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -93,32 +93,26 @@ void OvEditor::Panels::MenuBar::InitializeSettingsMenu()
9393
EDITOR_CONTEXT(uiManager)->ApplyStyle(static_cast<OvUI::Styling::EStyle>(p_value));
9494
};
9595

96-
enum class EFontScale : uint32_t
97-
{
98-
EXTRA_SMALL = 50,
99-
SMALL = 75,
100-
MEDIUM = 100,
101-
BIG = 150,
102-
EXTRA_BIG = 200
103-
};
104-
105-
auto& fontSizeMenu = m_settingsMenu->CreateWidget<MenuList>("Font Size");
106-
auto& fontSizeSelector = fontSizeMenu.CreateWidget<Selection::ComboBox>(static_cast<int>(Settings::EditorSettings::FontScale.Get()));
107-
fontSizeSelector.choices = {
108-
{ static_cast<int>(EFontScale::EXTRA_SMALL), "Extra Small"},
109-
{ static_cast<int>(EFontScale::SMALL), "Small"},
110-
{ static_cast<int>(EFontScale::MEDIUM), "Medium"},
111-
{ static_cast<int>(EFontScale::BIG), "Big"},
112-
{ static_cast<int>(EFontScale::EXTRA_BIG), "Extra Big"},
113-
};
114-
fontSizeSelector.ValueChangedEvent += [this](int p_value) {
115-
Settings::EditorSettings::FontScale = p_value;
116-
EDITOR_CONTEXT(uiManager)->SetFontScale(p_value / 100.0f);
96+
auto& uiScale = themeButton.CreateWidget<Selection::ComboBox>(static_cast<int>(Settings::EditorSettings::UIScale.Get()));
97+
uiScale.choices = {
98+
{ 0, "Automatic (DPI Aware)"},
99+
{ 100, "100%"},
100+
{ 150, "150%"},
101+
{ 200, "200%"},
117102
};
118-
auto& fontDpiScaling = fontSizeMenu.CreateWidget<OvUI::Widgets::Selection::CheckBox>(Settings::EditorSettings::FontDpiScaling, "Scale with DPI");
119-
fontDpiScaling.ValueChangedEvent += [this](bool p_value) {
120-
Settings::EditorSettings::FontDpiScaling = p_value;
121-
EDITOR_CONTEXT(uiManager)->EnableDPIScaling(p_value);
103+
uiScale.ValueChangedEvent += [this](int p_value) {
104+
Settings::EditorSettings::UIScale = p_value;
105+
if (p_value == 0)
106+
{
107+
EDITOR_CONTEXT(uiManager)->DpiScaleUI();
108+
}
109+
else
110+
{
111+
EDITOR_CONTEXT(uiManager)->SetUIScale(p_value / 100.0f);
112+
}
113+
// EDITOR_EXEC(DelayAction([p_value]() {
114+
// EDITOR_CONTEXT(uiManager)->SetStyleScale(p_value / 100.0f);
115+
// }));
122116
};
123117

124118
m_settingsMenu->CreateWidget<MenuItem>("Spawn actors at origin", "", true, true).ValueChangedEvent += EDITOR_BIND(SetActorSpawnAtOrigin, std::placeholders::_1);

Sources/OvEditor/src/OvEditor/Settings/EditorSettings.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ void OvEditor::Settings::EditorSettings::Save()
4444
iniFile.Add("rotation_snap_unit", RotationSnapUnit.Get());
4545
iniFile.Add("scaling_snap_unit", ScalingSnapUnit.Get());
4646
iniFile.Add("color_theme", ColorTheme.Get());
47+
iniFile.Add("ui_scale", UIScale.Get());
4748
iniFile.Add("console_max_logs", ConsoleMaxLogs.Get());
48-
iniFile.Add("font_scale", FontScale.Get());
49-
iniFile.Add("font_dpi_scaling", FontDpiScaling.Get());
5049
iniFile.Add("code_editor_command", CodeEditorCommand.Get());
5150
iniFile.Add("always_regenerate_scripting_symbols", RegenerateScriptingProjectFilesOnStartup.Get());
5251
iniFile.Rewrite();
@@ -66,9 +65,8 @@ void OvEditor::Settings::EditorSettings::Load()
6665
LoadIniEntry<float>(iniFile, "rotation_snap_unit", RotationSnapUnit);
6766
LoadIniEntry<float>(iniFile, "scaling_snap_unit", ScalingSnapUnit);
6867
LoadIniEntry<int>(iniFile, "color_theme", ColorTheme);
68+
LoadIniEntry<int>(iniFile, "ui_scale", UIScale);
6969
LoadIniEntry<int>(iniFile, "console_max_logs", ConsoleMaxLogs);
70-
LoadIniEntry<int>(iniFile, "font_scale", FontScale);
71-
LoadIniEntry<bool>(iniFile, "font_dpi_scaling", FontDpiScaling);
7270
LoadIniEntry<std::string>(iniFile, "code_editor_command", CodeEditorCommand);
7371
LoadIniEntry<bool>(iniFile, "always_regenerate_scripting_symbols", RegenerateScriptingProjectFilesOnStartup);
7472
}

Sources/OvUI/include/OvUI/Core/UIManager.h

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,26 @@ namespace OvUI::Core
6565

6666
/**
6767
* Set the font size
68-
* @param p_size
68+
* @param p_scale
6969
*/
70-
void SetFontScale(float p_size);
70+
void SetFontScale(float p_scale);
71+
72+
/**
73+
* Set the global UI scale
74+
* @param p_scale
75+
*/
76+
void SetStyleScale(float p_scale);
77+
78+
/**
79+
* Set the UI scale
80+
* @param p_scale
81+
*/
82+
void SetUIScale(float p_scale);
83+
84+
/**
85+
* Set UI scaled based on window DPI
86+
*/
87+
void DpiScaleUI();
7188

7289
/**
7390
* Allow the user to enable/disable .ini generation to save his editor layout
@@ -150,6 +167,8 @@ namespace OvUI::Core
150167
private:
151168
bool m_dockingState;
152169
bool m_dpiScaling;
170+
Styling::EStyle m_currentStyle;
171+
float m_styleScale = 1.0f;
153172
Modules::Canvas* m_currentCanvas = nullptr;
154173
std::unordered_map<std::string, ImFont*> m_fonts;
155174
std::string m_layoutSaveFilename = "imgui.ini";

Sources/OvUI/src/OvUI/Core/UIManager.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ OvUI::Core::UIManager::~UIManager()
5252

5353
void OvUI::Core::UIManager::ApplyStyle(Styling::EStyle p_style)
5454
{
55-
ImGui::GetStyle() = GetStyle(p_style);
55+
m_currentStyle = p_style;
56+
auto style = GetStyle(p_style);
57+
style.FontScaleMain = m_styleScale;
58+
style.ScaleAllSizes(m_styleScale);
59+
ImGui::GetStyle() = style;
5660
}
5761

5862
bool OvUI::Core::UIManager::LoadFont(const std::string& p_id, const std::string & p_path, float p_fontSize)
@@ -101,9 +105,20 @@ void OvUI::Core::UIManager::UseDefaultFont()
101105
ImGui::GetIO().FontDefault = nullptr;
102106
}
103107

104-
void OvUI::Core::UIManager::SetFontScale(float p_scale)
108+
void OvUI::Core::UIManager::SetUIScale(float p_scale)
105109
{
106-
ImGui::GetIO().FontGlobalScale = p_scale;
110+
// FIXME: Explain that (through assert or error message?)
111+
if (p_scale < 1.0f) return;
112+
113+
m_styleScale = p_scale;
114+
ApplyStyle(m_currentStyle);
115+
}
116+
117+
void OvUI::Core::UIManager::DpiScaleUI()
118+
{
119+
SetUIScale(
120+
ImGui::GetWindowDpiScale()
121+
);
107122
}
108123

109124
void OvUI::Core::UIManager::EnableEditorLayoutSave(bool p_value)

0 commit comments

Comments
 (0)