GCodeViewer - Use ImGui table to show estimated printing times in legend

This commit is contained in:
enricoturri1966 2022-09-27 14:00:36 +02:00
parent ea4da34e6b
commit 05a157c916

View File

@ -4247,6 +4247,14 @@ void GCodeViewer::render_legend(float& legend_height)
} }
#endif // !ENABLE_PREVIEW_LAYOUT #endif // !ENABLE_PREVIEW_LAYOUT
auto add_strings_row_to_table = [&imgui](const std::string& col_1, const ImVec4& col_1_color, const std::string& col_2, const ImVec4& col_2_color) {
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
imgui.text_colored(col_1_color, col_1.c_str());
ImGui::TableSetColumnIndex(1);
imgui.text_colored(col_2_color, col_2.c_str());
};
// settings section // settings section
bool has_settings = false; bool has_settings = false;
has_settings |= !m_settings_ids.print.empty(); has_settings |= !m_settings_ids.print.empty();
@ -4274,14 +4282,6 @@ void GCodeViewer::render_legend(float& legend_height)
return txt; return txt;
}; };
auto add_strings_row_to_table = [&imgui](const std::string& col_1, const ImVec4& col_1_color, const std::string& col_2, const ImVec4& col_2_color) {
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
imgui.text_colored(col_1_color, col_1.c_str());
ImGui::TableSetColumnIndex(1);
imgui.text_colored(col_2_color, col_2.c_str());
};
if (ImGui::BeginTable("Settings", 2)) { if (ImGui::BeginTable("Settings", 2)) {
if (!m_settings_ids.printer.empty()) if (!m_settings_ids.printer.empty())
add_strings_row_to_table(_u8L("Printer") + ":", ImGuiWrapper::COL_ORANGE_LIGHT, add_strings_row_to_table(_u8L("Printer") + ":", ImGuiWrapper::COL_ORANGE_LIGHT,
@ -4333,25 +4333,18 @@ void GCodeViewer::render_legend(float& legend_height)
imgui.title(time_title + ":"); imgui.title(time_title + ":");
std::string first_str = _u8L("First layer"); if (ImGui::BeginTable("Times", 2)) {
std::string total_str = _u8L("Total"); if (!time_mode.layers_times.empty()) {
add_strings_row_to_table(_u8L("First layer") + ":", ImGuiWrapper::COL_ORANGE_LIGHT,
short_time(get_time_dhms(time_mode.layers_times.front())), ImGuiWrapper::to_ImVec4(ColorRGBA::WHITE()));
}
float max_len = 10.0f + ImGui::GetStyle().ItemSpacing.x; add_strings_row_to_table(_u8L("Total") + ":", ImGuiWrapper::COL_ORANGE_LIGHT,
if (time_mode.layers_times.empty()) short_time(get_time_dhms(time_mode.time)), ImGuiWrapper::to_ImVec4(ColorRGBA::WHITE()));
max_len += ImGui::CalcTextSize(total_str.c_str()).x;
else
max_len += std::max(ImGui::CalcTextSize(first_str.c_str()).x, ImGui::CalcTextSize(total_str.c_str()).x);
if (!time_mode.layers_times.empty()) { ImGui::EndTable();
imgui.text(first_str + ":");
ImGui::SameLine(max_len);
imgui.text(short_time(get_time_dhms(time_mode.layers_times.front())));
} }
imgui.text(total_str + ":");
ImGui::SameLine(max_len);
imgui.text(short_time(get_time_dhms(time_mode.time)));
auto show_mode_button = [this, &imgui, can_show_mode_button](const wxString& label, PrintEstimatedStatistics::ETimeMode mode) { auto show_mode_button = [this, &imgui, can_show_mode_button](const wxString& label, PrintEstimatedStatistics::ETimeMode mode) {
if (can_show_mode_button(mode)) { if (can_show_mode_button(mode)) {
if (imgui.button(label)) { if (imgui.button(label)) {