Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
BitmapTextRenderer Class Reference

#include <src/slic3r/GUI/ExtraRenderers.hpp>

+ Inheritance diagram for BitmapTextRenderer:
+ Collaboration diagram for BitmapTextRenderer:

Public Member Functions

 BitmapTextRenderer (bool use_markup=false, wxDataViewCellMode mode=wxDATAVIEW_CELL_EDITABLE, int align=wxDVR_DEFAULT_ALIGNMENT)
 
 ~BitmapTextRenderer ()
 
void EnableMarkup (bool enable=true)
 
bool SetValue (const wxVariant &value) override
 
bool GetValue (wxVariant &value) const override
 
virtual bool Render (wxRect cell, wxDC *dc, int state) override
 
virtual wxSize GetSize () const override
 
bool HasEditorCtrl () const override
 
wxWindow * CreateEditorCtrl (wxWindow *parent, wxRect labelRect, const wxVariant &value) override
 
bool GetValueFromEditorCtrl (wxWindow *ctrl, wxVariant &value) override
 
bool WasCanceled () const
 
void set_can_create_editor_ctrl_function (std::function< bool()> can_create_fn)
 

Private Attributes

DataViewBitmapText m_value
 
bool m_was_unusable_symbol { false }
 
std::function< bool()> can_create_editor_ctrl { nullptr }
 

Detailed Description

Constructor & Destructor Documentation

◆ BitmapTextRenderer()

BitmapTextRenderer::BitmapTextRenderer ( bool  use_markup = false,
wxDataViewCellMode  mode = wxDATAVIEW_CELL_EDITABLE,
int  align = wxDVR_DEFAULT_ALIGNMENT 
)
inline
78 :
79 wxDataViewCustomRenderer(wxT("DataViewBitmapText"), mode, align)
80 {
81 EnableMarkup(use_markup);
82 }
void EnableMarkup(bool enable=true)
Definition ExtraRenderers.cpp:68

◆ ~BitmapTextRenderer()

BitmapTextRenderer::~BitmapTextRenderer ( )
60{
61#ifdef SUPPORTS_MARKUP
62 #ifdef wxHAS_GENERIC_DATAVIEWCTRL
63 delete m_markupText;
64 #endif //wxHAS_GENERIC_DATAVIEWCTRL
65#endif // SUPPORTS_MARKUP
66}

Member Function Documentation

◆ CreateEditorCtrl()

wxWindow * BitmapTextRenderer::CreateEditorCtrl ( wxWindow *  parent,
wxRect  labelRect,
const wxVariant &  value 
)
override
190{
192 return nullptr;
193
195 data << value;
196
197 m_was_unusable_symbol = false;
198
199 wxPoint position = labelRect.GetPosition();
200 if (data.GetBitmap().IsOk()) {
201 const int bmp_width = data.GetBitmap().GetWidth();
202 position.x += bmp_width;
203 labelRect.SetWidth(labelRect.GetWidth() - bmp_width);
204 }
205
206#ifdef __WXMSW__
207 // Case when from some reason we try to create next EditorCtrl till old one was not deleted
208 if (auto children = parent->GetChildren(); children.GetCount() > 0)
209 for (auto child : children)
210 if (dynamic_cast<wxTextCtrl*>(child)) {
211 parent->RemoveChild(child);
212 child->Destroy();
213 break;
214 }
215#endif // __WXMSW__
216
217 wxTextCtrl* text_editor = new wxTextCtrl(parent, wxID_ANY, data.GetText(),
218 position, labelRect.GetSize(), wxTE_PROCESS_ENTER);
219 text_editor->SetInsertionPointEnd();
220 text_editor->SelectAll();
221
222 return text_editor;
223}
bool m_was_unusable_symbol
Definition ExtraRenderers.hpp:114
std::function< bool()> can_create_editor_ctrl
Definition ExtraRenderers.hpp:116
Definition ExtraRenderers.hpp:17
if(!(yy_init))
Definition lexer.c:1190
constexpr auto data(C &c) -> decltype(c.data())
Definition span.hpp:195

