* Upgrade wxWidgets to 3.2.1 Based on prusa3d/PrusaSlicer@9a7e024 Co-authored-by: tamasmeszaros <meszaros.q@gmail.com> * Implement BitmapCache * update wxExtensions while keeping legacy items * update dc.DrawBitmap calls to use get_bitmap * Fix GetSize/Width/Height calls * update BitmapComboBox * fix ifndef in wxExtensions.hpp * update my todos to OcraftyoneTODO * Get to a compilable state Everything seems to be working (including the plater). I am not seeing any graphical issues * fix extruder color icons * fix crash on opening support tab * remove GetBmpSize method from DropDown.cpp * Update TextInput to use bitmap bundles * update a TODO after testing * fix the rendering of the icons on combobox * fix a few todos * fix WipeTowerDialog.cpp * Overhaul WipeTowerDialog Removed simple version of the dialog since BBS removed the functionality but left the code. Center the table (only seen when the table is smaller than the minimum size of the dialog) Fix issue where editing a value causes the m_min_flush_label to change colors slightly Fix an issue where changing a value or running an auto calc changes the disabled value from "-" to "0" * update a few todos * Update some todos * Show dropdown when editing is started * Update NanoSVG.cmake Update NanoSVG to work with PR #2780 * Dim the icon on ComboBox when disabled * solve ObjectDataViewModel todos leaving colPrint and colEditing cases alone as it does not seem to impact anything * Update names in wxExtensions -Rename msw_rescale to sys_color_changed -Replace GetBmpSize, GetBmpWidth, GetBmpHeight with renamed version (same name without "Bmp") Both of these changes were also made by PrusaSlicer. Original Commit: Prusa3D/PrusaSlicer@066b567 Co-authored-by: YuSanka <yusanka@gmail.com> * update BitmapCache::from_svg disable finding bundle in the cache to match load_svg update to match values used in load_svg * Update ScalableButton change the signature and remove functions/vars pertaining to a default bmp fix TODOs in ScalableButton Original Commit: Prusa3D/PrusaSlicer@066b567 Co-authored-by: YuSanka <yusanka@gmail.com> * fix up some more todos in wxExtensions * update ScalableBitmap to use bmp bundles use wxBitmapBundle by default add flag to use old scaled bitmap function (specifically to solve issue with advanced toggle) * attempt to fix macos deps build * fix ubuntu build * Revert "attempt to fix macos deps build" Mistakenly made change to wrong file This reverts commit d9c20b51216db1d409aeb0420d9d901000ad1b00. * update wxWidgets patch an attempt to fix macOS build * Remove duplicate variable from OrcaSlicer.cpp * Fix macOS build issue * Fix blank DataViewItem being added to objects list * Filament ComboBox editor updates -Add show drop down feature to ObjectTable -Call finish editing when ComboBox is closed in ObjectList * remove Apple specific declarations missed during refactor * delete old wxWidgets patch * fix ubuntu seg fault * include patch from #2926 * update patch to include wxWidgets/wxWidgets@991a74c * fix deps not compiling on Windows * update WipeTowerDialog relocates the recalculate button back to its previous position changes the wording of the tip message label add spacing below the matrix * finish patching wxWidgets from prusa3d/PrusaSlicer@f8477d1 and prusa3d/PrusaSlicer@066b567 Co-authored-by: YuSanka <yusanka@gmail.com> * fix combobox crash * revert outside plate changes --------- Co-authored-by: tamasmeszaros <meszaros.q@gmail.com> Co-authored-by: YuSanka <yusanka@gmail.com>
242 lines
7.1 KiB
C++
242 lines
7.1 KiB
C++
#include "TextInput.hpp"
|
|
#include "Label.hpp"
|
|
#include "TextCtrl.h"
|
|
#include "slic3r/GUI/Widgets/Label.hpp"
|
|
|
|
#include <wx/dcgraph.h>
|
|
|
|
BEGIN_EVENT_TABLE(TextInput, wxPanel)
|
|
|
|
EVT_PAINT(TextInput::paintEvent)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
/*
|
|
* Called by the system of by wxWidgets when the panel needs
|
|
* to be redrawn. You can also trigger this call by
|
|
* calling Refresh()/Update().
|
|
*/
|
|
|
|
TextInput::TextInput()
|
|
: label_color(std::make_pair(0x909090, (int) StateColor::Disabled),
|
|
std::make_pair(0x6B6B6B, (int) StateColor::Normal))
|
|
, text_color(std::make_pair(0x909090, (int) StateColor::Disabled),
|
|
std::make_pair(0x262E30, (int) StateColor::Normal))
|
|
{
|
|
radius = 0;
|
|
border_width = 1;
|
|
border_color = StateColor(std::make_pair(0xDBDBDB, (int) StateColor::Disabled), std::make_pair(0x009688, (int) StateColor::Hovered),
|
|
std::make_pair(0xDBDBDB, (int) StateColor::Normal));
|
|
background_color = StateColor(std::make_pair(0xF0F0F1, (int) StateColor::Disabled), std::make_pair(*wxWHITE, (int) StateColor::Normal));
|
|
SetFont(Label::Body_12);
|
|
}
|
|
|
|
TextInput::TextInput(wxWindow * parent,
|
|
wxString text,
|
|
wxString label,
|
|
wxString icon,
|
|
const wxPoint &pos,
|
|
const wxSize & size,
|
|
long style)
|
|
: TextInput()
|
|
{
|
|
Create(parent, text, label, icon, pos, size, style);
|
|
}
|
|
|
|
void TextInput::Create(wxWindow * parent,
|
|
wxString text,
|
|
wxString label,
|
|
wxString icon,
|
|
const wxPoint &pos,
|
|
const wxSize & size,
|
|
long style)
|
|
{
|
|
text_ctrl = nullptr;
|
|
StaticBox::Create(parent, wxID_ANY, pos, size, style);
|
|
wxWindow::SetLabel(label);
|
|
style &= ~wxRIGHT;
|
|
state_handler.attach({&label_color, & text_color});
|
|
state_handler.update_binds();
|
|
text_ctrl = new TextCtrl(this, wxID_ANY, text, {4, 4}, wxDefaultSize, style | wxBORDER_NONE | wxTE_PROCESS_ENTER);
|
|
text_ctrl->SetFont(Label::Body_14);
|
|
text_ctrl->SetInitialSize(text_ctrl->GetBestSize());
|
|
text_ctrl->SetBackgroundColour(background_color.colorForStates(state_handler.states()));
|
|
text_ctrl->SetForegroundColour(text_color.colorForStates(state_handler.states()));
|
|
state_handler.attach_child(text_ctrl);
|
|
text_ctrl->Bind(wxEVT_KILL_FOCUS, [this](auto &e) {
|
|
OnEdit();
|
|
e.SetId(GetId());
|
|
ProcessEventLocally(e);
|
|
e.Skip();
|
|
});
|
|
text_ctrl->Bind(wxEVT_TEXT_ENTER, [this](auto &e) {
|
|
OnEdit();
|
|
e.SetId(GetId());
|
|
ProcessEventLocally(e);
|
|
});
|
|
text_ctrl->Bind(wxEVT_RIGHT_DOWN, [this](auto &e) {}); // disable context menu
|
|
if (!icon.IsEmpty()) {
|
|
this->icon = ScalableBitmap(this, icon.ToStdString(), 16);
|
|
}
|
|
messureSize();
|
|
}
|
|
|
|
void TextInput::SetCornerRadius(double radius)
|
|
{
|
|
this->radius = radius;
|
|
Refresh();
|
|
}
|
|
|
|
void TextInput::SetLabel(const wxString& label)
|
|
{
|
|
wxWindow::SetLabel(label);
|
|
messureSize();
|
|
Refresh();
|
|
}
|
|
|
|
void TextInput::SetIcon(const wxBitmapBundle &icon_in)
|
|
{
|
|
this->icon = ScalableBitmap();
|
|
this->icon.bmp() = icon_in;
|
|
Rescale();
|
|
}
|
|
|
|
void TextInput::SetLabelColor(StateColor const &color)
|
|
{
|
|
label_color = color;
|
|
state_handler.update_binds();
|
|
}
|
|
|
|
void TextInput::SetTextColor(StateColor const& color)
|
|
{
|
|
text_color= color;
|
|
state_handler.update_binds();
|
|
}
|
|
|
|
void TextInput::Rescale()
|
|
{
|
|
if (!this->icon.name().empty())
|
|
this->icon.sys_color_changed();
|
|
messureSize();
|
|
Refresh();
|
|
}
|
|
|
|
bool TextInput::Enable(bool enable)
|
|
{
|
|
bool result = text_ctrl->Enable(enable) && wxWindow::Enable(enable);
|
|
if (result) {
|
|
wxCommandEvent e(EVT_ENABLE_CHANGED);
|
|
e.SetEventObject(this);
|
|
GetEventHandler()->ProcessEvent(e);
|
|
text_ctrl->SetBackgroundColour(background_color.colorForStates(state_handler.states()));
|
|
text_ctrl->SetForegroundColour(text_color.colorForStates(state_handler.states()));
|
|
}
|
|
return result;
|
|
}
|
|
|
|
void TextInput::SetMinSize(const wxSize& size)
|
|
{
|
|
wxSize size2 = size;
|
|
if (size2.y < 0) {
|
|
#ifdef __WXMAC__
|
|
if (GetPeer()) // peer is not ready in Create on mac
|
|
#endif
|
|
size2.y = GetSize().y;
|
|
}
|
|
wxWindow::SetMinSize(size2);
|
|
}
|
|
|
|
void TextInput::DoSetSize(int x, int y, int width, int height, int sizeFlags)
|
|
{
|
|
wxWindow::DoSetSize(x, y, width, height, sizeFlags);
|
|
if (sizeFlags & wxSIZE_USE_EXISTING) return;
|
|
wxSize size = GetSize();
|
|
wxPoint textPos = {5, 0};
|
|
if (this->icon.bmp().IsOk()) {
|
|
wxSize szIcon = this->icon.GetSize();
|
|
textPos.x += szIcon.x;
|
|
}
|
|
bool align_right = GetWindowStyle() & wxRIGHT;
|
|
if (align_right)
|
|
textPos.x += labelSize.x;
|
|
if (text_ctrl) {
|
|
wxSize textSize = text_ctrl->GetSize();
|
|
textSize.x = size.x - textPos.x - labelSize.x - 10;
|
|
text_ctrl->SetSize(textSize);
|
|
text_ctrl->SetPosition({textPos.x, (size.y - textSize.y) / 2});
|
|
}
|
|
}
|
|
|
|
void TextInput::DoSetToolTipText(wxString const &tip)
|
|
{
|
|
wxWindow::DoSetToolTipText(tip);
|
|
text_ctrl->SetToolTip(tip);
|
|
}
|
|
|
|
void TextInput::paintEvent(wxPaintEvent &evt)
|
|
{
|
|
// depending on your system you may need to look at double-buffered dcs
|
|
wxPaintDC dc(this);
|
|
render(dc);
|
|
}
|
|
|
|
/*
|
|
* Here we do the actual rendering. I put it in a separate
|
|
* method so that it can work no matter what type of DC
|
|
* (e.g. wxPaintDC or wxClientDC) is used.
|
|
*/
|
|
void TextInput::render(wxDC& dc)
|
|
{
|
|
StaticBox::render(dc);
|
|
int states = state_handler.states();
|
|
wxSize size = GetSize();
|
|
bool align_right = GetWindowStyle() & wxRIGHT;
|
|
// start draw
|
|
wxPoint pt = {5, 0};
|
|
if (icon.bmp().IsOk()) {
|
|
wxSize szIcon = get_preferred_size(icon.bmp(), m_parent);
|
|
pt.y = (size.y - szIcon.y) / 2;
|
|
dc.DrawBitmap(icon.get_bitmap(), pt);
|
|
pt.x += szIcon.x + 0;
|
|
}
|
|
auto text = wxWindow::GetLabel();
|
|
if (!text.IsEmpty()) {
|
|
wxSize textSize = text_ctrl->GetSize();
|
|
if (align_right) {
|
|
if (pt.x + labelSize.x > size.x)
|
|
text = wxControl::Ellipsize(text, dc, wxELLIPSIZE_END, size.x - pt.x);
|
|
pt.y = (size.y - labelSize.y) / 2;
|
|
} else {
|
|
pt.x += textSize.x;
|
|
pt.y = (size.y + textSize.y) / 2 - labelSize.y;
|
|
}
|
|
dc.SetTextForeground(label_color.colorForStates(states));
|
|
if(align_right)
|
|
dc.SetFont(GetFont());
|
|
else
|
|
dc.SetFont(Label::Body_12);
|
|
dc.DrawText(text, pt);
|
|
}
|
|
}
|
|
|
|
void TextInput::messureSize()
|
|
{
|
|
wxSize size = GetSize();
|
|
wxClientDC dc(this);
|
|
bool align_right = GetWindowStyle() & wxRIGHT;
|
|
if (align_right)
|
|
dc.SetFont(GetFont());
|
|
else
|
|
dc.SetFont(Label::Body_12);
|
|
labelSize = dc.GetTextExtent(wxWindow::GetLabel());
|
|
wxSize textSize = text_ctrl->GetSize();
|
|
int h = textSize.y + 8;
|
|
if (size.y < h) {
|
|
size.y = h;
|
|
}
|
|
wxSize minSize = size;
|
|
minSize.x = GetMinWidth();
|
|
SetMinSize(minSize);
|
|
SetSize(size);
|
|
}
|