ENH: color arrangement ui

jira: STUDIO-8124
Change-Id: Ibcde0e002ffd652b350bd05a9453ce7aaefd7bca
This commit is contained in:
Mack 2024-09-25 21:56:40 +08:00 committed by lane.wei
parent c1e4be1652
commit 65e3829f92
3 changed files with 46 additions and 20 deletions

View File

@ -4624,42 +4624,52 @@ void GCodeViewer::render_legend_color_arr_recommen(float window_padding)
Plater *plater = wxGetApp().plater();
wxCommandEvent evt(EVT_OPEN_FILAMENT_MAP_SETTINGS_DIALOG);
evt.SetEventObject(plater);
evt.SetInt(0);
wxPostEvent(plater, evt);
}
}
};
////BBS Color Arrangement Recommendation
ImGui::Dummy({ window_padding, window_padding });
ImGui::Dummy({ window_padding, window_padding });
ImGui::SameLine();
imgui.title(_u8L("Color Arrangement Recommendation"));
auto config = wxGetApp().plater()->get_partplate_list().get_current_fff_print().config();
auto filament_map_mode = config.filament_map_mode.value;
auto is_auto = filament_map_mode == FilamentMapMode::fmmAuto;
// 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 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;
float AMS_container_height = ams_item_height + line_height * (filament_map_mode == FilamentMapMode::fmmAuto ? 3 : 4);
float AMS_container_height = ams_item_height + line_height * (is_auto ? 6 : 7);
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.f, 1.f, 1.f, 1.0f));
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(.15f, .18f, .19f, 1.0f));
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(window_padding * 3, 0));
ImGui::BeginChild("#AMS", ImVec2(0, AMS_container_height), false, ImGuiWindowFlags_AlwaysUseWindowPadding);
ImGui::Dummy({window_padding, window_padding});
ImGui::BeginChild("#AMS", ImVec2(0, AMS_container_height), true, ImGuiWindowFlags_AlwaysUseWindowPadding);
{
float available_width = ImGui::GetContentRegionAvail().x;
float available_height = ImGui::GetContentRegionAvail().y;
float half_width = available_width * 0.5f;
float half_width = available_width * 0.49f;
float spacing = 18.0f * m_scale;
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.00f, 0.00f, 0.00f, 0.3f));
ImGui::Dummy({window_padding, window_padding});
ImGui::PushStyleColor(ImGuiCol_Separator, ImVec4(.8f, .8f, .8f, 1.0f));
if (is_auto)
imgui.title(_u8L("Color Arrangement Recommendation"));
else
imgui.title(_u8L("Color Arrangement"));
ImGui::PopStyleColor();
ImGui::Dummy({window_padding, window_padding});
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.00f, 0.00f, 0.00f, 0.1f));
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(window_padding * 2, window_padding));
ImDrawList *child_begin_draw_list = ImGui::GetWindowDrawList();
ImVec2 cursor_pos = ImGui::GetCursorScreenPos();
child_begin_draw_list->AddRectFilled(cursor_pos, ImVec2(cursor_pos.x + half_width, cursor_pos.y + line_height), IM_COL32(0, 0, 0, 64));
child_begin_draw_list->AddRectFilled(cursor_pos, ImVec2(cursor_pos.x + half_width, cursor_pos.y + line_height), IM_COL32(0, 0, 0, 20));
ImGui::BeginChild("#LeftAMS", ImVec2(half_width, ams_item_height), false, ImGuiWindowFlags_AlwaysUseWindowPadding);
{
imgui.bold_text(_u8L("Left"));
imgui.text(_u8L("Left"));
ImGui::Dummy({window_padding, window_padding});
int index = 1;
for (const auto &extruder_filament : m_left_extruder_filament) {
@ -4671,10 +4681,10 @@ void GCodeViewer::render_legend_color_arr_recommen(float window_padding)
}
ImGui::SameLine();
cursor_pos = ImGui::GetCursorScreenPos();
child_begin_draw_list->AddRectFilled(cursor_pos, ImVec2(cursor_pos.x + half_width, cursor_pos.y + line_height), IM_COL32(0, 0, 0, 64));
child_begin_draw_list->AddRectFilled(cursor_pos, ImVec2(cursor_pos.x + half_width, cursor_pos.y + line_height), IM_COL32(0, 0, 0, 20));
ImGui::BeginChild("#RightAMS", ImVec2(half_width, ams_item_height), false, ImGuiWindowFlags_AlwaysUseWindowPadding);
{
imgui.bold_text(_u8L("Right"));
imgui.text(_u8L("Right"));
ImGui::Dummy({window_padding, window_padding});
int index = 1;
for (const auto &extruder_filament : m_right_extruder_filament) {
@ -4686,6 +4696,7 @@ void GCodeViewer::render_legend_color_arr_recommen(float window_padding)
}
ImGui::PopStyleColor(1);
ImGui::PopStyleVar(1);
ImGui::Dummy({window_padding, window_padding});
link_text(_u8L("Customize Arrangement"));
auto stats_by_extruder = wxGetApp().plater()->get_partplate_list().get_current_fff_print().statistics_by_extruder();
@ -4728,6 +4739,7 @@ void GCodeViewer::render_legend_color_arr_recommen(float window_padding)
ImGui::EndChild();
}
ImGui::PopStyleColor(2);
ImGui::PopStyleVar(1);
}
@ -4750,6 +4762,8 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
ImGui::PushStyleColor(ImGuiCol_ScrollbarGrab, ImVec4(0.42f, 0.42f, 0.42f, 1.00f));
ImGui::PushStyleColor(ImGuiCol_ScrollbarGrabHovered, ImVec4(0.93f, 0.93f, 0.93f, 1.00f));
ImGui::PushStyleColor(ImGuiCol_ScrollbarGrabActive, ImVec4(0.93f, 0.93f, 0.93f, 1.00f));
//ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.f, 1.f, 1.f, 1.0f));
ImGui::PushStyleColor(ImGuiCol_Border, {1, 0, 0, 0});
ImGui::SetNextWindowBgAlpha(0.8f);
const float max_height = 0.75f * static_cast<float>(cnv_size.get_height());
const float child_height = 0.3333f * max_height;
@ -5053,7 +5067,7 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
if (m_fold) {
legend_height = ImGui::GetStyle().WindowPadding.y + ImGui::GetFrameHeight() + window_padding * 2.5;
imgui.end();
ImGui::PopStyleColor(6);
ImGui::PopStyleColor(7);
ImGui::PopStyleVar(2);
return;
}
@ -6045,9 +6059,8 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
render_legend_color_arr_recommen(window_padding);
legend_height = ImGui::GetCurrentWindow()->Size.y;
ImGui::Dummy({ window_padding, window_padding});
imgui.end();
ImGui::PopStyleColor(6);
ImGui::PopStyleColor(7);
ImGui::PopStyleVar(2);
}

View File

@ -2849,6 +2849,7 @@ 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);
@ -2867,8 +2868,13 @@ void ImGuiWrapper::filament_group(const std::string &filament_type, const char *
float gray = 0.299 * rgb[0] + 0.587 * rgb[1] + 0.114 * rgb[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());
ImGui::SetCursorPos({current_cursor.x + (img_size.x - text_size.x) * 0.5f, current_cursor.y + img_size.y});
float text_width_max = four_word_width;
if (filament_type.size() < 4) text_width_max = text_size.x;
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);
this->text(filament_type);
ImGui::PopTextWrapPos();
ImGui::EndGroup();
}
//ImGui::PopStyleVar(1);

View File

@ -14433,8 +14433,14 @@ void Plater::open_platesettings_dialog(wxCommandEvent& evt) {
void Plater::open_filament_map_setting_dialog(wxCommandEvent &evt)
{
PartPlate* curr_plate = p->partplate_list.get_curr_plate();
FilamentMapDialog filament_dlg(this, config(), curr_plate->get_filament_maps(), curr_plate->get_extruders(true),
curr_plate->get_filament_map_mode() == FilamentMapMode::fmmAuto, curr_plate->has_auto_filament_map_reslut());
int is_auto = evt.GetInt();
FilamentMapDialog filament_dlg(this,
config(),
curr_plate->get_filament_maps(),
curr_plate->get_extruders(true),
is_auto==1,
curr_plate->has_auto_filament_map_reslut()
);
if (filament_dlg.ShowModal() == wxID_OK) {
std::vector<int> new_filament_maps = filament_dlg.get_filament_maps();
std::vector<int> old_filament_maps = curr_plate->get_filament_maps();
@ -14631,8 +14637,9 @@ int Plater::select_plate_by_hover_id(int hover_id, bool right_click, bool isModi
else if ((action == PartPlate::PLATE_FILAMENT_MAP_ID) && (!right_click)) {
ret = select_plate(plate_index);
if (!ret) {
PartPlate * curr_plate = p->partplate_list.get_curr_plate();
wxCommandEvent evt(EVT_OPEN_FILAMENT_MAP_SETTINGS_DIALOG);
evt.SetInt(plate_index);
evt.SetInt(curr_plate->get_filament_map_mode()==FilamentMapMode::fmmAuto);
evt.SetEventObject(this);
wxPostEvent(this, evt);
} else {