References can_create_editor_ctrl, and m_was_unusable_symbol.

◆ EnableMarkup()

void BitmapTextRenderer::EnableMarkup ( bool  enable = true)
69{
70#ifdef SUPPORTS_MARKUP
71#ifdef wxHAS_GENERIC_DATAVIEWCTRL
72 if (enable) {
73 if (!m_markupText)
74 m_markupText = new wxItemMarkupText(wxString());
75 }
76 else {
77 if (m_markupText) {
78 delete m_markupText;
79 m_markupText = nullptr;
80 }
81 }
82#else
83 is_markupText = enable;
84#endif //wxHAS_GENERIC_DATAVIEWCTRL
85#endif // SUPPORTS_MARKUP
86}

◆ GetSize()

wxSize BitmapTextRenderer::GetSize ( ) const
overridevirtual
160{
161 if (!m_value.GetText().empty())
162 {
163 wxSize size;
164#if defined(SUPPORTS_MARKUP) && defined(wxHAS_GENERIC_DATAVIEWCTRL)
165 if (m_markupText)
166 {
167 wxDataViewCtrl* const view = GetView();
168 wxClientDC dc(view);
169 if (GetAttr().HasFont())
170 dc.SetFont(GetAttr().GetEffectiveFont(view->GetFont()));
171
172 size = m_markupText->Measure(dc);
173
174 int lines = m_value.GetText().Freq('\n') + 1;
175 size.SetHeight(size.GetHeight() * lines);
176 }
177 else
178#endif // SUPPORTS_MARKUP && wxHAS_GENERIC_DATAVIEWCTRL
179 size = GetTextExtent(m_value.GetText());
180
181 if (m_value.GetBitmap().IsOk())
182 size.x += m_value.GetBitmap().GetWidth() + 4;
183 return size;
184 }
185 return wxSize(80, 20);
186}
DataViewBitmapText m_value
Definition ExtraRenderers.hpp:113
const wxBitmap & GetBitmap() const
Definition ExtraRenderers.hpp:34
wxString GetText() const
Definition ExtraRenderers.hpp:32
constexpr auto size(const C &c) -> decltype(c.size())
Definition span.hpp:183

References DataViewBitmapText::GetBitmap(), DataViewBitmapText::GetText(), and m_value.

+ Here is the call graph for this function:

◆ GetValue()

bool BitmapTextRenderer::GetValue ( wxVariant &  value) const
override
113{
114 return false;
115}

◆ GetValueFromEditorCtrl()

bool BitmapTextRenderer::GetValueFromEditorCtrl ( wxWindow *  ctrl,
wxVariant &  value 
)
override
226{
227 wxTextCtrl* text_editor = wxDynamicCast(ctrl, wxTextCtrl);
228 if (!text_editor || text_editor->GetValue().IsEmpty())
229 return false;
230
233 return false;
234
235 // The icon can't be edited so get its old value and reuse it.
236 wxVariant valueOld;
237 GetView()->GetModel()->GetValue(valueOld, m_item, /*colName*/0);
238
239 DataViewBitmapText bmpText;
240 bmpText << valueOld;
241
242 // But replace the text with the value entered by user.
243 bmpText.SetText(text_editor->GetValue());
244
245 value << bmpText;
246 return true;
247}
void SetText(const wxString &text)
Definition ExtraRenderers.hpp:31
static bool has_illegal_filename_characters(const wxString &name)
Definition Plater.cpp:143

References Slic3r::GUI::Plater::has_illegal_filename_characters(), m_was_unusable_symbol, and DataViewBitmapText::SetText().

+ Here is the call graph for this function:

◆ HasEditorCtrl()

bool BitmapTextRenderer::HasEditorCtrl ( ) const
inlineoverride
99 {
100#ifdef __WXOSX__
101 return false;
102#else
103 return true;
104#endif
105 }

