OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::CenteredMultiLinePanel Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/TroubleshootDialog.hpp>

Inheritance diagram for Slic3r::GUI::CenteredMultiLinePanel:
Collaboration diagram for Slic3r::GUI::CenteredMultiLinePanel:

Public Member Functions

 CenteredMultiLinePanel (wxWindow *parent, const std::vector< wxString > &lines={})
void SetText (const std::vector< wxString > &lines)

Private Member Functions

std::vector< wxString > Wrap (wxDC &dc, const wxString &text, int maxW)
void OnPaint (wxPaintEvent &)
void UpdateMinSize ()
void OnSize (wxSizeEvent &e)

Private Attributes

std::vector< wxString > m_lines

Static Private Attributes

static constexpr double m_block_gap = 0.55
static constexpr double m_line_height = 1.15

Detailed Description

Constructor & Destructor Documentation

◆ CenteredMultiLinePanel()

Slic3r::GUI::CenteredMultiLinePanel::CenteredMultiLinePanel ( wxWindow * parent,
const std::vector< wxString > & lines = {} )
inline
108 {})
109 : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL | wxFULL_REPAINT_ON_RESIZE)
110 {
111 SetFont(Label::Body_14);
112 SetBackgroundStyle(wxBG_STYLE_PAINT);
113 Bind(wxEVT_PAINT, &CenteredMultiLinePanel::OnPaint, this);
114 Bind(wxEVT_SIZE, &CenteredMultiLinePanel::OnSize, this);
115
116 SetText(lines);
117 }
static wxFont Body_14
Definition Label.hpp:53
void SetText(const std::vector< wxString > &lines)
Definition TroubleshootDialog.hpp:119
void OnSize(wxSizeEvent &e)
Definition TroubleshootDialog.hpp:205
void OnPaint(wxPaintEvent &)
Definition TroubleshootDialog.hpp:150

Member Function Documentation

◆ OnPaint()

void Slic3r::GUI::CenteredMultiLinePanel::OnPaint ( wxPaintEvent & )
inlineprivate
151 {
152 wxAutoBufferedPaintDC dc(this);
153 dc.Clear();
154
155 int cWidth = GetClientSize().GetWidth();
156 if (m_lines.empty() || cWidth < 50) return;
157
158 dc.SetTextForeground(GetForegroundColour());
159
160 int y = 0;
161 for (size_t i = 0; i < m_lines.size(); ++i) {
162 wxCoord tw, th;
163 for (auto& line : Wrap(dc, m_lines[i], cWidth)) {
164 line.Trim();
165 line.Trim(false);
166 dc.GetTextExtent(line, &tw, &th);
167 dc.DrawText(line, (cWidth - tw) / 2, y);
168 y += static_cast<int>(th * m_line_height);
169 }
170 if (i < m_lines.size() - 1)
171 y += static_cast<int>(th * m_block_gap);
172 }
173 }
static constexpr double m_block_gap
Definition TroubleshootDialog.hpp:103
std::vector< wxString > m_lines
Definition TroubleshootDialog.hpp:105
std::vector< wxString > Wrap(wxDC &dc, const wxString &text, int maxW)
Definition TroubleshootDialog.hpp:128
static constexpr double m_line_height
Definition TroubleshootDialog.hpp:104

References m_block_gap, m_line_height, m_lines, and Wrap().

Here is the call graph for this function:

◆ OnSize()

void Slic3r::GUI::CenteredMultiLinePanel::OnSize ( wxSizeEvent & e)
inlineprivate
206 {
207 Refresh();
209 e.Skip();
210 }
void UpdateMinSize()
Definition TroubleshootDialog.hpp:175

References UpdateMinSize().

Here is the call graph for this function:

◆ SetText()

void Slic3r::GUI::CenteredMultiLinePanel::SetText ( const std::vector< wxString > & lines)
inline
120 {
121 if(!lines.empty()){
122 m_lines = lines;
123 Refresh();
125 }
126 }

References m_lines, and UpdateMinSize().

Here is the call graph for this function:

◆ UpdateMinSize()

void Slic3r::GUI::CenteredMultiLinePanel::UpdateMinSize ( )
inlineprivate
176 {
177 if (m_lines.empty() || !GetParent()) {
178 SetMinSize(wxDefaultSize);
179 return;
180 }
181 wxClientDC dc(this);
182 int cWidth = GetClientSize().GetWidth();
183 // Don't compute/commit a size based on a not-yet-laid-out width
184 // Mirrors the guard in OnPaint() so both use the same wrap results
185 if (cWidth < 50) return;
186
187 int y = 0;
188 for (size_t i = 0; i < m_lines.size(); ++i) {
189 wxCoord th;
190 for (auto& line : Wrap(dc, m_lines[i], cWidth)) {
191 dc.GetTextExtent(line, nullptr, &th);
192 y += static_cast<int>(th * m_line_height);
193 }
194 if (i < m_lines.size() - 1)
195 y += static_cast<int>(th * m_block_gap);
196 }
197
198 if(GetMinSize().GetHeight() != y){
199 SetMinSize(wxSize(-1, y));
200 if(GetParent())
201 GetParent()->Layout();
202 }
203 }

References m_block_gap, m_line_height, m_lines, and Wrap().

Referenced by OnSize(), and SetText().

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

◆ Wrap()

std::vector< wxString > Slic3r::GUI::CenteredMultiLinePanel::Wrap ( wxDC & dc,
const wxString & text,
int maxW )
inlineprivate
129 {
130 std::vector<wxString> out;
131 wxString cur;
132 for (const auto& word : wxSplit(text, ' ', true)) {
133 wxString trial = cur.empty() ? word : cur + " " + word;
134 wxCoord w, h;
135 dc.GetTextExtent(trial, &w, &h);
136 if (w <= maxW)
137 cur = trial;
138 else if (!cur.empty()){
139 out.push_back(cur);
140 cur = word;
141 }
142 else
143 out.push_back(word);
144 }
145 if (!cur.empty())
146 out.push_back(cur);
147 return out;
148 }

Referenced by OnPaint(), and UpdateMinSize().

Here is the caller graph for this function:

Member Data Documentation

◆ m_block_gap

double Slic3r::GUI::CenteredMultiLinePanel::m_block_gap = 0.55
staticconstexprprivate

Referenced by OnPaint(), and UpdateMinSize().

◆ m_line_height

double Slic3r::GUI::CenteredMultiLinePanel::m_line_height = 1.15
staticconstexprprivate

Referenced by OnPaint(), and UpdateMinSize().

◆ m_lines

std::vector<wxString> Slic3r::GUI::CenteredMultiLinePanel::m_lines
private

Referenced by OnPaint(), SetText(), and UpdateMinSize().


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