From 05d714814fba80929b5e35660735e287ed5df832 Mon Sep 17 00:00:00 2001 From: "liz.li" Date: Fri, 3 Nov 2023 15:52:56 +0800 Subject: [PATCH] ENH: dailytips modification 1. modify closing behavior 2. dailytips can adjust self size according to the canvas size. And also adjust GodeViewer legend window size 3. fix a button text encoding bug 4. support vertical/horizontal layout(horizontal layout currently not used) jira: new Change-Id: I8e0b6e85c455d0608d7388fb441829c1991ad01f --- src/slic3r/GUI/DailyTips.cpp | 124 ++++++++++-------- src/slic3r/GUI/DailyTips.hpp | 11 +- src/slic3r/GUI/GCodeViewer.cpp | 8 +- src/slic3r/GUI/GCodeViewer.hpp | 2 + .../GUI/SlicingProgressNotification.cpp | 98 ++++++++------ .../GUI/SlicingProgressNotification.hpp | 3 +- 6 files changed, 144 insertions(+), 102 deletions(-) diff --git a/src/slic3r/GUI/DailyTips.cpp b/src/slic3r/GUI/DailyTips.cpp index 401fe3cd5..c2beb1597 100644 --- a/src/slic3r/GUI/DailyTips.cpp +++ b/src/slic3r/GUI/DailyTips.cpp @@ -19,7 +19,7 @@ struct DailyTipsData { class DailyTipsDataRenderer { public: - DailyTipsDataRenderer() = default; + DailyTipsDataRenderer(DailyTipsLayout layout); ~DailyTipsDataRenderer(); void update_data(const DailyTipsData& data); void render(const ImVec2& pos, const ImVec2& size) const; @@ -38,8 +38,14 @@ private: GLTexture* m_texture{ nullptr }; GLTexture* m_placeholder_texture{ nullptr }; bool m_is_dark{ false }; + DailyTipsLayout m_layout; }; +DailyTipsDataRenderer::DailyTipsDataRenderer(DailyTipsLayout layout) + : m_layout(layout) +{ +} + DailyTipsDataRenderer::~DailyTipsDataRenderer() { if (m_texture) delete m_texture; @@ -84,13 +90,23 @@ void DailyTipsDataRenderer::render(const ImVec2& pos, const ImVec2& size) const ImGuiWrapper& imgui = *wxGetApp().imgui(); ImGuiWindow* parent_window = ImGui::GetCurrentWindow(); int window_flags = parent_window->Flags; + window_flags &= ~ImGuiWindowFlags_NoScrollbar; + window_flags &= ~ImGuiWindowFlags_NoScrollWithMouse; std::string name = "##DailyTipsDataRenderer" + std::to_string(parent_window->ID); ImGui::SetNextWindowPos(pos); if (ImGui::BeginChild(name.c_str(), size, false, window_flags)) { - ImVec2 img_size = ImVec2(size.x, 9.0f / 16.0f * size.x); - render_img({0, 0}, img_size); - float img_text_gap = ImGui::CalcTextSize("A").y; - render_text({0, img_size.y + img_text_gap }, size); + if (m_layout == DailyTipsLayout::Vertical) { + ImVec2 img_size = ImVec2(size.x, 9.0f / 16.0f * size.x); + render_img({ 0, 0 }, img_size); + float img_text_gap = ImGui::CalcTextSize("A").y; + render_text({ 0, img_size.y + img_text_gap }, size); + } + if (m_layout == DailyTipsLayout::Horizontal) { + ImVec2 img_size = ImVec2(16.0f / 9.0f * size.y, size.y); + render_img({ 0, 0 }, img_size); + float img_text_gap = ImGui::CalcTextSize("A").y; + render_text({ img_size.x + img_text_gap, 0 }, { size.x - img_size.x - img_text_gap, size.y }); + } } ImGui::EndChild(); } @@ -129,7 +145,7 @@ void DailyTipsDataRenderer::render_text(const ImVec2& start_pos, const ImVec2& s content_lines = m_data.main_text.substr(end_pos + 1); } - ImGui::SetCursorPosY(start_pos.y); + ImGui::SetCursorPos(start_pos); imgui.text(title_line); bool is_zh = false; @@ -139,6 +155,7 @@ void DailyTipsDataRenderer::render_text(const ImVec2& start_pos, const ImVec2& s } if (!is_zh) { // problem in Chinese with spaces + ImGui::SetCursorPosX(start_pos.x); imgui.text_wrapped(content_lines, size.x); } else { @@ -148,6 +165,7 @@ void DailyTipsDataRenderer::render_text(const ImVec2& start_pos, const ImVec2& s wrapped_text->Wrap(size.x + ImGui::CalcTextSize("A").x * 5.0f); std::string wrapped_content_lines = wrapped_text->GetLabel().ToUTF8().data(); wrapped_text->Destroy(); + ImGui::SetCursorPosX(start_pos.x); imgui.text(wrapped_content_lines); } @@ -158,10 +176,10 @@ void DailyTipsDataRenderer::render_text(const ImVec2& start_pos, const ImVec2& s std::string first_part_text = tips_line.substr(0, tips_line.find(wiki_part_text)); ImVec2 wiki_part_size = ImGui::CalcTextSize(wiki_part_text.c_str()); ImVec2 first_part_size = ImGui::CalcTextSize(first_part_text.c_str()); - - ImVec2 link_start_pos = ImGui::GetCursorScreenPos(); //text + ImGui::SetCursorPosX(start_pos.x); + ImVec2 link_start_pos = ImGui::GetCursorScreenPos(); imgui.text(first_part_text); ImColor HyperColor = ImColor(31, 142, 234).Value; @@ -190,9 +208,19 @@ void DailyTipsDataRenderer::render_text(const ImVec2& start_pos, const ImVec2& s int DailyTipsPanel::uid = 0; -DailyTipsPanel::DailyTipsPanel(bool can_expand) - : DailyTipsPanel(ImVec2(0, 0), ImVec2(0, 0), can_expand) +DailyTipsPanel::DailyTipsPanel(bool can_expand, DailyTipsLayout layout) + : m_pos(ImVec2(0, 0)), + m_width(0), + m_height(0), + m_can_expand(can_expand), + m_layout(layout), + m_uid(DailyTipsPanel::uid++), + m_dailytips_renderer(std::make_unique(layout)) { + ImGuiWrapper& imgui = *wxGetApp().imgui(); + float scale = imgui.get_font_size() / 15.0f; + m_footer_height = 58.0f * scale; + m_is_expanded = wxGetApp().app_config->get("show_hints") == "true"; } void DailyTipsPanel::set_position(const ImVec2& pos) @@ -204,6 +232,7 @@ void DailyTipsPanel::set_size(const ImVec2& size) { m_width = size.x; m_height = size.y; + m_content_height = m_height - m_footer_height; } void DailyTipsPanel::set_can_expand(bool can_expand) @@ -216,26 +245,11 @@ ImVec2 DailyTipsPanel::get_size() return ImVec2(m_width, m_height); } -DailyTipsPanel::DailyTipsPanel(const ImVec2& pos, const ImVec2& size, bool can_expand) - : m_pos(pos), - m_width(size.x), - m_height(size.y), - m_can_expand(can_expand) -{ - m_dailytips_renderer = std::make_unique(); - m_is_expanded = wxGetApp().app_config->get("show_hints") == "true"; - m_uid = (DailyTipsPanel::uid++); -} - void DailyTipsPanel::render() { ImGuiWrapper& imgui = *wxGetApp().imgui(); float scale = imgui.get_font_size() / 15.0f; - m_header_height = m_can_expand ? 38.0f * scale : 0; - m_footer_height = 38.0f * scale; - m_content_height = m_height - m_header_height - m_footer_height; - if (!m_first_enter) { retrieve_data_from_hint_database(HintDataNavigation::Curr); m_first_enter = true; @@ -244,7 +258,7 @@ void DailyTipsPanel::render() push_styles(); if (m_can_expand) { if (m_is_expanded) { - m_height = m_header_height + m_content_height + m_footer_height; + m_height = m_content_height + m_footer_height; } else { m_height = m_footer_height; @@ -261,13 +275,11 @@ void DailyTipsPanel::render() if (ImGui::BeginChild((std::string("##DailyTipsPanel") + std::to_string(m_uid)).c_str(), ImVec2(m_width, m_height), false, window_flags)) { if (m_can_expand) { if (m_is_expanded) { - render_header(m_pos, { m_width, m_header_height }); - m_dailytips_renderer->render({ m_pos.x, m_pos.y + m_header_height }, { m_width, m_content_height }); + m_dailytips_renderer->render({ m_pos.x, m_pos.y }, { m_width, m_content_height }); render_controller_buttons({ m_pos.x, m_pos.y + m_height - m_footer_height }, { m_width, m_footer_height }); } else { render_controller_buttons({ m_pos.x, m_pos.y + m_height - m_footer_height }, { m_width, m_footer_height }); - } } else { @@ -330,22 +342,22 @@ void DailyTipsPanel::on_change_color_mode(bool is_dark) m_dailytips_renderer->on_change_color_mode(is_dark); } -void DailyTipsPanel::render_header(const ImVec2& pos, const ImVec2& size) -{ - ImGuiWrapper& imgui = *wxGetApp().imgui(); - ImGuiWindow* parent_window = ImGui::GetCurrentWindow(); - int window_flags = parent_window->Flags; - std::string name = "##DailyTipsPanelHeader" + std::to_string(parent_window->ID); - ImGui::SetNextWindowPos(pos); - if (ImGui::BeginChild(name.c_str(), size, false, window_flags)) { - ImVec2 text_pos = pos + ImVec2(0, (size.y - ImGui::CalcTextSize("A").y) / 2); - ImGui::SetCursorScreenPos(text_pos); - imgui.push_bold_font(); - imgui.text(_u8L("Daily Tips")); - imgui.pop_bold_font(); - } - ImGui::EndChild(); -} +//void DailyTipsPanel::render_header(const ImVec2& pos, const ImVec2& size) +//{ +// ImGuiWrapper& imgui = *wxGetApp().imgui(); +// ImGuiWindow* parent_window = ImGui::GetCurrentWindow(); +// int window_flags = parent_window->Flags; +// std::string name = "##DailyTipsPanelHeader" + std::to_string(parent_window->ID); +// ImGui::SetNextWindowPos(pos); +// if (ImGui::BeginChild(name.c_str(), size, false, window_flags)) { +// ImVec2 text_pos = pos + ImVec2(0, (size.y - ImGui::CalcTextSize("A").y) / 2); +// ImGui::SetCursorScreenPos(text_pos); +// imgui.push_bold_font(); +// imgui.text(_u8L("Daily Tips")); +// imgui.pop_bold_font(); +// } +// ImGui::EndChild(); +//} void DailyTipsPanel::render_controller_buttons(const ImVec2& pos, const ImVec2& size) { @@ -356,8 +368,8 @@ void DailyTipsPanel::render_controller_buttons(const ImVec2& pos, const ImVec2& std::string name = "##DailyTipsPanelControllers" + std::to_string(parent_window->ID); ImGui::SetNextWindowPos(pos); if (ImGui::BeginChild(name.c_str(), size, false, window_flags)) { - ImVec2 button_size = ImVec2(size.y, size.y); - float button_margin_x = 8.0f; + ImVec2 button_size = ImVec2(38.0f, 38.0f) * scale; + float button_margin_x = 8.0f * scale; std::wstring button_text; // collapse / expand @@ -371,7 +383,7 @@ void DailyTipsPanel::render_controller_buttons(const ImVec2& pos, const ImVec2& ImGui::PushStyleColor(ImGuiCol_Text, ImColor(144, 144, 144).Value); button_text = ImGui::CollapseArrowIcon; - imgui.button((_u8L("Collapse") + button_text).c_str()); + imgui.button((_L("Collapse") + button_text)); ImVec2 collapse_btn_size = ImGui::CalcTextSize((_u8L("Collapse")).c_str()); collapse_btn_size.x += button_size.x / 2.0f; if (ImGui::IsMouseHoveringRect(btn_pos, btn_pos + collapse_btn_size, true)) @@ -398,7 +410,7 @@ void DailyTipsPanel::render_controller_buttons(const ImVec2& pos, const ImVec2& // for bold font text, split text and icon-font button imgui.push_bold_font(); - imgui.button((_u8L("Daily Tips")).c_str()); + imgui.button((_L("Daily Tips"))); imgui.pop_bold_font(); ImVec2 expand_btn_size = ImGui::CalcTextSize((_u8L("Daily Tips")).c_str()); ImGui::SetCursorScreenPos(ImVec2(btn_pos.x + expand_btn_size.x + ImGui::CalcTextSize(" ").x, btn_pos.y)); @@ -445,7 +457,7 @@ void DailyTipsPanel::render_controller_buttons(const ImVec2& pos, const ImVec2& // prev button ImColor button_text_color = m_is_dark ? ImColor(228, 228, 228) : ImColor(38, 46, 48); - ImVec2 prev_button_pos = pos + size + ImVec2(-button_margin_x - button_size.x * 2, -size.y); + ImVec2 prev_button_pos = pos + size + ImVec2(-button_margin_x - button_size.x * 2, -size.y + (size.y - button_size.y) / 2); ImGui::SetCursorScreenPos(prev_button_pos); button_text = ImGui::PrevArrowBtnIcon; if (ImGui::IsMouseHoveringRect(prev_button_pos, prev_button_pos + button_size, true)) @@ -460,7 +472,7 @@ void DailyTipsPanel::render_controller_buttons(const ImVec2& pos, const ImVec2& // next button button_text_color = m_is_dark ? ImColor(228, 228, 228) : ImColor(38, 46, 48); - ImVec2 next_button_pos = pos + size + ImVec2(-button_size.x, -size.y); + ImVec2 next_button_pos = pos + size + ImVec2(-button_size.x, -size.y + (size.y - button_size.y) / 2); ImGui::SetCursorScreenPos(next_button_pos); button_text = ImGui::NextArrowBtnIcon; if (ImGui::IsMouseHoveringRect(next_button_pos, next_button_pos + button_size, true)) @@ -489,19 +501,25 @@ void DailyTipsPanel::push_styles() ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(1.0f, 1.0f)); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, 0.0f)); ImGui::PushStyleVar(ImGuiStyleVar_ItemInnerSpacing, ImVec2(0.0f, 0.0f)); + ImGui::PushStyleVar(ImGuiStyleVar_ScrollbarSize, 4.0f * scale); + ImGui::PushStyleColor(ImGuiCol_ScrollbarBg, m_is_dark ? ImGuiWrapper::COL_WINDOW_BG_DARK : ImGuiWrapper::COL_WINDOW_BG); + 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)); } void DailyTipsPanel::pop_styles() { ImGuiWrapper& imgui = *wxGetApp().imgui(); imgui.pop_common_window_style(); - ImGui::PopStyleVar(5); + ImGui::PopStyleVar(6); + ImGui::PopStyleColor(4); } DailyTipsWindow::DailyTipsWindow() { - m_panel = new DailyTipsPanel(false); + m_panel = new DailyTipsPanel(false, DailyTipsLayout::Vertical); } void DailyTipsWindow::open() diff --git a/src/slic3r/GUI/DailyTips.hpp b/src/slic3r/GUI/DailyTips.hpp index f48978f66..a791d857e 100644 --- a/src/slic3r/GUI/DailyTips.hpp +++ b/src/slic3r/GUI/DailyTips.hpp @@ -10,12 +10,16 @@ namespace Slic3r { namespace GUI { +enum class DailyTipsLayout{ + Horizontal, + Vertical +}; + class DailyTipsDataRenderer; class DailyTipsPanel { static int uid; public: - DailyTipsPanel(bool can_expand = true); - DailyTipsPanel(const ImVec2& pos, const ImVec2& size, bool can_expand = true); + DailyTipsPanel(bool can_expand = true, DailyTipsLayout layout = DailyTipsLayout::Vertical); void set_position(const ImVec2& pos); void set_size(const ImVec2& size); void set_can_expand(bool can_expand); @@ -28,7 +32,6 @@ public: void on_change_color_mode(bool is_dark); protected: - void render_header(const ImVec2& pos, const ImVec2& size); void render_controller_buttons(const ImVec2& pos, const ImVec2& size); void push_styles(); void pop_styles(); @@ -42,12 +45,12 @@ private: ImVec2 m_pos; float m_width; float m_height; - float m_header_height; float m_content_height; float m_footer_height; int m_uid; bool m_first_enter{ false }; bool m_is_dark{ false }; + DailyTipsLayout m_layout{ DailyTipsLayout::Vertical }; }; class DailyTipsWindow { diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index 3015dd13b..b9c73d553 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -1277,14 +1277,14 @@ void GCodeViewer::render(int canvas_width, int canvas_height, int right_margin) //BBS: always render shells in preview window render_shells(); + m_legend_height = 0.0f; if (m_roles.empty()) return; glsafe(::glEnable(GL_DEPTH_TEST)); render_toolpaths(); //render_shells(); - float legend_height = 0.0f; - render_legend(legend_height, canvas_width, canvas_height, right_margin); + render_legend(m_legend_height, canvas_width, canvas_height, right_margin); if (m_user_mode != wxGetApp().get_mode()) { update_by_mode(wxGetApp().get_mode()); @@ -1298,7 +1298,7 @@ void GCodeViewer::render(int canvas_width, int canvas_height, int right_margin) m_sequential_view.marker.set_world_position(m_sequential_view.current_position); m_sequential_view.marker.set_world_offset(m_sequential_view.current_offset); //BBS fixed buttom margin. m_moves_slider.pos_y - m_sequential_view.render(legend_height, canvas_width, canvas_height - bottom_margin * m_scale, right_margin * m_scale, m_view_type); + m_sequential_view.render(m_legend_height, canvas_width, canvas_height - bottom_margin * m_scale, right_margin * m_scale, m_view_type); } #if ENABLE_GCODE_VIEWER_STATISTICS render_statistics(); @@ -4420,7 +4420,7 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv 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::SetNextWindowBgAlpha(0.8f); - const float max_height = 0.75f * static_cast(cnv_size.get_height()); + const float max_height = 0.45f * static_cast(cnv_size.get_height()); const float child_height = 0.3333f * max_height; ImGui::SetNextWindowSizeConstraints({ 0.0f, 0.0f }, { -1.0f, max_height }); imgui.begin(std::string("Legend"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove); diff --git a/src/slic3r/GUI/GCodeViewer.hpp b/src/slic3r/GUI/GCodeViewer.hpp index d6dac0bec..7343f0c71 100644 --- a/src/slic3r/GUI/GCodeViewer.hpp +++ b/src/slic3r/GUI/GCodeViewer.hpp @@ -779,6 +779,7 @@ private: std::vector options_items; bool m_legend_enabled{ true }; + float m_legend_height; PrintEstimatedStatistics m_print_statistics; PrintEstimatedStatistics::ETimeMode m_time_estimate_mode{ PrintEstimatedStatistics::ETimeMode::Normal }; #if ENABLE_GCODE_VIEWER_STATISTICS @@ -882,6 +883,7 @@ public: bool is_legend_enabled() const { return m_legend_enabled; } void enable_legend(bool enable) { m_legend_enabled = enable; } + float get_legend_height() { return m_legend_height; } void export_toolpaths_to_obj(const char* filename) const; diff --git a/src/slic3r/GUI/SlicingProgressNotification.cpp b/src/slic3r/GUI/SlicingProgressNotification.cpp index e18c78ad4..ce4e1f099 100644 --- a/src/slic3r/GUI/SlicingProgressNotification.cpp +++ b/src/slic3r/GUI/SlicingProgressNotification.cpp @@ -239,22 +239,31 @@ void NotificationManager::SlicingProgressNotification::render(GLCanvas3D& canvas m_is_dark ? push_style_color(ImGuiCol_Border, { 62 / 255.f, 62 / 255.f, 69 / 255.f, 1.f }, true, m_current_fade_opacity) : push_style_color(ImGuiCol_Border, m_CurrentColor, true, m_current_fade_opacity); } else { + // for debug + //ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, m_WindowRadius / 4); + //m_is_dark ? push_style_color(ImGuiCol_Border, { 62 / 255.f, 62 / 255.f, 69 / 255.f, 1.f }, true, m_current_fade_opacity) : push_style_color(ImGuiCol_Border, m_CurrentColor, true, m_current_fade_opacity); + ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); push_style_color(ImGuiCol_Border, { 0, 0, 0, 0 }, true, m_current_fade_opacity); } - const ImVec2 progress_child_window_padding = ImVec2(25.f, 5.f) * scale; - const ImVec2 dailytips_child_window_padding = ImVec2(25.f, 2.f) * scale; - const ImVec2 bottom_padding = ImVec2(25.f, 20.f) * scale; - const float progress_panel_width = (m_window_width - 2 * progress_child_window_padding.x); - const float progress_panel_height = (78.0f * scale); - const float dailytips_panel_width = (m_window_width - 2 * dailytips_child_window_padding.x); - const float dailytips_panel_height = (395.0f * scale); - Size cnv_size = canvas.get_canvas_size(); + + //m_window_width = 600.f * scale; + //if (m_sp_state == SlicingProgressNotification::SlicingProgressState::SP_COMPLETED || m_sp_state == SlicingProgressNotification::SlicingProgressState::SP_CANCELLED) + // m_window_width = m_line_height * 25; + const ImVec2 progress_child_window_padding = ImVec2(15.f, 0.f) * scale; + const ImVec2 dailytips_child_window_padding = m_dailytips_panel->is_expanded() ? ImVec2(15.f, 10.f) * scale : ImVec2(15.f, 0.f) * scale; + const ImVec2 bottom_padding = ImVec2(0.f, 0.f) * scale; + const float progress_panel_width = (m_window_width - 2 * progress_child_window_padding.x); + const float progress_panel_height = (58.0f * scale); + const float dailytips_panel_width = (m_window_width - 2 * dailytips_child_window_padding.x); + const float gcodeviewer_height = wxGetApp().plater()->get_preview_canvas3D()->get_gcode_viewer().get_legend_height(); + const float dailytips_panel_height = std::min(380.0f * scale, std::max(90.0f, (cnv_size.get_height() - gcodeviewer_height - progress_panel_height - dailytips_child_window_padding.y - initial_y - m_line_height * 4))); + float right_gap = right_margin + (move_from_overlay ? overlay_width + m_line_height * 5 : 0); - ImVec2 window_pos((float)cnv_size.get_width() - right_gap - m_window_width, (float)cnv_size.get_height() - m_top_y); - imgui.set_next_window_pos(window_pos.x, window_pos.y, ImGuiCond_Always, 0.0f, 0.0f); + m_window_pos = ImVec2((float)cnv_size.get_width() - right_gap - m_window_width, (float)cnv_size.get_height() - m_top_y); + imgui.set_next_window_pos(m_window_pos.x, m_window_pos.y, ImGuiCond_Always, 0.0f, 0.0f); // dynamically resize window by progress state if (m_sp_state == SlicingProgressNotification::SlicingProgressState::SP_COMPLETED || m_sp_state == SlicingProgressNotification::SlicingProgressState::SP_CANCELLED) m_window_height = 64.0f * scale; @@ -282,12 +291,12 @@ void NotificationManager::SlicingProgressNotification::render(GLCanvas3D& canvas if (m_sp_state == SlicingProgressState::SP_CANCELLED || m_sp_state == SlicingProgressState::SP_COMPLETED) { ImVec2 button_size = ImVec2(38.f, 38.f) * scale; float button_right_margin_x = 3.0f * scale; - ImVec2 button_pos = window_pos + ImVec2(m_window_width - button_size.x - button_right_margin_x, (m_window_height - button_size.y) / 2.0f); + ImVec2 button_pos = m_window_pos + ImVec2(m_window_width - button_size.x - button_right_margin_x, (m_window_height - button_size.y) / 2.0f); float text_left_margin_x = 15.0f * scale; - ImVec2 text_pos = window_pos + ImVec2(text_left_margin_x, m_window_height / 2.0f - m_line_height * 1.2f); - ImVec2 view_dailytips_text_pos = window_pos + ImVec2(text_left_margin_x, m_window_height / 2.0f + m_line_height * 0.2f); + ImVec2 text_pos = m_window_pos + ImVec2(text_left_margin_x, m_window_height / 2.0f - m_line_height * 1.2f); + ImVec2 view_dailytips_text_pos = m_window_pos + ImVec2(text_left_margin_x, m_window_height / 2.0f + m_line_height * 0.2f); - bbl_render_left_sign(imgui, m_window_width, m_window_height, window_pos.x + m_window_width, window_pos.y); + bbl_render_left_sign(imgui, m_window_width, m_window_height, m_window_pos.x + m_window_width, m_window_pos.y); render_text(text_pos); render_close_button(button_pos, button_size); render_show_dailytips(view_dailytips_text_pos); @@ -320,11 +329,12 @@ void NotificationManager::SlicingProgressNotification::render(GLCanvas3D& canvas ImGui::GetCurrentWindow()->DrawList->AddLine(separator_min, separator_max, ImColor(238, 238, 238)); child_name = "##DailyTipsPanel" + std::to_string(parent_window->ID); - ImGui::SetNextWindowPos(ImGui::GetCursorScreenPos() + dailytips_child_window_padding); + ImVec2 dailytips_pos = ImGui::GetCursorScreenPos() + dailytips_child_window_padding; + ImVec2 dailytips_size = ImVec2(dailytips_panel_width, dailytips_panel_height); + m_dailytips_panel->set_position(dailytips_pos); + m_dailytips_panel->set_size(dailytips_size); + ImGui::SetNextWindowPos(dailytips_pos); if (ImGui::BeginChild(child_name.c_str(), ImVec2(dailytips_panel_width, dailytips_panel_height), false, child_window_flags)) { - ImVec2 child_window_pos = ImGui::GetWindowPos(); - ImVec2 dailytips_pos = child_window_pos; - ImVec2 dailytips_size = ImVec2(dailytips_panel_width, dailytips_panel_height); render_dailytips_panel(dailytips_pos, dailytips_size); } ImGui::EndChild(); @@ -356,7 +366,6 @@ void Slic3r::GUI::NotificationManager::SlicingProgressNotification::render_text( push_style_color(ImGuiCol_TextSelectedBg, ImVec4(0, .75f, .75f, 1.f), m_state == EState::FadingOut, m_current_fade_opacity); ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(.0f, .0f, .0f, .0f)); - ImVec2 icon_size = ImVec2(38.f, 38.f) * scale; ImGui::SetCursorScreenPos(pos); std::wstring icon_text; icon_text = ImGui::CompleteIcon; @@ -364,26 +373,37 @@ void Slic3r::GUI::NotificationManager::SlicingProgressNotification::render_text( ImGui::PopStyleColor(5); - // complete text - imgui.push_bold_font(); - ImGui::SetCursorScreenPos(ImVec2(pos.x + icon_size.x, pos.y)); - imgui.text(m_text1.substr(0, m_endlines[0]).c_str()); - imgui.pop_bold_font(); - - // before closing text - int64_t now = GLCanvas3D::timestamp_now(); - int64_t duration_time = now - m_before_complete_start; - if (duration_time > BEFORE_COMPLETE_DURATION) { - set_progress_state(SlicingProgressState::SP_COMPLETED); - return; + ImVec2 icon_size = ImVec2(38.f, 38.f) * scale; + if (ImGui::IsMouseHoveringRect(m_window_pos, m_window_pos + ImVec2(m_window_width, m_window_height), false)) { + // complete text + imgui.push_bold_font(); + ImGui::SetCursorScreenPos(ImVec2(pos.x + icon_size.x + ImGui::CalcTextSize(" ").x, pos.y + (icon_size.y - m_line_height) / 2)); + imgui.text(m_text1.substr(0, m_endlines[0]).c_str()); + imgui.pop_bold_font(); + + m_before_complete_start = GLCanvas3D::timestamp_now(); } - boost::format fmt(_u8L("Closing in %ds")); - fmt % (3 - duration_time / 1000); - ImGui::PushStyleColor(ImGuiCol_Text, ImColor(144, 144, 144).Value); - ImGui::SetCursorScreenPos(ImVec2(pos.x + icon_size.x, pos.y + m_line_height + m_line_height / 2)); - imgui.text(fmt.str()); - ImGui::PopStyleColor(); + else { + // complete text + imgui.push_bold_font(); + ImGui::SetCursorScreenPos(ImVec2(pos.x + icon_size.x + ImGui::CalcTextSize(" ").x, pos.y)); + imgui.text(m_text1.substr(0, m_endlines[0]).c_str()); + imgui.pop_bold_font(); + // timer to close + int64_t now = GLCanvas3D::timestamp_now(); + int64_t duration_time = now - m_before_complete_start; + if (duration_time > BEFORE_COMPLETE_DURATION) { + set_progress_state(SlicingProgressState::SP_COMPLETED); + return; + } + boost::format fmt(_u8L("Closing in %ds")); + fmt % (3 - duration_time / 1000); + ImGui::PushStyleColor(ImGuiCol_Text, ImColor(144, 144, 144).Value); + ImGui::SetCursorScreenPos(ImVec2(pos.x + icon_size.x + ImGui::CalcTextSize(" ").x, pos.y + m_line_height + m_line_height / 2)); + imgui.text(fmt.str()); + ImGui::PopStyleColor(); + } } else { //one line text @@ -424,8 +444,6 @@ void NotificationManager::SlicingProgressNotification::render_dailytips_panel(co m_dailytips_panel->set_can_expand(false); else m_dailytips_panel->set_can_expand(true); - m_dailytips_panel->set_position(pos); - m_dailytips_panel->set_size(size); m_dailytips_panel->render(); } @@ -444,7 +462,7 @@ void NotificationManager::SlicingProgressNotification::render_show_dailytips(con ImGui::SetCursorScreenPos(pos); std::wstring button_text; button_text = ImGui::OpenArrowIcon; - imgui.button((_u8L("View all Daily tips") + " " + button_text).c_str()); + imgui.button(_L("View all Daily tips") + " " + button_text); //click behavior if (ImGui::IsMouseHoveringRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), true)) { diff --git a/src/slic3r/GUI/SlicingProgressNotification.hpp b/src/slic3r/GUI/SlicingProgressNotification.hpp index 8d6916baf..196cb65d1 100644 --- a/src/slic3r/GUI/SlicingProgressNotification.hpp +++ b/src/slic3r/GUI/SlicingProgressNotification.hpp @@ -23,7 +23,7 @@ public: SlicingProgressNotification(const NotificationData& n, NotificationIDProvider& id_provider, wxEvtHandler* evt_handler, std::function callback) : PopNotification(n, id_provider, evt_handler) , m_cancel_callback(callback) - , m_dailytips_panel(new DailyTipsPanel(true)) + , m_dailytips_panel(new DailyTipsPanel(true, DailyTipsLayout::Vertical)) { set_progress_state(SlicingProgressState::SP_NO_SLICING); } @@ -65,6 +65,7 @@ protected: int get_duration() override; protected: + ImVec2 m_window_pos; float m_percentage{ 0.0f }; int64_t m_before_complete_start; // if returns false, process was already canceled