FIX: support filament display in group result
1. Add "Sup." prefix for support filament 2. Align the filament group elems jira:STUDIO-10263 Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: Idd6d11d14cd378142dff03596eea5efb47dde79f
This commit is contained in:
parent
e7454fa47d
commit
038df3180a
|
@ -1042,11 +1042,12 @@ void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print& pr
|
|||
std::vector<int> filament_maps = print.get_filament_maps();
|
||||
std::vector<std::string> color_opt = print.config().option<ConfigOptionStrings>("filament_colour")->values;
|
||||
std::vector<std::string> type_opt = print.config().option<ConfigOptionStrings>("filament_type")->values;
|
||||
std::vector<unsigned char> support_filament_opt = print.config().option<ConfigOptionBools>("filament_is_support")->values;
|
||||
for (auto extruder_id : m_extruder_ids) {
|
||||
if (filament_maps[extruder_id] == 1) {
|
||||
m_left_extruder_filament.push_back({type_opt[extruder_id], color_opt[extruder_id], extruder_id});
|
||||
m_left_extruder_filament.push_back({type_opt[extruder_id], color_opt[extruder_id], extruder_id, (bool)(support_filament_opt[extruder_id])});
|
||||
} else {
|
||||
m_right_extruder_filament.push_back({type_opt[extruder_id], color_opt[extruder_id], extruder_id});
|
||||
m_right_extruder_filament.push_back({type_opt[extruder_id], color_opt[extruder_id], extruder_id, (bool)(support_filament_opt[extruder_id])});
|
||||
}
|
||||
}
|
||||
//BBS: add mutex for protection of gcode result
|
||||
|
@ -4705,11 +4706,38 @@ void GCodeViewer::render_legend_color_arr_recommen(float window_padding)
|
|||
bool less_to_single_ext = delta_weight_to_single_ext > EPSILON || delta_change_to_single_ext > 0;
|
||||
bool more_to_best = delta_weight_to_best > EPSILON || delta_change_to_best > 0;
|
||||
|
||||
auto get_filament_display_type = [](const ExtruderFilament& filament) {
|
||||
if (filament.is_support_filament && (filament.type == "PLA" || filament.type == "PA" || filament.type == "ABS"))
|
||||
return "Sup." + filament.type;
|
||||
return filament.type;
|
||||
};
|
||||
|
||||
|
||||
// BBS AMS containers
|
||||
float line_height = ImGui::GetFrameHeight();
|
||||
int AMS_filament_max_num = std::max(m_left_extruder_filament.size(), m_right_extruder_filament.size());
|
||||
float ams_item_height = 0;
|
||||
float filament_group_item_align_width = 0;
|
||||
{
|
||||
float three_words_width = imgui.calc_text_size("ABC").x;
|
||||
float ams_item_height = std::ceil(AMS_filament_max_num / 4.0f) * (three_words_width * 1.6f + line_height) + line_height * 2;
|
||||
const int line_capacity = 4;
|
||||
|
||||
for (const auto& extruder_filaments : {m_left_extruder_filament,m_right_extruder_filament })
|
||||
{
|
||||
float container_height = 0.f;
|
||||
for (size_t idx = 0; idx < extruder_filaments.size(); idx += line_capacity) {
|
||||
float text_line_height = 0;
|
||||
for (int j = idx; j < extruder_filaments.size() && j < idx + line_capacity; ++j) {
|
||||
auto text_info = imgui.calculate_filament_group_text_size(get_filament_display_type(extruder_filaments[j]));
|
||||
auto text_size = std::get<0>(text_info);
|
||||
filament_group_item_align_width = max(filament_group_item_align_width, text_size.x);
|
||||
text_line_height = max(text_line_height, text_size.y);
|
||||
}
|
||||
container_height += (three_words_width * 1.5f + text_line_height );
|
||||
}
|
||||
container_height += 2 * line_height;
|
||||
ams_item_height = std::max(ams_item_height, container_height);
|
||||
}
|
||||
}
|
||||
|
||||
int tips_count = 8;
|
||||
if (more_to_best)
|
||||
|
@ -4754,7 +4782,7 @@ void GCodeViewer::render_legend_color_arr_recommen(float window_padding)
|
|||
ImGui::Dummy({window_padding, window_padding});
|
||||
int index = 1;
|
||||
for (const auto &extruder_filament : m_left_extruder_filament) {
|
||||
imgui.filament_group(extruder_filament.type, extruder_filament.hex_color.c_str(), extruder_filament.filament_id);
|
||||
imgui.filament_group(get_filament_display_type(extruder_filament), extruder_filament.hex_color.c_str(), extruder_filament.filament_id, filament_group_item_align_width);
|
||||
if (index % 4 != 0) { ImGui::SameLine(0, spacing); }
|
||||
index++;
|
||||
}
|
||||
|
@ -4769,7 +4797,7 @@ void GCodeViewer::render_legend_color_arr_recommen(float window_padding)
|
|||
ImGui::Dummy({window_padding, window_padding});
|
||||
int index = 1;
|
||||
for (const auto &extruder_filament : m_right_extruder_filament) {
|
||||
imgui.filament_group(extruder_filament.type, extruder_filament.hex_color.c_str(), extruder_filament.filament_id);
|
||||
imgui.filament_group(get_filament_display_type(extruder_filament), extruder_filament.hex_color.c_str(), extruder_filament.filament_id, filament_group_item_align_width);
|
||||
if (index % 4 != 0) { ImGui::SameLine(0, spacing); }
|
||||
index++;
|
||||
}
|
||||
|
|
|
@ -715,6 +715,7 @@ public:
|
|||
std::string type;
|
||||
std::string hex_color;
|
||||
unsigned char filament_id;
|
||||
bool is_support_filament;
|
||||
};
|
||||
|
||||
enum class EViewType : unsigned char
|
||||
|
|
|
@ -2899,7 +2899,25 @@ void ImGuiWrapper::clipboard_set(void* /* user_data */, const char* text)
|
|||
}
|
||||
}
|
||||
|
||||
void ImGuiWrapper::filament_group(const std::string &filament_type, const char *hex_color, unsigned char filament_id)
|
||||
std::tuple<ImVec2, bool> ImGuiWrapper::calculate_filament_group_text_size(const std::string& filament_type)
|
||||
{
|
||||
ImVec2 text_size = ImGui::CalcTextSize(filament_type.c_str());
|
||||
float four_word_width = ImGui::CalcTextSize("ABCD").x;
|
||||
|
||||
float wrap_width = four_word_width;
|
||||
float line_height = ImGui::GetTextLineHeight();
|
||||
|
||||
bool is_multiline = text_size.x > wrap_width;
|
||||
int line_count = std::ceil(text_size.x / wrap_width);
|
||||
float text_height = line_count * line_height;
|
||||
|
||||
float final_width = is_multiline ? wrap_width : text_size.x;
|
||||
float final_height = line_count * line_height;
|
||||
|
||||
return { { final_width,final_height },is_multiline };
|
||||
}
|
||||
|
||||
void ImGuiWrapper::filament_group(const std::string& filament_type, const char* hex_color, unsigned char filament_id, float align_width)
|
||||
{
|
||||
//ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
|
||||
std::string id = std::to_string(static_cast<unsigned int> (filament_id + 1));
|
||||
|
@ -2907,7 +2925,6 @@ void ImGuiWrapper::filament_group(const std::string &filament_type, const char *
|
|||
static ImTextureID transparent;
|
||||
ImVec2 text_size = ImGui::CalcTextSize(filament_type.c_str());
|
||||
// BBS image sizing based on text width (DPI scaling)
|
||||
float four_word_width = ImGui::CalcTextSize("ABCD").x;
|
||||
float img_width = ImGui::CalcTextSize("ABC").x;
|
||||
ImVec2 img_size = { img_width, img_width * 1.5f };
|
||||
ImVec2 id_text_size = this->calc_text_size(id);
|
||||
|
@ -2931,13 +2948,29 @@ void ImGuiWrapper::filament_group(const std::string &filament_type, const char *
|
|||
float gray = 0.299 * rgba[0] + 0.587 * rgba[1] + 0.114 * rgba[2];
|
||||
ImVec4 text_color = gray < 80 ? ImVec4(1.0f, 1.0f, 1.0f, 1.0f) : ImVec4(0, 0, 0, 1.0f);
|
||||
this->text_colored(text_color, id.c_str());
|
||||
float text_width_max = four_word_width;
|
||||
if (filament_type.size() < 4) text_width_max = text_size.x;
|
||||
|
||||
auto wrapped_text_info = calculate_filament_group_text_size(filament_type);
|
||||
ImVec2 wrapped_text_size = std::get<0>(wrapped_text_info);
|
||||
bool is_multiline = std::get<1>(wrapped_text_info);
|
||||
|
||||
float text_y_offset = 4.f;
|
||||
float text_x_offset = is_multiline ? (img_size.x - wrapped_text_size.x) * 0.5f + 2.f : (img_size.x - wrapped_text_size.x) * 0.5f + 2.f;
|
||||
|
||||
auto cursor_x_before_text = ImGui::GetCursorPosX();
|
||||
current_cursor = ImGui::GetCursorPos();
|
||||
ImGui::SetCursorPos({current_cursor.x + (img_size.x - text_width_max) * 0.5f + 2, current_cursor.y + 4});
|
||||
ImGui::PushTextWrapPos(ImGui::GetCursorPosX() + four_word_width);
|
||||
ImGui::SetCursorPos({
|
||||
current_cursor.x + text_x_offset,
|
||||
current_cursor.y + text_y_offset
|
||||
});
|
||||
|
||||
if (is_multiline) {
|
||||
ImGui::PushTextWrapPos(ImGui::GetCursorPosX() + wrapped_text_size.x);
|
||||
}
|
||||
this->text(filament_type);
|
||||
if (is_multiline) {
|
||||
ImGui::PopTextWrapPos();
|
||||
}
|
||||
ImGui::Dummy(ImVec2(align_width, 0));
|
||||
ImGui::EndGroup();
|
||||
}
|
||||
//ImGui::PopStyleVar(1);
|
||||
|
|
|
@ -153,7 +153,10 @@ public:
|
|||
void text_wrapped(const wxString &label, float wrap_width);
|
||||
void tooltip(const char *label, float wrap_width);
|
||||
void tooltip(const wxString &label, float wrap_width);
|
||||
void filament_group(const std::string &filament_type, const char *hex_color, unsigned char filament_id);
|
||||
void filament_group(const std::string &filament_type, const char *hex_color, unsigned char filament_id, float align_width);
|
||||
|
||||
// text size and is_multi_line
|
||||
std::tuple<ImVec2,bool> calculate_filament_group_text_size(const std::string& filament_type);
|
||||
void sub_title(const std::string &label);
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue