GCodeViewer - Use ImGui table to show data for printer/filament/print settings ids in legend

This commit is contained in:
enricoturri1966 2022-09-27 13:50:26 +02:00
parent 8f1d4a4cdc
commit ea4da34e6b

View File

@ -4261,27 +4261,9 @@ void GCodeViewer::render_legend(float& legend_height)
show_settings &= (m_view_type == EViewType::FeatureType || m_view_type == EViewType::Tool); show_settings &= (m_view_type == EViewType::FeatureType || m_view_type == EViewType::Tool);
show_settings &= has_settings; show_settings &= has_settings;
if (show_settings) { if (show_settings) {
auto calc_offset = [this]() {
float ret = 0.0f;
if (!m_settings_ids.printer.empty())
ret = std::max(ret, ImGui::CalcTextSize((_u8L("Printer") + std::string(":")).c_str()).x);
if (!m_settings_ids.print.empty())
ret = std::max(ret, ImGui::CalcTextSize((_u8L("Print settings") + std::string(":")).c_str()).x);
if (!m_settings_ids.filament.empty()) {
for (unsigned char i : m_extruder_ids) {
ret = std::max(ret, ImGui::CalcTextSize((_u8L("Filament") + " " + std::to_string(i + 1) + ":").c_str()).x);
}
}
if (ret > 0.0f)
ret += 2.0f * ImGui::GetStyle().ItemSpacing.x;
return ret;
};
ImGui::Spacing(); ImGui::Spacing();
imgui.title(_u8L("Settings")); imgui.title(_u8L("Settings"));
float offset = calc_offset();
auto trim_text_if_needed = [](const std::string& txt) { auto trim_text_if_needed = [](const std::string& txt) {
const float max_length = 250.0f; const float max_length = 250.0f;
const float length = ImGui::CalcTextSize(txt.c_str()).x; const float length = ImGui::CalcTextSize(txt.c_str()).x;
@ -4292,26 +4274,32 @@ void GCodeViewer::render_legend(float& legend_height)
return txt; return txt;
}; };
if (!m_settings_ids.printer.empty()) { 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.text(_u8L("Printer") + ":"); ImGui::TableNextRow();
ImGui::SameLine(offset); ImGui::TableSetColumnIndex(0);
imgui.text(trim_text_if_needed(m_settings_ids.printer)); imgui.text_colored(col_1_color, col_1.c_str());
} ImGui::TableSetColumnIndex(1);
if (!m_settings_ids.print.empty()) { imgui.text_colored(col_2_color, col_2.c_str());
imgui.text(_u8L("Print settings") + ":"); };
ImGui::SameLine(offset);
imgui.text(trim_text_if_needed(m_settings_ids.print)); if (ImGui::BeginTable("Settings", 2)) {
} if (!m_settings_ids.printer.empty())
if (!m_settings_ids.filament.empty()) { add_strings_row_to_table(_u8L("Printer") + ":", ImGuiWrapper::COL_ORANGE_LIGHT,
for (unsigned char i : m_extruder_ids) { trim_text_if_needed(m_settings_ids.printer), ImGuiWrapper::to_ImVec4(ColorRGBA::WHITE()));
if (i < static_cast<unsigned char>(m_settings_ids.filament.size()) && !m_settings_ids.filament[i].empty()) { if (!m_settings_ids.print.empty())
std::string txt = _u8L("Filament"); add_strings_row_to_table(_u8L("Print settings") + ":", ImGuiWrapper::COL_ORANGE_LIGHT,
txt += (m_extruder_ids.size() == 1) ? ":" : " " + std::to_string(i + 1); trim_text_if_needed(m_settings_ids.print), ImGuiWrapper::to_ImVec4(ColorRGBA::WHITE()));
imgui.text(txt); if (!m_settings_ids.filament.empty()) {
ImGui::SameLine(offset); for (unsigned char i : m_extruder_ids) {
imgui.text(trim_text_if_needed(m_settings_ids.filament[i])); if (i < static_cast<unsigned char>(m_settings_ids.filament.size()) && !m_settings_ids.filament[i].empty()) {
std::string txt = _u8L("Filament");
txt += (m_extruder_ids.size() == 1) ? ":" : " " + std::to_string(i + 1);
add_strings_row_to_table(txt, ImGuiWrapper::COL_ORANGE_LIGHT,
trim_text_if_needed(m_settings_ids.filament[i]), ImGuiWrapper::to_ImVec4(ColorRGBA::WHITE()));
}
} }
} }
ImGui::EndTable();
} }
} }