Save/restore window size in UX settings.

PiperOrigin-RevId: 913695007
Change-Id: I3366b11a5de53292d4ffe0e4c46f866381624788
This commit is contained in:
Haroon Qureshi
2026-05-11 07:43:29 -07:00
committed by Copybara-Service
parent 465e574c42
commit 5d818306ef
4 changed files with 33 additions and 1 deletions
+12
View File
@@ -177,6 +177,18 @@ void Window::SetTitle(std::string_view title) {
SDL_SetWindowTitle(sdl_window_, title.data());
}
void Window::Resize(int width, int height) {
SDL_SetWindowSize(sdl_window_, width, height);
SDL_SetWindowPosition(sdl_window_, SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED);
SDL_GetWindowSize(sdl_window_, &width_, &height_);
int drawable_width = width_;
int drawable_height = height_;
SDL_GL_GetDrawableSize(sdl_window_, &drawable_width, &drawable_height);
scale_ = (float)drawable_width / (float)width_;
}
void Window::DisableWindowResizing() {
SDL_SetWindowResizable(sdl_window_, SDL_FALSE);
}
+3
View File
@@ -79,6 +79,9 @@ class Window {
// Returns the graphics configuration of the window.
GraphicsMode GetGraphicsMode() const;
// Resizes the window to the given width and height.
void Resize(int width, int height);
// Enables window resizing.
void EnableWindowResizing();
+16 -1
View File
@@ -104,6 +104,11 @@ void App::SwitchGraphicsMode(int width, int height,
window_config);
renderer_ = std::make_unique<platform::Renderer>(
window_->GetNativeWindowHandle(), gfx_mode_);
LoadSettings();
if (ui_.window_width > 0 && ui_.window_height > 0) {
window_->Resize(ui_.window_width, ui_.window_height);
}
}
void App::Recompile() {
@@ -791,6 +796,10 @@ void App::LoadSettings() {
void App::SaveSettings() {
if (!ini_path_.empty()) {
std::string settings = ImGui::SaveIniSettingsToMemory();
if (window_) {
ui_.window_width = window_->GetWidth();
ui_.window_height = window_->GetHeight();
}
platform::AppendIniSection(settings, "[Studio][UX]", ui_.ToDict());
platform::KeyValues plugin_names;
@@ -1839,12 +1848,18 @@ App::UiState::Dict App::UiState::ToDict() const {
return {
{"theme", std::to_string(static_cast<int>(theme))},
{"font_scale", std::to_string(font_scale)},
{"window_width", std::to_string(window_width)},
{"window_height", std::to_string(window_height)},
};
}
void App::UiState::FromDict(const Dict& dict) {
using platform::ReadIniValue;
*this = UiState();
theme = ReadIniValue(dict, "theme", theme);
font_scale = platform::ReadIniValue(dict, "font_scale", font_scale);
window_width = ReadIniValue(dict, "window_width", window_width);
window_height = ReadIniValue(dict, "window_height", window_height);
font_scale = ReadIniValue(dict, "font_scale", font_scale);
}
} // namespace mujoco::studio
+2
View File
@@ -106,6 +106,8 @@ class App {
int key_idx = 0;
platform::GuiTheme theme = platform::GuiTheme::kLight;
float font_scale = 1.0f;
int window_width = 0;
int window_height = 0;
using Dict = std::unordered_map<std::string, std::string>;
Dict ToDict() const;