From 86f10f9f2a34c828ff1e31527cccd1002f2a4344 Mon Sep 17 00:00:00 2001 From: redstrate <54911369+redstrate@users.noreply.github.com> Date: Mon, 17 Aug 2020 09:27:24 -0400 Subject: [PATCH] Change asset browser's column calculation to be more conservative --- tools/common/src/commoneditor.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tools/common/src/commoneditor.cpp b/tools/common/src/commoneditor.cpp index ec42ca7..add3d37 100755 --- a/tools/common/src/commoneditor.cpp +++ b/tools/common/src/commoneditor.cpp @@ -284,7 +284,7 @@ void CommonEditor::begin_frame() { ImGui::SetWindowSize(ImVec2(500, 500)); - ImGui::BeginChild("assetbox", ImVec2(-1, -1), true); + ImGui::BeginChild("assetbox", ImVec2(-1, 400), true); int column = 0; for(auto& [p, a_type] : asset_files) { @@ -756,10 +756,15 @@ void CommonEditor::drawAssets() { if(!filesystem_cached) cacheAssetFilesystem(); - auto window_size = ImGui::GetWindowSize(); + const float window_width = ImGui::GetWindowWidth(); + const float item_spacing = ImGui::GetStyle().ItemSpacing.x; + const float frame_padding = ImGui::GetStyle().FramePadding.x; + const float window_padding = ImGui::GetStyle().WindowPadding.x; - const int max_columns = (static_cast(window_size.x) % 70) - 2; + const float column_width = 64.0f + item_spacing + (frame_padding * 2.0f); + const int max_columns = std::floor((window_width - window_padding) / column_width); + int column = 0; for(auto& [p, type] : asset_files) { ImGui::PushID(&p); @@ -781,7 +786,7 @@ void CommonEditor::drawAssets() { column++; - if(column == max_columns) { + if(column >= max_columns) { column = 0; } else { ImGui::SameLine();