ENH: add a duration before slicing complete for showing dailytips

jira: new

Change-Id: I3c30eb45fa99f6c973bac6621f5ddf1de3eb2bfe
This commit is contained in:
liz.li 2023-10-27 17:05:48 +08:00 committed by Lane.Wei
parent ea237758fa
commit 5477495d49
5 changed files with 96 additions and 14 deletions

View File

@ -0,0 +1,10 @@
<svg width="25" height="25" viewBox="0 0 25 25" fill="none" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_14987_19175)">
<path d="M12.5 2.34375C15.1936 2.34375 17.7769 3.41378 19.6816 5.31845C21.5862 7.22311 22.6562 9.80639 22.6562 12.5C22.6562 15.1936 21.5862 17.7769 19.6816 19.6816C17.7769 21.5862 15.1936 22.6562 12.5 22.6562C9.80639 22.6562 7.22311 21.5862 5.31845 19.6816C3.41378 17.7769 2.34375 15.1936 2.34375 12.5C2.34375 9.80639 3.41378 7.22311 5.31845 5.31845C7.22311 3.41378 9.80639 2.34375 12.5 2.34375ZM12.5 25C15.8152 25 18.9946 23.683 21.3388 21.3388C23.683 18.9946 25 15.8152 25 12.5C25 9.18479 23.683 6.00537 21.3388 3.66117C18.9946 1.31696 15.8152 0 12.5 0C9.18479 0 6.00537 1.31696 3.66117 3.66117C1.31696 6.00537 0 9.18479 0 12.5C0 15.8152 1.31696 18.9946 3.66117 21.3388C6.00537 23.683 9.18479 25 12.5 25ZM18.0176 10.2051C18.4766 9.74609 18.4766 9.00391 18.0176 8.5498C17.5586 8.0957 16.8164 8.09082 16.3623 8.5498L10.9424 13.9697L8.64746 11.6748C8.18848 11.2158 7.44629 11.2158 6.99219 11.6748C6.53809 12.1338 6.5332 12.876 6.99219 13.3301L10.1172 16.4551C10.5762 16.9141 11.3184 16.9141 11.7725 16.4551L18.0176 10.2051Z" fill="#00AE42"/>
</g>
<defs>
<clipPath id="clip0_14987_19175">
<rect width="25" height="25" fill="white"/>
</clipPath>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -206,6 +206,7 @@ namespace ImGui
const wchar_t OpenArrowIcon = 0x0840;
const wchar_t CollapseArrowIcon = 0x0841;
const wchar_t ExpandArrowIcon = 0x0842;
const wchar_t CompleteIcon = 0x0843;
// void MyFunction(const char* name, const MyMatrix44& v);
}

View File

@ -127,6 +127,7 @@ static const std::map<const wchar_t, std::string> font_icons_large = {
{ImGui::PrevArrowHoverBtnIcon, "notification_arrow_left_hovered" },
{ImGui::NextArrowBtnIcon, "notification_arrow_right" },
{ImGui::NextArrowHoverBtnIcon, "notification_arrow_right_hovered" },
{ImGui::CompleteIcon, "notification_slicing_complete" },
};
static const std::map<const wchar_t, std::string> font_icons_extra_large = {

View File

@ -17,6 +17,9 @@ namespace {
}
}
static constexpr int BEFORE_COMPLETE_DURATION = 3000; //ms
static constexpr int REFRESH_TIMEOUT = 100; //ms
void NotificationManager::SlicingProgressNotification::init()
{
if (m_sp_state == SlicingProgressState::SP_PROGRESS) {
@ -48,8 +51,14 @@ bool NotificationManager::SlicingProgressNotification::set_progress_state(float
{
if (percent < 0.f)
return true;//set_progress_state(SlicingProgressState::SP_CANCELLED);
else if (percent >= 1.f)
else if (percent >= 1.f) {
if (m_dailytips_panel->is_expanded()) {
m_before_complete_start = GLCanvas3D::timestamp_now();
return set_progress_state(SlicingProgressState::SP_BEFORE_COMPLETED);
}
else
return set_progress_state(SlicingProgressState::SP_COMPLETED);
}
else
return set_progress_state(SlicingProgressState::SP_PROGRESS, percent);
}
@ -90,9 +99,17 @@ bool NotificationManager::SlicingProgressNotification::set_progress_state(Notifi
set_export_possible(false);
m_sp_state = state;
return true;
case Slic3r::GUI::NotificationManager::SlicingProgressNotification::SlicingProgressState::SP_COMPLETED:
case Slic3r::GUI::NotificationManager::SlicingProgressNotification::SlicingProgressState::SP_BEFORE_COMPLETED:
if (m_sp_state != SlicingProgressState::SP_BEGAN && m_sp_state != SlicingProgressState::SP_PROGRESS)
return false;
m_has_print_info = false;
// m_export_possible is important only for SP_PROGRESS state, thus we can reset it here
set_export_possible(false);
m_sp_state = state;
return true;
case Slic3r::GUI::NotificationManager::SlicingProgressNotification::SlicingProgressState::SP_COMPLETED:
if (m_sp_state != SlicingProgressState::SP_BEGAN && m_sp_state != SlicingProgressState::SP_PROGRESS && m_sp_state != SlicingProgressState::SP_BEFORE_COMPLETED)
return false;
set_percentage(1);
m_has_print_info = false;
// m_export_possible is important only for SP_PROGRESS state, thus we can reset it here
@ -126,6 +143,13 @@ void NotificationManager::SlicingProgressNotification::set_status_text(const std
m_state = EState::Shown;
}
break;
case Slic3r::GUI::NotificationManager::SlicingProgressNotification::SlicingProgressState::SP_BEFORE_COMPLETED:
{
NotificationData data{ NotificationType::SlicingProgress, NotificationLevel::ProgressBarNotificationLevel, 0, _u8L("Slice ok.") };
update(data);
m_state = EState::Shown;
}
break;
case Slic3r::GUI::NotificationManager::SlicingProgressNotification::SlicingProgressState::SP_COMPLETED:
{
NotificationData data{ NotificationType::SlicingProgress, NotificationLevel::ProgressBarNotificationLevel, 0, _u8L("Slice ok.") };
@ -177,6 +201,9 @@ int NotificationManager::SlicingProgressNotification::get_duration()
bool NotificationManager::SlicingProgressNotification::update_state(bool paused, const int64_t delta)
{
bool ret = PopNotification::update_state(paused, delta);
if (m_sp_state == SlicingProgressState::SP_BEFORE_COMPLETED || m_sp_state == SlicingProgressState::SP_COMPLETED)
ret = true;
// sets Estate to hidden
if (get_state() == PopNotification::EState::ClosePending || get_state() == PopNotification::EState::Finished)
set_progress_state(SlicingProgressState::SP_NO_SLICING);
@ -259,7 +286,7 @@ void NotificationManager::SlicingProgressNotification::render(GLCanvas3D& canvas
render_show_dailytips(view_dailytips_text_pos);
}
if (m_sp_state == SlicingProgressState::SP_PROGRESS) {
if (m_sp_state == SlicingProgressState::SP_PROGRESS || m_sp_state == SlicingProgressState::SP_BEFORE_COMPLETED) {
std::string child_name = "##SlicingProgressPanel" + std::to_string(parent_window->ID);
ImGui::SetNextWindowPos(parent_window->Pos + progress_child_window_padding);
@ -273,9 +300,11 @@ void NotificationManager::SlicingProgressNotification::render(GLCanvas3D& canvas
ImVec2 text_pos = ImVec2(progress_bar_pos.x, progress_bar_pos.y - m_line_height * 1.2f);
render_text(text_pos);
if (m_sp_state == SlicingProgressState::SP_PROGRESS) {
render_bar(progress_bar_pos, progress_bar_size);
render_cancel_button(button_pos, button_size);
}
}
ImGui::EndChild();
// Separator Line
@ -312,10 +341,49 @@ void Slic3r::GUI::NotificationManager::SlicingProgressNotification::render_text(
{
ImGuiWrapper& imgui = *wxGetApp().imgui();
if (m_sp_state == SlicingProgressState::SP_BEFORE_COMPLETED) {
// complete icon
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(.0f, .0f, .0f, .0f));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(.0f, .0f, .0f, .0f));
push_style_color(ImGuiCol_Text, ImVec4(1.f, 1.f, 1.f, 1.f), m_state == EState::FadingOut, m_current_fade_opacity);
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) * m_scale;
ImGui::SetCursorScreenPos(pos);
std::wstring icon_text;
icon_text = ImGui::CompleteIcon;
imgui.button(icon_text.c_str());
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;
}
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 {
//one line text
ImGui::SetCursorScreenPos(pos);
imgui.text(m_text1.substr(0, m_endlines[0]).c_str());
}
}
void Slic3r::GUI::NotificationManager::SlicingProgressNotification::render_bar(const ImVec2& pos, const ImVec2& size)
{

View File

@ -17,6 +17,7 @@ public:
SP_BEGAN, // still hidden but allows to go to SP_PROGRESS state. This prevents showing progress after slicing was canceled.
SP_PROGRESS, // never fades outs, no close button, has cancel button
SP_CANCELLED, // fades after 10 seconds, simple message
SP_BEFORE_COMPLETED, // to keep displaying DailyTips for 3 seconds
SP_COMPLETED // Has export hyperlink and print info, fades after 20 sec if sidebar is shown, otherwise no fade out
};
SlicingProgressNotification(const NotificationData& n, NotificationIDProvider& id_provider, wxEvtHandler* evt_handler, std::function<bool()> callback)
@ -64,6 +65,7 @@ protected:
protected:
float m_percentage{ 0.0f };
int64_t m_before_complete_start;
// if returns false, process was already canceled
std::function<bool()> m_cancel_callback;
SlicingProgressState m_sp_state{ SlicingProgressState::SP_PROGRESS };