OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::WikiLabel Class Reference
Inheritance diagram for Slic3r::GUI::WikiLabel:
Collaboration diagram for Slic3r::GUI::WikiLabel:

Public Member Functions

 WikiLabel (wxWindow *parent, const wxString &label, const wxString &url=wxEmptyString, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
void SetLabel (const wxString &label) override
bool SetFont (const wxFont &font) override
wxString GetLabel () const override
void SetURL (const wxString &url)
wxString GetURL () const
void ReflowText ()
wxSize DoGetBestSize () const override
void Rescale ()

Private Member Functions

void OnPaint (wxPaintEvent &evt)
void OnSize (wxSizeEvent &evt)
void OnMotion (wxMouseEvent &evt)
void OnLeaveWin (wxMouseEvent &evt)
void OnLeftDown (wxMouseEvent &evt)

Private Attributes

wxString m_label
wxString m_url
wxArrayString m_lines
bool m_hovered = false
wxFont m_font
int m_last_wrap_width = -1

Detailed Description

Constructor & Destructor Documentation

◆ WikiLabel()

Slic3r::GUI::WikiLabel::WikiLabel ( wxWindow * parent,
const wxString & label,
const wxString & url = wxEmptyString,
const wxPoint & pos = wxDefaultPosition,
const wxSize & size = wxDefaultSize )
inline
116 : wxPanel(parent, wxID_ANY, pos, size, wxFULL_REPAINT_ON_RESIZE)
117 , m_label(label)
118 , m_url(url)
119 {
120#ifndef __WXOSX__
121 SetDoubleBuffered(true);// SetDoubleBuffered exists on Win and Linux/GTK, but is missing on OSX
122#endif
123 SetBackgroundColour(parent->GetBackgroundColour());
124
126
127 Bind(wxEVT_PAINT, &WikiLabel::OnPaint, this);
128 Bind(wxEVT_SIZE, &WikiLabel::OnSize, this);
129 Bind(wxEVT_MOTION, &WikiLabel::OnMotion, this);
130 Bind(wxEVT_LEAVE_WINDOW, &WikiLabel::OnLeaveWin, this);
131 Bind(wxEVT_LEFT_DOWN, &WikiLabel::OnLeftDown, this);
132 }
static wxFont Body_14
Definition Label.hpp:53
void OnMotion(wxMouseEvent &evt)
Definition Preferences.cpp:270
wxString m_label
Definition Preferences.cpp:101
void OnSize(wxSizeEvent &evt)
Definition Preferences.cpp:263
void OnPaint(wxPaintEvent &evt)
Definition Preferences.cpp:230
bool SetFont(const wxFont &font) override
Definition Preferences.cpp:142
void OnLeftDown(wxMouseEvent &evt)
Definition Preferences.cpp:288
wxString m_url
Definition Preferences.cpp:102
void OnLeaveWin(wxMouseEvent &evt)
Definition Preferences.cpp:279

References Label::Body_14, m_label, m_url, OnLeaveWin(), OnLeftDown(), OnMotion(), OnPaint(), OnSize(), and SetFont().

Here is the call graph for this function:

Member Function Documentation

◆ DoGetBestSize()

wxSize Slic3r::GUI::WikiLabel::DoGetBestSize ( ) const
inlineoverride
202 {
203 const int lineH = wxMax(1, wxWindow::GetCharHeight()); // GTK can return 0 from GetCharHeight() before the window is realized
204 const int nLines = m_lines.IsEmpty() ? 1 : static_cast<int>(m_lines.size());
205 const int totalH = static_cast<int>(nLines * lineH * 1.3);
206
207 const int clientW = GetClientSize().GetWidth();
208
209 if (clientW > 0)
210 return wxSize(clientW, totalH);
211
212 if (m_label.IsEmpty())
213 return wxSize(1, lineH);
214
215 int maxW = 0;
216 for (const wxString& line : wxSplit(m_label, '\n'))
217 maxW = wxMax(maxW, GetTextExtent(line).GetWidth());
218
219 return wxSize(wxMax(1, maxW), totalH);
220 }
wxArrayString m_lines
Definition Preferences.cpp:103

References m_label, and m_lines.

◆ GetLabel()

wxString Slic3r::GUI::WikiLabel::GetLabel ( ) const
inlineoverride
154{ return m_label; }

References m_label.

◆ GetURL()

wxString Slic3r::GUI::WikiLabel::GetURL ( ) const
inline
156{ return m_url; }

References m_url.

◆ OnLeaveWin()

void Slic3r::GUI::WikiLabel::OnLeaveWin ( wxMouseEvent & evt)
inlineprivate
280 {
281 if(!m_url.IsEmpty() && m_hovered){
282 m_hovered = false;
283 Refresh();
284 }
285 evt.Skip();
286 }
bool m_hovered
Definition Preferences.cpp:104

References m_hovered, m_url, and Slic3r::GUI::wxMouseEvent.

Referenced by WikiLabel().

Here is the caller graph for this function:

◆ OnLeftDown()

void Slic3r::GUI::WikiLabel::OnLeftDown ( wxMouseEvent & evt)
inlineprivate
289 {
290 if (!m_url.IsEmpty())
291 wxLaunchDefaultBrowser(m_url);
292 evt.Skip();
293 }

References m_url, and Slic3r::GUI::wxMouseEvent.

Referenced by WikiLabel().

Here is the caller graph for this function:

◆ OnMotion()

void Slic3r::GUI::WikiLabel::OnMotion ( wxMouseEvent & evt)
inlineprivate
271 {
272 if(!m_url.IsEmpty() && !m_hovered){
273 m_hovered = true;
274 Refresh();
275 }
276 evt.Skip();
277 }

References m_hovered, m_url, and Slic3r::GUI::wxMouseEvent.

Referenced by WikiLabel().

Here is the caller graph for this function:

◆ OnPaint()

void Slic3r::GUI::WikiLabel::OnPaint ( wxPaintEvent & evt)
inlineprivate
231 {
232 wxPaintDC dc(this);
233
234 dc.SetBackground(wxBrush(GetParent() ? GetParent()->GetBackgroundColour() : *wxWHITE));
235 dc.Clear();
236
237 wxColour textCol = StateColor::darkModeColorFor(m_hovered ? "#26A69A" : "#363636");
238
239 dc.SetTextForeground(textCol);
240 dc.SetFont(m_font);
241 dc.SetBackgroundMode(wxTRANSPARENT);
242
243 int lineH = dc.GetCharHeight();
244 int y = lround(lineH * 0.15);
245
246 for (const wxString& line : m_lines) {
247 if (!line.IsEmpty()) {
248 dc.DrawText(line, 0, y);
249
250 if (m_hovered) {
251 int tw, th;
252 dc.GetTextExtent(line, &tw, &th);
253
254 int underlineY = y + lineH - 1; // 1 px below the baseline
255 dc.SetPen(wxPen(textCol, 1));
256 dc.DrawLine(0, underlineY, tw, underlineY);
257 }
258 }
259 y += lineH;
260 }
261 }
wxFont m_font
Definition Preferences.cpp:105
static wxColour darkModeColorFor(wxColour const &color)
Definition StateColor.cpp:219

References StateColor::darkModeColorFor(), m_font, m_hovered, and m_lines.

Referenced by WikiLabel().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnSize()

void Slic3r::GUI::WikiLabel::OnSize ( wxSizeEvent & evt)
inlineprivate
264 {
265 ReflowText();
266 Refresh();
267 evt.Skip();
268 }
void ReflowText()
Definition Preferences.cpp:158

References ReflowText().

Referenced by WikiLabel().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReflowText()

void Slic3r::GUI::WikiLabel::ReflowText ( )
inline
159 {
160 const int clientW = GetClientSize().GetWidth();
161
162 if (clientW <= 0 || (clientW == m_last_wrap_width && !m_lines.IsEmpty()))
163 return;
164
165 m_last_wrap_width = clientW;
166
167 wxArrayString lines;
168 for (const wxString& para : wxSplit(m_label, '\n')) {
169 if (para.IsEmpty())
170 lines.Add(wxEmptyString);
171 else {
172 wxString currentLine;
173 for (const wxString& word : wxSplit(para, ' ')) {
174 wxString candidate = currentLine.IsEmpty() ? word : (currentLine + ' ' + word);
175
176 if (GetTextExtent(candidate).GetWidth() <= clientW)
177 currentLine = candidate;
178 else {
179 if (currentLine.IsEmpty())
180 lines.Add(word); // single word wider than column
181 else {
182 lines.Add(currentLine);
183 currentLine = word;
184 }
185 }
186 }
187 if (!currentLine.IsEmpty())
188 lines.Add(currentLine);
189 }
190 }
191 m_lines = lines;
192
193 const int lineH = wxMax(1, wxWindow::GetCharHeight()); // GTK can return 0 from GetCharHeight() before the window is realized
194 const int nLines = m_lines.IsEmpty() ? 1 : static_cast<int>(m_lines.size());
195 const int totalH = static_cast<int>(nLines * lineH * 1.3);
196
197 SetMinSize(wxSize(-1, totalH));
198 InvalidateBestSize();
199 }
int m_last_wrap_width
Definition Preferences.cpp:106

References m_label, m_last_wrap_width, and m_lines.

Referenced by OnSize(), SetFont(), and SetLabel().

Here is the caller graph for this function:

◆ Rescale()

void Slic3r::GUI::WikiLabel::Rescale ( )
inline
223 {
224 m_last_wrap_width = -1; // force re-wrap
225 m_lines.Clear();
226 InvalidateBestSize();
227 }

References m_last_wrap_width, and m_lines.

◆ SetFont()

bool Slic3r::GUI::WikiLabel::SetFont ( const wxFont & font)
inlineoverride
143 {
144 const bool changed = wxPanel::SetFont(font);
145 m_font = font;
146 m_last_wrap_width = -1; // force re-wrap
147 if (IsShownOnScreen()) {
148 ReflowText();
149 Refresh();
150 }
151 return changed;
152 }

References m_font, m_last_wrap_width, and ReflowText().

Referenced by WikiLabel().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetLabel()

void Slic3r::GUI::WikiLabel::SetLabel ( const wxString & label)
inlineoverride
135 {
136 m_label = label;
137 m_last_wrap_width = -1; // force re-wrap
138 ReflowText();
139 Refresh();
140 }

References m_label, m_last_wrap_width, and ReflowText().

Here is the call graph for this function:

◆ SetURL()

void Slic3r::GUI::WikiLabel::SetURL ( const wxString & url)
inline
155{ m_url = url; }

References m_url.

Member Data Documentation

◆ m_font

wxFont Slic3r::GUI::WikiLabel::m_font
private

Referenced by OnPaint(), and SetFont().

◆ m_hovered

bool Slic3r::GUI::WikiLabel::m_hovered = false
private

Referenced by OnLeaveWin(), OnMotion(), and OnPaint().

◆ m_label

wxString Slic3r::GUI::WikiLabel::m_label
private

◆ m_last_wrap_width

int Slic3r::GUI::WikiLabel::m_last_wrap_width = -1
private

Referenced by ReflowText(), Rescale(), SetFont(), and SetLabel().

◆ m_lines

wxArrayString Slic3r::GUI::WikiLabel::m_lines
private

◆ m_url

wxString Slic3r::GUI::WikiLabel::m_url
private

The documentation for this class was generated from the following file: