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
+21 -2
View File
@@ -213,15 +213,32 @@ void SetupTheme(GuiTheme theme) {
s.DockingNodeHasCloseButton = false;
}
void RescaleDock(float ratio) {
if (ratio == 1) return;
ImGuiID root = ImGui::GetID("Root");
ImGuiDockNode* root_node = ImGui::DockBuilderGetNode(root);
if (root_node) {
struct ScaleNodes {
static void Apply(ImGuiDockNode* node, float r) {
node->SizeRef.x *= r;
if (node->ChildNodes[0]) Apply(node->ChildNodes[0], r);
if (node->ChildNodes[1]) Apply(node->ChildNodes[1], r);
}
};
ScaleNodes::Apply(root_node, ratio);
}
}
ImVec4 ConfigureDockingLayout() {
ImGuiViewport* viewport = ImGui::GetMainViewport();
const float scale = ImGui::GetWindowDpiScale();
const float font_scale = ImGui::GetIO().FontGlobalScale;
const float kOptionsRelWidth = 0.22f;
const float kInspectorRelWidth = 0.22f;
const float kStatsRelHeight = 0.3f;
const float kToolsBarHeight = 36.f * scale;
const float kStatusBarHeight = 32.f * scale;
const float kToolsBarHeight = 36.f * scale * font_scale;
const float kStatusBarHeight = 32.f * scale * font_scale;
const ImVec2 dockspace_pos{viewport->WorkPos.x,
viewport->WorkPos.y + kToolsBarHeight};
@@ -303,6 +320,7 @@ ImVec4 ConfigureDockingLayout() {
platform::ScopedStyle style;
style.Var(ImGuiStyleVar_WindowBorderSize, 1.0f);
style.Var(ImGuiStyleVar_WindowRounding, 0.0f);
style.Var(ImGuiStyleVar_WindowMinSize, ImVec2(1, 1));
const float toolbar_vpad =
std::max(0.f, (kToolsBarHeight - ImGui::GetFrameHeight()) * 0.5f);
style.Var(ImGuiStyleVar_WindowPadding, ImVec2(4, toolbar_vpad));
@@ -318,6 +336,7 @@ ImVec4 ConfigureDockingLayout() {
platform::ScopedStyle style;
style.Var(ImGuiStyleVar_WindowBorderSize, 1.0f);
style.Var(ImGuiStyleVar_WindowRounding, 0.0f);
style.Var(ImGuiStyleVar_WindowMinSize, ImVec2(1, 1));
ImGui::SetNextWindowPos(ImVec2(0, viewport->Size.y - kStatusBarHeight),
ImGuiCond_Always);
ImGui::SetNextWindowSize(ImVec2(viewport->Size.x, kStatusBarHeight),
+3
View File
@@ -42,6 +42,9 @@ enum class GuiTheme {
// Updates the ImGui internal style state to match the requested theme.
void SetupTheme(GuiTheme theme);
// Rescales all dock node widths by the given ratio.
void RescaleDock(float ratio);
// Configures the ImGui docking module to the standard layout used by Studio.
// This includes the following named sections:
// "ToolBar": fixed size bar spanning the top of the window; for placing