◆ Render()

bool BitmapTextRenderer::Render ( wxRect  cell,
wxDC *  dc,
int  state 
)
overridevirtual
130{
131 int xoffset = 0;
132
133 const wxBitmap& icon = m_value.GetBitmap();
134 if (icon.IsOk())
135 {
136 wxSize icon_sz = get_size(icon);
137 dc->DrawBitmap(icon, rect.x, rect.y + (rect.height - icon_sz.y) / 2);
138 xoffset = icon_sz.x + 4;
139 }
140
141#if defined(SUPPORTS_MARKUP) && defined(wxHAS_GENERIC_DATAVIEWCTRL)
142 if (m_markupText)
143 {
144 rect.x += xoffset;
145 m_markupText->Render(GetView(), *dc, rect, 0, GetEllipsizeMode());
146 }
147 else
148#endif // SUPPORTS_MARKUP && wxHAS_GENERIC_DATAVIEWCTRL
149#ifdef _WIN32
150 // workaround for Windows DarkMode : Don't respect to the state & wxDATAVIEW_CELL_SELECTED to avoid update of the text color
151 RenderText(m_value.GetText(), xoffset, rect, dc, state & wxDATAVIEW_CELL_SELECTED ? 0 :state);
152#else
153 RenderText(m_value.GetText(), xoffset, rect, dc, state);
154#endif
155
156 return true;
157}
IMGUI_API void RenderText(ImVec2 pos, const char *text, const char *text_end=NULL, bool hide_text_after_hash=true)
Definition imgui.cpp:2665

References DataViewBitmapText::GetBitmap(), DataViewBitmapText::GetText(), and m_value.

+ Here is the call graph for this function:

◆ set_can_create_editor_ctrl_function()

void BitmapTextRenderer::set_can_create_editor_ctrl_function ( std::function< bool()>  can_create_fn)
inline
110{ can_create_editor_ctrl = can_create_fn; }

References can_create_editor_ctrl.

Referenced by Slic3r::GUI::ObjectList::create_objects_ctrl().

+ Here is the caller graph for this function:

◆ SetValue()

bool BitmapTextRenderer::SetValue ( const wxVariant &  value)
override
89{
90 m_value << value;
91
92#ifdef SUPPORTS_MARKUP
93#ifdef wxHAS_GENERIC_DATAVIEWCTRL
94 if (m_markupText)
95 m_markupText->SetMarkup(m_value.GetText());
96 /*
97#else
98#if defined(__WXGTK__)
99 GValue gvalue = G_VALUE_INIT;
100 g_value_init(&gvalue, G_TYPE_STRING);
101 g_value_set_string(&gvalue, wxGTK_CONV_FONT(str.GetText(), GetOwner()->GetOwner()->GetFont()));
102 g_object_set_property(G_OBJECT(m_renderer/ *.GetText()* /), is_markupText ? "markup" : "text", &gvalue);
103 g_value_unset(&gvalue);
104#endif // __WXGTK__
105 */
106#endif // wxHAS_GENERIC_DATAVIEWCTRL
107#endif // SUPPORTS_MARKUP
108
109 return true;
110}

References DataViewBitmapText::GetText(), and m_value.

+ Here is the call graph for this function:

◆ WasCanceled()

bool BitmapTextRenderer::WasCanceled ( ) const
inline
108{ return m_was_unusable_symbol; }

References m_was_unusable_symbol.

Member Data Documentation

◆ can_create_editor_ctrl

std::function<bool()> BitmapTextRenderer::can_create_editor_ctrl { nullptr }
private

◆ m_value

DataViewBitmapText BitmapTextRenderer::m_value
private

Referenced by GetSize(), Render(), and SetValue().

◆ m_was_unusable_symbol

bool BitmapTextRenderer::m_was_unusable_symbol { false }
private

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