Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Kocik <kocikdav@gmail.com>2022-03-24 14:48:39 +0300
committerDavid Kocik <kocikdav@gmail.com>2022-03-24 14:48:39 +0300
commit999e13703086ebc4ac5a2a9ccd3a898ef13c2731 (patch)
tree101a369eafc633df7b2ee6c1f211963da2071923
parentfa565ca468c2cf8a1858c681dbf3f449ba4157d1 (diff)
parent9ece7c0ad47244a489ee72d1a81402ab6c561911 (diff)
Merge branch 'dk_notifications'
-rw-r--r--src/slic3r/GUI/GUI_ObjectList.cpp2
-rw-r--r--src/slic3r/GUI/NotificationManager.cpp110
-rw-r--r--src/slic3r/GUI/NotificationManager.hpp2
-rw-r--r--src/slic3r/GUI/Plater.cpp2
4 files changed, 107 insertions, 9 deletions
diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp
index 27c374b3f..4370a2f64 100644
--- a/src/slic3r/GUI/GUI_ObjectList.cpp
+++ b/src/slic3r/GUI/GUI_ObjectList.cpp
@@ -821,7 +821,7 @@ void ObjectList::paste_objects_into_list(const std::vector<size_t>& object_idxs)
wxDataViewItemArray items;
for (const size_t object : object_idxs)
{
- add_object_to_list(object);
+ add_object_to_list(object, false);
items.Add(m_objects_model->GetItemById(object));
}
diff --git a/src/slic3r/GUI/NotificationManager.cpp b/src/slic3r/GUI/NotificationManager.cpp
index fc9e5f49c..fc20e43f5 100644
--- a/src/slic3r/GUI/NotificationManager.cpp
+++ b/src/slic3r/GUI/NotificationManager.cpp
@@ -318,7 +318,8 @@ void NotificationManager::PopNotification::count_lines()
}
m_lines_count++;
}
- // hypertext calculation
+ // original hypertext calculation (when there was no text2)
+ /*
if (!m_hypertext.empty()) {
int prev_end = m_endlines.size() > 1 ? m_endlines[m_endlines.size() - 2] : 0; // m_endlines.size() - 2 because we are fitting hypertext instead of last endline
if (ImGui::CalcTextSize((escape_string_cstyle(text.substr(prev_end, last_end - prev_end)) + m_hypertext).c_str()).x > m_window_width - m_window_width_offset) {
@@ -326,9 +327,84 @@ void NotificationManager::PopNotification::count_lines()
m_lines_count++;
}
}
+ */
+ int prev_end = m_endlines.size() > 1 ? m_endlines[m_endlines.size() - 2] : 0;
+ int size_of_last_line = ImGui::CalcTextSize(text.substr(prev_end, last_end - prev_end).c_str()).x;
+ // hypertext calculation
+ if (!m_hypertext.empty()) {
+ if (size_of_last_line + ImGui::CalcTextSize(m_hypertext.c_str()).x > m_window_width - m_window_width_offset) {
+ // hypertext on new line
+ size_of_last_line = ImGui::CalcTextSize((m_hypertext + " ").c_str()).x;
+ m_endlines.push_back(last_end);
+ m_lines_count++;
+ }
+ else {
+ size_of_last_line += ImGui::CalcTextSize((m_hypertext + " ").c_str()).x;
+ }
+ }
+ // text after hypertext calculation
+ if (!m_text2.empty()) {
+ text = m_text2;
+ last_end = 0;
+ m_endlines2.clear();
+ // if size_of_last_line too large to fit anything
+ size_t first_end = std::min(text.find_first_of('\n'), text.find_first_of(' '));
+ if (size_of_last_line >= m_window_width - m_window_width_offset - ImGui::CalcTextSize(text.substr(0, first_end).c_str()).x) {
+ m_endlines2.push_back(0);
+ size_of_last_line = 0;
+ }
+ while (last_end < text.length() - 1)
+ {
+ size_t next_hard_end = text.find_first_of('\n', last_end);
+ if (next_hard_end != std::string::npos && ImGui::CalcTextSize(text.substr(last_end, next_hard_end - last_end).c_str()).x < m_window_width - m_window_width_offset - size_of_last_line) {
+ //next line is ended by '/n'
+ m_endlines2.push_back(next_hard_end);
+ last_end = next_hard_end + 1;
+ }
+ else {
+ // find next suitable endline
+ if (ImGui::CalcTextSize(text.substr(last_end).c_str()).x >= m_window_width - m_window_width_offset - size_of_last_line) {
+ // more than one line till end
+ size_t next_space = text.find_first_of(' ', last_end);
+ if (next_space > 0) {
+ size_t next_space_candidate = text.find_first_of(' ', next_space + 1);
+ while (next_space_candidate > 0 && ImGui::CalcTextSize(text.substr(last_end, next_space_candidate - last_end).c_str()).x < m_window_width - m_window_width_offset - size_of_last_line) {
+ next_space = next_space_candidate;
+ next_space_candidate = text.find_first_of(' ', next_space + 1);
+ }
+ }
+ else {
+ next_space = text.length();
+ }
+ // when one word longer than line.
+ if (ImGui::CalcTextSize(text.substr(last_end, next_space - last_end).c_str()).x > m_window_width - m_window_width_offset - size_of_last_line ||
+ ImGui::CalcTextSize(text.substr(last_end, next_space - last_end).c_str()).x + size_of_last_line < (m_window_width - m_window_width_offset) / 5 * 3
+ ) {
+ float width_of_a = ImGui::CalcTextSize("a").x;
+ int letter_count = (int)((m_window_width - m_window_width_offset - size_of_last_line) / width_of_a);
+ while (last_end + letter_count < text.size() && ImGui::CalcTextSize(text.substr(last_end, letter_count).c_str()).x < m_window_width - m_window_width_offset - size_of_last_line) {
+ letter_count += get_utf8_sequence_length(text, last_end + letter_count);
+ }
+ m_endlines2.push_back(last_end + letter_count);
+ last_end += letter_count;
+ }
+ else {
+ m_endlines2.push_back(next_space);
+ last_end = next_space + 1;
+ }
+ }
+ else {
+ m_endlines2.push_back(text.length());
+ last_end = text.length();
+ }
+
+ }
+ if (size_of_last_line == 0) // if first line is continuation of previous text, do not add to line count.
+ m_lines_count++;
+ size_of_last_line = 0; // should countain value only for first line (with hypertext)
- // m_text_2 (text after hypertext) is not used for regular notifications right now.
- // its caluculation is in HintNotification::count_lines()
+ }
+ }
}
void NotificationManager::PopNotification::init()
@@ -394,8 +470,29 @@ void NotificationManager::PopNotification::render_text(ImGuiWrapper& imgui, cons
render_hypertext(imgui, x_offset + ImGui::CalcTextSize((line + (line.empty() ? "" : " ")).c_str()).x, starting_y + (m_endlines.size() - 1) * shift_y, m_hypertext);
}
- // text2 (text after hypertext) is not rendered for regular notifications
- // its rendering is in HintNotification::render_text
+ // text2
+ if (!m_text2.empty() && (m_multiline|| m_lines_count <= 2)) {
+ starting_y += (m_endlines.size() - 1) * shift_y;
+ last_end = 0;
+ for (size_t i = 0; i < (m_multiline ? m_endlines2.size() : 2); i++) {
+ if (i == 0) //first line X is shifted by hypertext
+ ImGui::SetCursorPosX(x_offset + ImGui::CalcTextSize((line + m_hypertext + (line.empty() ? " " : " ")).c_str()).x);
+ else
+ ImGui::SetCursorPosX(x_offset);
+
+ ImGui::SetCursorPosY(starting_y + i * shift_y);
+ line.clear();
+ if (m_endlines2.size() > i && m_text2.size() >= m_endlines2[i]) {
+
+ // regular line
+ line = m_text2.substr(last_end, m_endlines2[i] - last_end);
+ last_end = m_endlines2[i];
+ if (m_text2.size() > m_endlines2[i])
+ last_end += (m_text2[m_endlines2[i]] == '\n' || m_text2[m_endlines2[i]] == ' ' ? 1 : 0);
+ imgui.text(line.c_str());
+ }
+ }
+ }
}
void NotificationManager::PopNotification::render_hypertext(ImGuiWrapper& imgui, const float text_x, const float text_y, const std::string text, bool more)
@@ -1541,10 +1638,11 @@ void NotificationManager::push_notification(NotificationType type,
const std::string& text,
const std::string& hypertext,
std::function<bool(wxEvtHandler*)> callback,
+ const std::string& text_after,
int timestamp)
{
int duration = get_standard_duration(level);
- push_notification_data({ type, level, duration, text, hypertext, callback }, timestamp);
+ push_notification_data({ type, level, duration, text, hypertext, callback, text_after }, timestamp);
}
void NotificationManager::push_delayed_notification(const NotificationType type, std::function<bool(void)> condition_callback, int64_t initial_delay, int64_t delay_interval)
diff --git a/src/slic3r/GUI/NotificationManager.hpp b/src/slic3r/GUI/NotificationManager.hpp
index 72889c854..c6a24d997 100644
--- a/src/slic3r/GUI/NotificationManager.hpp
+++ b/src/slic3r/GUI/NotificationManager.hpp
@@ -154,7 +154,7 @@ public:
// Push a NotificationType::CustomNotification with provided notification level and 10s for RegularNotificationLevel.
// ErrorNotificationLevel are never faded out.
void push_notification(NotificationType type, NotificationLevel level, const std::string& text, const std::string& hypertext = "",
- std::function<bool(wxEvtHandler*)> callback = std::function<bool(wxEvtHandler*)>(), int timestamp = 0);
+ std::function<bool(wxEvtHandler*)> callback = std::function<bool(wxEvtHandler*)>(), const std::string& text_after = "", int timestamp = 0);
// Pushes basic_notification with delay. See push_delayed_notification_data.
void push_delayed_notification(const NotificationType type, std::function<bool(void)> condition_callback, int64_t initial_delay, int64_t delay_interval);
// Removes all notifications of type from m_waiting_notifications
diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp
index df593f130..3a5a49fd9 100644
--- a/src/slic3r/GUI/Plater.cpp
+++ b/src/slic3r/GUI/Plater.cpp
@@ -2217,7 +2217,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
bool is_collapsed = wxGetApp().app_config->get("collapsed_sidebar") == "1";
sidebar->collapse(is_collapsed);
}
-}
+ }
Plater::priv::~priv()
{