From d2c50b5548cbcc74feb04971cd1280c2b1ee1a6e Mon Sep 17 00:00:00 2001 From: shweet Date: Sun, 22 Nov 2026 19:00:42 -0500 Subject: [PATCH] Lay out the welcome window and dockspace with one helper --- src/ui/dockspace.cpp | 10 ++-------- src/ui/layout.h | 10 ++++++++++ src/ui/welcome.cpp | 9 +-------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/ui/dockspace.cpp b/src/ui/dockspace.cpp index 8f0e994..35103b9 100644 --- a/src/ui/dockspace.cpp +++ b/src/ui/dockspace.cpp @@ -1,4 +1,5 @@ #include "ui/dockspace.h" +#include "ui/layout.h" bool Dockspace::is_canvas_focused_get() const { @@ -31,14 +32,7 @@ void Dockspace::update(Taskbar& taskbar, Documents& documents, Manager& manager, { isCanvasFocused = false; - auto viewport = ImGui::GetMainViewport(); - auto windowHeight = viewport->Size.y - taskbar.height - documents.height; - if (windowHeight < 1.0f) - windowHeight = 1.0f; - - ImGui::SetNextWindowViewport(viewport->ID); - ImGui::SetNextWindowPos(ImVec2(viewport->Pos.x, viewport->Pos.y + taskbar.height + documents.height)); - ImGui::SetNextWindowSize(ImVec2(viewport->Size.x, windowHeight)); + main_area_next_set(taskbar.height + documents.height); if (ImGui::Begin("##DockSpace", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | diff --git a/src/ui/layout.h b/src/ui/layout.h index 2e692c4..198b0f5 100644 --- a/src/ui/layout.h +++ b/src/ui/layout.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include "vec.h" @@ -52,3 +53,12 @@ inline void tooltip_set(StringType type) { ImGui::SetItemTooltip("%s", localize.get(type)); } + +// The next window fills the main viewport below `top`. +inline void main_area_next_set(float top) +{ + auto viewport = ImGui::GetMainViewport(); + ImGui::SetNextWindowViewport(viewport->ID); + ImGui::SetNextWindowPos(ImVec2(viewport->Pos.x, viewport->Pos.y + top)); + ImGui::SetNextWindowSize(ImVec2(viewport->Size.x, std::max(viewport->Size.y - top, 1.0f))); +} diff --git a/src/ui/welcome.cpp b/src/ui/welcome.cpp index e7773b4..9adadb6 100644 --- a/src/ui/welcome.cpp +++ b/src/ui/welcome.cpp @@ -12,14 +12,7 @@ void welcome_update(Manager& manager, Resources& resources, Dialog& dialog, Taskbar& taskbar, Documents& documents) { - auto viewport = ImGui::GetMainViewport(); - auto windowHeight = viewport->Size.y - taskbar.height - documents.height; - if (windowHeight < 1.0f) - windowHeight = 1.0f; - - ImGui::SetNextWindowViewport(viewport->ID); - ImGui::SetNextWindowPos(ImVec2(viewport->Pos.x, viewport->Pos.y + taskbar.height + documents.height)); - ImGui::SetNextWindowSize(ImVec2(viewport->Size.x, windowHeight)); + main_area_next_set(taskbar.height + documents.height); if (ImGui::Begin(localize.get(LABEL_WELCOME_WINDOW), nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize |