Add font scaling to studio, bound to CTRL+MINUS/PLUS

PiperOrigin-RevId: 907491215
Change-Id: I144467c3ff0e3d11f4a5bfb6ed2b1e4e88b8693d
This commit is contained in:
Yuval Tassa
2026-04-29 03:41:21 -07:00
committed by Copybara-Service
parent d92fe0810c
commit 9796345888
4 changed files with 37 additions and 2 deletions
+12
View File
@@ -578,6 +578,14 @@ void App::HandleKeyboardEvents() {
tmp_.inspector_panel = !tmp_.inspector_panel;
} else if (ImGui_IsChordJustPressed(ImGuiKey_Tab)) {
tmp_.options_panel = !tmp_.options_panel;
} else if (ImGui_IsChordJustPressed(ImGuiKey_Minus | ImGuiMod_Ctrl)) {
float old_scale = ui_.font_scale;
ui_.font_scale = std::clamp(ui_.font_scale - 0.1f, 0.5f, 3.0f);
platform::RescaleDock(ui_.font_scale / old_scale);
} else if (ImGui_IsChordJustPressed(ImGuiKey_Equal | ImGuiMod_Ctrl)) {
float old_scale = ui_.font_scale;
ui_.font_scale = std::clamp(ui_.font_scale + 0.1f, 0.5f, 3.0f);
platform::RescaleDock(ui_.font_scale / old_scale);
} else if (ImGui_IsChordJustPressed(ImGuiKey_Minus)) {
SetSpeedIndex(tmp_.speed_index + 1);
} else if (ImGui_IsChordJustPressed(ImGuiKey_Equal)) {
@@ -823,6 +831,8 @@ void App::BuildGui() {
platform::SetupTheme(ui_.theme);
}
ImGui::GetIO().FontGlobalScale = ui_.font_scale;
const ImVec4 workspace_rect = platform::ConfigureDockingLayout();
// Place charts in bottom right corner of the workspace.
@@ -1841,11 +1851,13 @@ float App::GetExpectedLabelWidth() {
App::UiState::Dict App::UiState::ToDict() const {
return {
{"theme", std::to_string(static_cast<int>(theme))},
{"font_scale", std::to_string(font_scale)},
};
}
void App::UiState::FromDict(const Dict& dict) {
*this = UiState();
theme = ReadIniValue(dict, "theme", theme);
font_scale = platform::ReadIniValue(dict, "font_scale", font_scale);
}
} // namespace mujoco::studio
+1
View File
@@ -105,6 +105,7 @@ class App {
int camera_idx = platform::kTumbleCameraIdx;
int key_idx = 0;
platform::GuiTheme theme = platform::GuiTheme::kLight;
float font_scale = 1.0f;
using Dict = std::unordered_map<std::string, std::string>;
Dict ToDict() const;