mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-08 07:27:41 -06:00
FIX: [STUDIO-3547] use Label instead of ErrorMsgStaticText
Change-Id: Ibf813bea7ced38a6a303d6d4bac3cac542663ba0
This commit is contained in:
parent
a4b3a5c000
commit
0162fceb98
6 changed files with 98 additions and 94 deletions
|
@ -108,6 +108,11 @@ public:
|
|||
for (bool newLine = false; !line.empty(); newLine = true) {
|
||||
if (newLine) OnNewLine();
|
||||
|
||||
if (1 == line.length()) {
|
||||
DoOutputLine(line);
|
||||
break;
|
||||
}
|
||||
|
||||
wxArrayInt widths;
|
||||
dc.GetPartialTextExtents(line, widths);
|
||||
|
||||
|
@ -136,6 +141,10 @@ public:
|
|||
// No spaces, so can't wrap.
|
||||
lastSpace = posEnd;
|
||||
}
|
||||
if (lastSpace == 0) {
|
||||
// Break at least one char
|
||||
lastSpace = 1;
|
||||
}
|
||||
|
||||
// Output the part that fits.
|
||||
DoOutputLine(line.substr(0, lastSpace));
|
||||
|
@ -184,13 +193,14 @@ private:
|
|||
class wxLabelWrapper2 : public wxTextWrapper2
|
||||
{
|
||||
public:
|
||||
void WrapLabel(wxWindow *text, int widthMax)
|
||||
void WrapLabel(wxWindow *text, wxString const & label, int widthMax)
|
||||
{
|
||||
m_text.clear();
|
||||
Wrap(text, text->GetLabel(), widthMax);
|
||||
text->SetLabel(m_text);
|
||||
Wrap(text, label, widthMax);
|
||||
}
|
||||
|
||||
wxString GetText() const { return m_text; }
|
||||
|
||||
protected:
|
||||
virtual void OnOutputLine(const wxString &line) wxOVERRIDE { m_text += line; }
|
||||
|
||||
|
@ -232,23 +242,32 @@ Label::Label(wxWindow *parent, wxString const &text, long style) : Label(parent,
|
|||
Label::Label(wxWindow *parent, wxFont const &font, wxString const &text, long style)
|
||||
: wxStaticText(parent, wxID_ANY, text, wxDefaultPosition, wxDefaultSize, style)
|
||||
{
|
||||
this->font = font;
|
||||
this->m_font = font;
|
||||
this->m_text = text;
|
||||
SetFont(font);
|
||||
SetForegroundColour(*wxBLACK);
|
||||
SetBackgroundColour(StaticBox::GetParentBackgroundColor(parent));
|
||||
SetForegroundColour("#262E30");
|
||||
if (style & LB_PROPAGATE_MOUSE_EVENT) {
|
||||
for (auto evt : {
|
||||
wxEVT_LEFT_UP, wxEVT_LEFT_DOWN})
|
||||
for (auto evt : { wxEVT_LEFT_UP, wxEVT_LEFT_DOWN })
|
||||
Bind(evt, [this] (auto & e) { GetParent()->GetEventHandler()->ProcessEventLocally(e); });
|
||||
};
|
||||
};
|
||||
if (style & LB_AUTO_WRAP) {
|
||||
Bind(wxEVT_SIZE, &Label::OnSize, this);
|
||||
Wrap(GetSize().x);
|
||||
}
|
||||
}
|
||||
|
||||
void Label::SetLabel(const wxString& label)
|
||||
{
|
||||
if (GetLabel() == label)
|
||||
if (m_text == label)
|
||||
return;
|
||||
wxStaticText::SetLabel(label);
|
||||
m_text = label;
|
||||
if ((GetWindowStyle() & LB_AUTO_WRAP)) {
|
||||
Wrap(GetSize().x);
|
||||
} else {
|
||||
wxStaticText::SetLabel(label);
|
||||
}
|
||||
#ifdef __WXOSX__
|
||||
if ((GetWindowStyle() & LB_HYPERLINK)) {
|
||||
SetLabelMarkup(label);
|
||||
|
@ -263,22 +282,21 @@ void Label::SetWindowStyleFlag(long style)
|
|||
return;
|
||||
wxStaticText::SetWindowStyleFlag(style);
|
||||
if (style & LB_HYPERLINK) {
|
||||
this->color = GetForegroundColour();
|
||||
this->m_color = GetForegroundColour();
|
||||
static wxColor clr_url("#00AE42");
|
||||
SetFont(this->font.Underlined());
|
||||
SetFont(this->m_font.Underlined());
|
||||
SetForegroundColour(clr_url);
|
||||
SetCursor(wxCURSOR_HAND);
|
||||
#ifdef __WXOSX__
|
||||
SetLabelMarkup(GetLabel());
|
||||
SetLabelMarkup(m_text);
|
||||
#endif
|
||||
} else {
|
||||
SetForegroundColour(this->color);
|
||||
SetFont(this->font);
|
||||
SetForegroundColour(this->m_color);
|
||||
SetFont(this->m_font);
|
||||
SetCursor(wxCURSOR_ARROW);
|
||||
#ifdef __WXOSX__
|
||||
auto label = GetLabel();
|
||||
wxStaticText::SetLabel({});
|
||||
wxStaticText::SetLabel(label);
|
||||
SetLabel(m_text);
|
||||
#endif
|
||||
}
|
||||
Refresh();
|
||||
|
@ -287,5 +305,15 @@ void Label::SetWindowStyleFlag(long style)
|
|||
void Label::Wrap(int width)
|
||||
{
|
||||
wxLabelWrapper2 wrapper;
|
||||
wrapper.WrapLabel(this, width);
|
||||
wrapper.Wrap(this, m_text, width);
|
||||
m_skip_size_evt = true;
|
||||
wxStaticText::SetLabel(wrapper.GetText());
|
||||
m_skip_size_evt = false;
|
||||
}
|
||||
|
||||
void Label::OnSize(wxSizeEvent &evt)
|
||||
{
|
||||
evt.Skip();
|
||||
if (m_skip_size_evt) return;
|
||||
Wrap(evt.GetSize().x);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue