OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
TextInput Class Reference

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

Inheritance diagram for TextInput:
Collaboration diagram for TextInput:

Public Member Functions

 TextInput ()
 TextInput (wxWindow *parent, wxString text, wxString label="", wxString icon="", const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0)
void Create (wxWindow *parent, wxString text, wxString label="", wxString icon="", const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0)
void SetCornerRadius (double radius)
int GetCornerRadius () const
void SetLabel (const wxString &label) override
void SetStaticTips (const wxString &tips, const wxBitmap &bitmap)
void SetIcon (const wxBitmap &icon)
void SetIcon (const wxString &icon)
void SetIcon_1 (const wxString &icon)
void SetIcon_1 (const wxBitmap &icon)
void SetLabelColor (StateColor const &color)
void SetTextColor (StateColor const &color)
virtual void Rescale ()
virtual bool Enable (bool enable=true) override
virtual void SetMinSize (const wxSize &size) override
wxTextCtrl * GetTextCtrl ()
wxTextCtrl const * GetTextCtrl () const

Protected Member Functions

virtual void OnEdit ()
virtual void DoSetSize (int x, int y, int width, int height, int sizeFlags=wxSIZE_AUTO) override
void DoSetToolTipText (wxString const &tip) override

Private Member Functions

void paintEvent (wxPaintEvent &evt)
void render (wxDC &dc)
void messureSize ()

Private Attributes

wxSize labelSize
ScalableBitmap icon
ScalableBitmap icon_1
StateColor label_color
StateColor text_color
wxTextCtrl * text_ctrl
wxString static_tips
wxSize static_tips_size
wxBitmap static_tips_icon

Static Private Attributes

static const int TextInputWidth = 200
static const int TextInputHeight = 50

Detailed Description

Constructor & Destructor Documentation

◆ TextInput() [1/2]

TextInput::TextInput ( )
38 : label_color(std::make_pair(0x6B6B6B, (int) StateColor::Disabled),
39 std::make_pair(0x6B6B6B, (int) StateColor::Normal))
40 , text_color(std::make_pair(0x6B6B6B, (int) StateColor::Disabled),
41 std::make_pair(0x262E30, (int) StateColor::Normal))
42{
43 radius = 0;
44 border_width = 1;
45 border_color = StateColor(std::make_pair(0xDBDBDB, (int) StateColor::Disabled), std::make_pair(0x009688, (int) StateColor::Hovered),
46 std::make_pair(0xDBDBDB, (int) StateColor::Normal));
47 background_color = StateColor(std::make_pair(0xF0F0F1, (int) StateColor::Disabled), std::make_pair(*wxWHITE, (int) StateColor::Normal));
48 SetFont(Label::Body_12);
49}
static wxFont Body_12
Definition Label.hpp:55
@ Hovered
Definition StateColor.hpp:20
@ Normal
Definition StateColor.hpp:16
@ Disabled
Definition StateColor.hpp:22
StateColor text_color
Definition TextInput.hpp:21
StateColor label_color
Definition TextInput.hpp:20

References TextInput(), Label::Body_12, StateColor::Disabled, StateColor::Hovered, label_color, StateColor::Normal, and text_color.

Referenced by Slic3r::GUI::GridTextInput::GridTextInput(), Slic3r::GUI::LayerRangeEditor::LayerRangeEditor(), TextInput(), and TextInput().

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

◆ TextInput() [2/2]

TextInput::TextInput ( wxWindow * parent,
wxString text,
wxString label = "",
wxString icon = "",
const wxPoint & pos = wxDefaultPosition,
const wxSize & size = wxDefaultSize,
long style = 0 )
58 : TextInput()
59{
60 Create(parent, text, label, icon, pos, size, style);
61}
#define style
Definition WipeTowerDialog.cpp:101
TextInput()
Definition TextInput.cpp:37
void Create(wxWindow *parent, wxString text, wxString label="", wxString icon="", const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0)
Definition TextInput.cpp:63
ScalableBitmap icon
Definition TextInput.hpp:18

References TextInput(), Create(), icon, and style.

Here is the call graph for this function:

Member Function Documentation

◆ Create()

void TextInput::Create ( wxWindow * parent,
wxString text,
wxString label = "",
wxString icon = "",
const wxPoint & pos = wxDefaultPosition,
const wxSize & size = wxDefaultSize,
long style = 0 )
70{
71 text_ctrl = nullptr;
72 StaticBox::Create(parent, wxID_ANY, pos, size, style);
73 wxWindow::SetLabel(label);
74 assert((style & wxRIGHT) == 0);
75 style &= ~wxALIGN_MASK;
76 state_handler.attach({&label_color, & text_color});
77 state_handler.update_binds();
78 text_ctrl = new TextCtrl(this, wxID_ANY, text, {4, 4}, wxDefaultSize, style | wxBORDER_NONE | wxTE_PROCESS_ENTER);
79
80#ifdef __WXGTK__
81 Slic3r::GUI::RemoveInputBorder(text_ctrl);
82#endif
83
84 text_ctrl->SetFont(Label::Body_14);
85 text_ctrl->SetInitialSize(text_ctrl->GetBestSize());
86 text_ctrl->SetBackgroundColour(background_color.colorForStates(state_handler.states()));
87 text_ctrl->SetForegroundColour(text_color.colorForStates(state_handler.states()));
88 state_handler.attach_child(text_ctrl);
89 text_ctrl->Bind(wxEVT_KILL_FOCUS, [this](auto &e) {
90 OnEdit();
91 e.SetId(GetId());
92 ProcessEventLocally(e);
93 e.Skip();
94 });
95 text_ctrl->Bind(wxEVT_TEXT_ENTER, [this](auto &e) {
96 OnEdit();
97 e.SetId(GetId());
98 ProcessEventLocally(e);
99 });
100 text_ctrl->Bind(wxEVT_RIGHT_DOWN, [](auto &e) {}); // disable context menu
101 if (!icon.IsEmpty()) {
102 this->icon = ScalableBitmap(this, icon.ToStdString(), 16);
103 }
104 messureSize();
105}
wxTextCtrl TextCtrl
Definition TextCtrl.h:14
static wxFont Body_14
Definition Label.hpp:53
bool Create(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0)
Definition StaticBox.cpp:51
void messureSize()
Definition TextInput.cpp:343
virtual void OnEdit()
Definition TextInput.hpp:81
wxTextCtrl * text_ctrl
Definition TextInput.hpp:22

References Label::Body_14, StaticBox::Create(), icon, label_color, messureSize(), OnEdit(), style, text_color, and text_ctrl.

Referenced by ComboBox::ComboBox(), and TextInput().

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

◆ DoSetSize()

void TextInput::DoSetSize ( int x,
int y,
int width,
int height,
int sizeFlags = wxSIZE_AUTO )
overrideprotectedvirtual
211{
212 wxWindow::DoSetSize(x, y, width, height, sizeFlags);
213 if (sizeFlags & wxSIZE_USE_EXISTING) return;
214 wxSize size = GetSize();
215 wxPoint textPos = {5, 0};
216 if (this->icon.bmp().IsOk()) {
217 wxSize szIcon = this->icon.GetBmpSize();
218 textPos.x += szIcon.x;
219 }
220 if (this->icon_1.bmp().IsOk()) {
221 wxSize szIcon = this->icon_1.GetBmpSize();
222 textPos.x += (szIcon.x);
223 }
224 bool align_right = GetWindowStyle() & wxALIGN_RIGHT;
225 if (align_right)
226 textPos.x += labelSize.x;
227 if (text_ctrl) {
228 wxSize textSize = text_ctrl->GetSize();
229 textSize.x = size.x - textPos.x - labelSize.x - 10;
230 if(textSize.x < -1) textSize.x = -1;
231 text_ctrl->SetSize(textSize);
232 text_ctrl->SetPosition({textPos.x, (size.y - textSize.y) / 2});
233 }
234}
wxSize labelSize
Definition TextInput.hpp:17
ScalableBitmap icon_1
Definition TextInput.hpp:19

References icon, icon_1, labelSize, and text_ctrl.

◆ DoSetToolTipText()

void TextInput::DoSetToolTipText ( wxString const & tip)
overrideprotected
237{
238 wxWindow::DoSetToolTipText(tip);
239 text_ctrl->SetToolTip(tip);
240}

References text_ctrl.

◆ Enable()

bool TextInput::Enable ( bool enable = true)
overridevirtual
186{
187 bool result = text_ctrl->Enable(enable) && wxWindow::Enable(enable);
188 if (result) {
189 wxCommandEvent e(EVT_ENABLE_CHANGED);
190 e.SetEventObject(this);
191 GetEventHandler()->ProcessEvent(e);
192 text_ctrl->SetBackgroundColour(background_color.colorForStates(state_handler.states()));
193 text_ctrl->SetForegroundColour(text_color.colorForStates(state_handler.states()));
194 }
195 return result;
196}

References text_color, and text_ctrl.

◆ GetCornerRadius()

int TextInput::GetCornerRadius ( ) const
inline
54{ return static_cast<int>(radius); }

Referenced by CustomWidgetsPlugin::addTextInputProps().

Here is the caller graph for this function:

◆ GetTextCtrl() [1/2]

wxTextCtrl * TextInput::GetTextCtrl ( )
inline

◆ GetTextCtrl() [2/2]

wxTextCtrl const * TextInput::GetTextCtrl ( ) const
inline
78{ return text_ctrl; }

References text_ctrl.

◆ messureSize()

void TextInput::messureSize ( )
private
344{
345 wxSize size = GetSize();
346 wxClientDC dc(this);
347 bool align_right = GetWindowStyle() & wxALIGN_RIGHT;
348 if (align_right)
349 dc.SetFont(GetFont());
350 else
351 dc.SetFont(Label::Body_12);
352 labelSize = dc.GetTextExtent(wxWindow::GetLabel());
353 wxSize textSize = text_ctrl->GetSize();
354
355 if (!static_tips.empty()) {
356 static_tips_size = dc.GetTextExtent(static_tips);
357 textSize.x = std::max(labelSize.GetWidth(), static_tips_size.GetWidth());
358 textSize.y += static_tips_size.y;
359 textSize.y += 8;
360 }
361
362 int h = textSize.y + 8;
363 if (size.y < h) {
364 size.y = h;
365 }
366
367 wxSize minSize = size;
368 minSize.x = GetMinWidth();
369 SetMinSize(minSize);
370 SetSize(size);
371}
wxSize static_tips_size
Definition TextInput.hpp:25
virtual void SetMinSize(const wxSize &size) override
Definition TextInput.cpp:198
wxString static_tips
Definition TextInput.hpp:24

References Label::Body_12, labelSize, SetMinSize(), static_tips, static_tips_size, and text_ctrl.

Referenced by Create(), Rescale(), SetLabel(), and SetStaticTips().

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

◆ OnEdit()

virtual void TextInput::OnEdit ( )
inlineprotectedvirtual
81{}

Referenced by Create().

Here is the caller graph for this function:

◆ paintEvent()

void TextInput::paintEvent ( wxPaintEvent & evt)
private
243{
244 // depending on your system you may need to look at double-buffered dcs
245 wxPaintDC dc(this);
246 render(dc);
247}
void render(wxDC &dc)
Definition TextInput.cpp:254

References render().

Here is the call graph for this function:

◆ render()

void TextInput::render ( wxDC & dc)
private
255{
257 int states = state_handler.states();
258 wxSize size = GetSize();
259 bool align_center = GetWindowStyle() & wxALIGN_CENTER_HORIZONTAL;
260 bool align_right = GetWindowStyle() & wxALIGN_RIGHT;
261 // start draw
262 wxPoint pt = {5, 0};
263 if (icon.bmp().IsOk()) {
264 wxSize szIcon = icon.GetBmpSize();
265 pt.y = (size.y - szIcon.y) / 2;
266 if (align_center) {
267 if (pt.x * 2 + szIcon.x + 0 + labelSize.x < size.x)
268 pt.x = (size.x - (szIcon.x + 0 + labelSize.x)) / 2;
269 }
270 dc.DrawBitmap(icon.bmp(), pt);
271 pt.x += (szIcon.x + szIcon.x * 0.2);
272 }
273 if (icon_1.bmp().IsOk()) {
274 wxSize szIcon = icon_1.GetBmpSize();
275 pt.y = (size.y - szIcon.y) / 2;
276 if (align_center) {
277 if (pt.x * 2 + szIcon.x + 0 + labelSize.x < size.x)
278 pt.x = (size.x - (szIcon.x + 0 + labelSize.x)) / 2;
279 }
280 pt.x += szIcon.x / 4.f;
281 dc.DrawBitmap(icon_1.bmp(), pt);
282 pt.x += szIcon.x + 0;
283 }
284 auto text = wxWindow::GetLabel();
285 if (!text.IsEmpty()) {
286 if (static_tips.IsEmpty()) {
287 wxSize textSize = text_ctrl->GetSize();
288 if (align_right || align_center)
289 {
290 if (pt.x + labelSize.x + 5 > size.x)
291 text = wxControl::Ellipsize(text, dc, wxELLIPSIZE_END, size.x - pt.x - 5);
292 pt.y = (size.y - labelSize.y) / 2;
293 }
294 else
295 {
296 pt.x += textSize.x;
297 pt.y = (size.y + textSize.y) / 2 - labelSize.y;
298 }
299 dc.SetTextForeground(label_color.colorForStates(states));
300 if(align_right)
301 dc.SetFont(GetFont());
302 else
303 dc.SetFont(Label::Body_12);
304 dc.DrawText(text, pt);
305 } else {
306 wxSize textSize = text_ctrl->GetSize();
307 if (align_right || align_center) {
308 if (pt.x + labelSize.x + 5 > size.x)
309 text = wxControl::Ellipsize(text, dc, wxELLIPSIZE_END, size.x - pt.x - 5);
310 pt.y = (size.y - labelSize.y - static_tips_size.y - 8) / 2;
311 } else {
312 pt.x += textSize.x;
313 pt.y = (size.y - labelSize.y - static_tips_size.y - 8) / 2;
314 }
315 dc.SetTextForeground(label_color.colorForStates(states));
316 if(align_right)
317 dc.SetFont(GetFont());
318 else
319 dc.SetFont(Label::Body_12);
320 dc.DrawText(text, pt);
321
322 if (align_right || align_center) {
323 if (pt.x + static_tips_size.x + 5 > size.x) {
324 text = wxControl::Ellipsize(static_tips, dc, wxELLIPSIZE_END, size.x - pt.x - 5);
325 }
326
327 pt.y += (labelSize.y + 8);
328 } else {
329 pt.x += static_tips_size.x;
330 pt.y += (labelSize.y + 8);
331 }
332
333 dc.SetTextForeground(wxColour(144, 144, 144));
334
335 wxFont font = GetFont();
336 font.SetPointSize(font.GetPointSize() - 1);// use smaller font
337 dc.SetFont(font);
338 dc.DrawText(static_tips, pt);
339 }
340 }
341}
void render(wxDC &dc)
Definition StaticBox.cpp:181

References Label::Body_12, icon, icon_1, label_color, labelSize, StaticBox::render(), static_tips, static_tips_size, and text_ctrl.

Referenced by paintEvent().

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

◆ Rescale()

void TextInput::Rescale ( )
virtual
176{
177 if (!this->icon.name().empty())
178 this->icon.msw_rescale();
179 if (!this->icon_1.name().empty())
180 this->icon_1.msw_rescale();
181 messureSize();
182 Refresh();
183}

References icon, icon_1, and messureSize().

Referenced by Slic3r::GUI::LayerRangeEditor::msw_rescale(), ComboBox::Rescale(), SetIcon(), SetIcon(), SetIcon_1(), and SetIcon_1().

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

◆ SetCornerRadius()

void TextInput::SetCornerRadius ( double radius)
108{
109 this->radius = radius;
110 Refresh();
111}

Referenced by CustomWidgetsPlugin::addTextInputProps().

Here is the caller graph for this function:

◆ SetIcon() [1/2]

void TextInput::SetIcon ( const wxBitmap & icon)
129{
130 this->icon = ScalableBitmap();
131 this->icon.bmp() = icon;
132 Rescale();
133}
virtual void Rescale()
Definition TextInput.cpp:175

References icon, and Rescale().

Here is the call graph for this function:

◆ SetIcon() [2/2]

void TextInput::SetIcon ( const wxString & icon)
136{
137 if (this->icon.name() == icon.ToStdString())
138 return;
139 this->icon = ScalableBitmap(this, icon.ToStdString(), 16);
140 Rescale();
141}

References icon, and Rescale().

Here is the call graph for this function:

◆ SetIcon_1() [1/2]

void TextInput::SetIcon_1 ( const wxBitmap & icon)
156 {
157 this->icon_1 = ScalableBitmap();
158 if (icon.IsOk())
159 this->icon_1.bmp() = icon;
160 Rescale();
161}

References icon, icon_1, and Rescale().

Here is the call graph for this function:

◆ SetIcon_1() [2/2]

void TextInput::SetIcon_1 ( const wxString & icon)
143 {
144 if (this->icon_1.name() == icon.ToStdString())
145 return;
146 if (icon.empty()) {
147 this->icon_1 = ScalableBitmap();
148 return;
149 }
150 this->icon_1 = ScalableBitmap(this, icon.ToStdString(), 14);
151 Rescale();
152}

References icon, icon_1, and Rescale().

Referenced by ComboBox::SetLabel().

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

◆ SetLabel()

void TextInput::SetLabel ( const wxString & label)
override
114{
115 wxWindow::SetLabel(label);
116 messureSize();
117 Refresh();
118}

References messureSize().

Referenced by CustomWidgetsPlugin::addTextInputProps(), ComboBox::SetLabel(), and ComboBox::SetTextLabel().

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

◆ SetLabelColor()

void TextInput::SetLabelColor ( StateColor const & color)
164{
165 label_color = color;
166 state_handler.update_binds();
167}

References label_color.

Referenced by ComboBox::ComboBox().

Here is the caller graph for this function:

◆ SetMinSize()

void TextInput::SetMinSize ( const wxSize & size)
overridevirtual
199{
200 wxSize size2 = size;
201 if (size2.y < 0) {
202#ifdef __WXMAC__
203 if (GetPeer()) // peer is not ready in Create on mac
204#endif
205 size2.y = GetSize().y;
206 }
207 wxWindow::SetMinSize(size2);
208}

Referenced by messureSize().

Here is the caller graph for this function:

◆ SetStaticTips()

void TextInput::SetStaticTips ( const wxString & tips,
const wxBitmap & bitmap )
121{
122 static_tips = tips;
123 static_tips_icon = bitmap;
124 messureSize();
125 Refresh();
126}
wxBitmap static_tips_icon
Definition TextInput.hpp:26

References messureSize(), static_tips, and static_tips_icon.

Here is the call graph for this function:

◆ SetTextColor()

void TextInput::SetTextColor ( StateColor const & color)
170{
171 text_color= color;
172 state_handler.update_binds();
173}

References text_color.

Member Data Documentation

◆ icon

◆ icon_1

ScalableBitmap TextInput::icon_1
private

◆ label_color

StateColor TextInput::label_color
private

◆ labelSize

wxSize TextInput::labelSize
private

Referenced by DoSetSize(), messureSize(), and render().

◆ static_tips

wxString TextInput::static_tips
private

Referenced by messureSize(), render(), and SetStaticTips().

◆ static_tips_icon

wxBitmap TextInput::static_tips_icon
private

Referenced by SetStaticTips().

◆ static_tips_size

wxSize TextInput::static_tips_size
private

Referenced by messureSize(), and render().

◆ text_color

StateColor TextInput::text_color
private

◆ text_ctrl

wxTextCtrl* TextInput::text_ctrl
private

◆ TextInputHeight

const int TextInput::TextInputHeight = 50
staticprivate

◆ TextInputWidth

const int TextInput::TextInputWidth = 200
staticprivate

The documentation for this class was generated from the following files:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/Widgets/TextInput.hpp
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/Widgets/TextInput.cpp