NEW:optimize text wrap and tips for sending prints

Change-Id: I6e1aa8eba4d7bf948068126cd25216e8dbc68413
This commit is contained in:
tao wang 2022-12-08 10:56:18 +08:00 committed by Lane.Wei
parent 81d38bf140
commit 65ff90690f
3 changed files with 30 additions and 29 deletions

View File

@ -26,16 +26,12 @@ BBLStatusBarSend::BBLStatusBarSend(wxWindow *parent, int id)
wxBoxSizer *m_sizer_body = new wxBoxSizer(wxVERTICAL); wxBoxSizer *m_sizer_body = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *m_sizer_bottom = new wxBoxSizer(wxHORIZONTAL); wxBoxSizer *m_sizer_bottom = new wxBoxSizer(wxHORIZONTAL);
m_status_text = new wxStaticText(m_self, wxID_ANY, "", wxDefaultPosition, wxSize(m_self->FromDIP(280), -1), 0); m_status_text = new wxStaticText(m_self, wxID_ANY, wxEmptyString);
m_status_text->SetForegroundColour(wxColour(107, 107, 107)); m_status_text->SetForegroundColour(wxColour(107, 107, 107));
m_status_text->SetFont(::Label::Body_13); m_status_text->SetFont(::Label::Body_13);
m_status_text->Wrap(m_self->FromDIP(280));
m_status_text->SetSize(wxSize(m_self->FromDIP(280), m_self->FromDIP(46))); m_status_text->SetSize(wxSize(m_self->FromDIP(280), m_self->FromDIP(46)));
m_status_text->SetMaxSize(wxSize(m_self->FromDIP(280), m_self->FromDIP(46))); m_status_text->SetMaxSize(wxSize(m_self->FromDIP(280), m_self->FromDIP(46)));
//m_status_text->SetSize()
m_prog = new wxGauge(m_self, wxID_ANY, 100, wxDefaultPosition, wxSize(-1, m_self->FromDIP(6)), wxGA_HORIZONTAL); m_prog = new wxGauge(m_self, wxID_ANY, 100, wxDefaultPosition, wxSize(-1, m_self->FromDIP(6)), wxGA_HORIZONTAL);
m_prog->SetValue(0); m_prog->SetValue(0);
@ -201,38 +197,43 @@ bool BBLStatusBarSend::is_english_text(wxString str)
return true; return true;
} }
wxString BBLStatusBarSend::format_text(wxStaticText* st, wxString str, int warp) bool BBLStatusBarSend::format_text(wxStaticText* dc, int width, const wxString& text, wxString& multiline_text)
{ {
int index = 0; bool multiline = false;
if (!str.empty()) { multiline_text = text;
while ((index = str.find('\n', index)) != string::npos) { if (width > 0 && dc->GetTextExtent(text).x > width) {
str.erase(index, 1); size_t start = 0;
} while (true) {
} size_t idx = size_t(-1);
for (size_t i = start; i < multiline_text.Len(); i++) {
wxString out_txt = str; if (multiline_text[i] == ' ') {
wxString count_txt = ""; if (dc->GetTextExtent(multiline_text.SubString(start, i)).x < width)
int new_line_pos = 0; idx = i;
for (int i = 0; i < str.length(); i++) {
auto text_size = st->GetTextExtent(count_txt);
if (text_size.x < warp) {
count_txt += str[i];
}
else { else {
out_txt.insert(i - 1, '\n'); if (idx == size_t(-1)) idx = i;
count_txt = ""; break;
} }
} }
return out_txt; }
if (idx == size_t(-1)) break;
multiline = true;
multiline_text[idx] = '\n';
start = idx + 1;
if (dc->GetTextExtent(multiline_text.Mid(start)).x < width) break;
}
}
return multiline;
//return dc->GetTextExtent(multiline_text);
} }
void BBLStatusBarSend::set_status_text(const wxString& txt) void BBLStatusBarSend::set_status_text(const wxString& txt)
{ {
//auto txtss = "Sending the printing task has timed out.\nPlease try again!"; //auto txtss = "Sending the printing task has timed out.\nPlease try again!";
//auto txtss = "The printing project is being uploaded... 25%%"; //auto txtss = "The printing project is being uploaded... 25%%";
//m_status_text->SetLabelText(txtss); //m_status_text->SetLabelText(txtss);
wxString str = format_text(m_status_text,txt,280); wxString str;
format_text(m_status_text, m_self->FromDIP(280), txt, str);
m_status_text->SetLabelText(str); m_status_text->SetLabelText(str);
//if (is_english_text(str)) m_status_text->Wrap(m_self->FromDIP(280)); //if (is_english_text(str)) m_status_text->Wrap(m_self->FromDIP(280));
} }

View File

@ -58,7 +58,7 @@ public:
inline void reset_cancel_callback() { set_cancel_callback(); } inline void reset_cancel_callback() { set_cancel_callback(); }
wxPanel * get_panel(); wxPanel * get_panel();
bool is_english_text(wxString str); bool is_english_text(wxString str);
wxString format_text(wxStaticText* st, wxString str, int warp); bool format_text(wxStaticText* dc, int width, const wxString& text, wxString& multiline_text);
void set_status_text(const wxString& txt); void set_status_text(const wxString& txt);
void set_percent_text(const wxString &txt); void set_percent_text(const wxString &txt);
void msw_rescale(); void msw_rescale();

View File

@ -215,7 +215,7 @@ void PrintJob::process()
} }
} }
else if (stage == BBL::SendingPrintJobStage::PrintingStageFinished) { else if (stage == BBL::SendingPrintJobStage::PrintingStageFinished) {
msg = wxString::Format(_L("Successfully sent. Will automatically jump to the device page in %s s"), info); msg = wxString::Format(_L("Successfully sent. Will automatically jump to the device page in %ss"), info);
this->update_percent_finish(); this->update_percent_finish();
} else { } else {
if (this->connection_type == "lan") { if (this->connection_type == "lan") {