Skip to content

Commit

Permalink
Fix preview legend window size (#3363)
Browse files Browse the repository at this point in the history
Fix issue that the legend window expands to all available horizontal space if scrollbar is displayed

(cherry picked from commit a8ade15)
  • Loading branch information
Noisyfox authored and SoftFever committed Dec 30, 2023
1 parent 5a14fa2 commit 0857742
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/slic3r/GUI/GCodeViewer.cpp
Expand Up @@ -4504,16 +4504,17 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
return ret;
};

auto calculate_offsets = [max_width, window_padding](const std::vector<std::pair<std::string, std::vector<::string>>>& title_columns, float extra_size = 0.0f) {
auto calculate_offsets = [&imgui, max_width, window_padding](const std::vector<std::pair<std::string, std::vector<::string>>>& title_columns, float extra_size = 0.0f) {
const ImGuiStyle& style = ImGui::GetStyle();
std::vector<float> offsets;
offsets.push_back(max_width(title_columns[0].second, title_columns[0].first, extra_size) + 3.0f * style.ItemSpacing.x);
for (size_t i = 1; i < title_columns.size() - 1; i++)
offsets.push_back(offsets.back() + max_width(title_columns[i].second, title_columns[i].first) + style.ItemSpacing.x);
if (title_columns.back().first == _u8L("Display")) {
const auto preferred_offset = ImGui::GetWindowWidth() - ImGui::CalcTextSize(_u8L("Display").c_str()).x - ImGui::GetFrameHeight() / 2 - 2 * window_padding;
const auto preferred_offset = ImGui::GetWindowWidth() - ImGui::CalcTextSize(_u8L("Display").c_str()).x - ImGui::GetFrameHeight() / 2 - 2 * window_padding - ImGui::GetStyle().ScrollbarSize;
if (preferred_offset > offsets.back()) {
offsets.back() = preferred_offset;
imgui.set_requires_extra_frame();
}
}

Expand Down

0 comments on commit 0857742

Please sign in to comment.