mirror of
https://github.com/QIDITECH/QIDISlicer.git
synced 2026-02-04 09:58:44 +03:00
PRUSA 2.7.0
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
#include "TextInput.hpp"
|
||||
#include "Label.hpp"
|
||||
#include "TextCtrl.h"
|
||||
#include "slic3r/GUI/Widgets/Label.hpp"
|
||||
#include "UIColors.hpp"
|
||||
|
||||
#include <wx/dcgraph.h>
|
||||
#include <wx/panel.h>
|
||||
|
||||
#include "slic3r/GUI/GUI_App.hpp"
|
||||
|
||||
BEGIN_EVENT_TABLE(TextInput, wxPanel)
|
||||
|
||||
@@ -23,12 +24,9 @@ TextInput::TextInput()
|
||||
, text_color(std::make_pair(0x909090, (int) StateColor::Disabled),
|
||||
std::make_pair(0x262E30, (int) StateColor::Normal))
|
||||
{
|
||||
if (Slic3r::GUI::wxGetApp().suppress_round_corners())
|
||||
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,
|
||||
@@ -54,14 +52,17 @@ void TextInput::Create(wxWindow * parent,
|
||||
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 = new wxTextCtrl(this, wxID_ANY, text, {4, 4}, size, style | wxBORDER_NONE);
|
||||
#ifdef __WXOSX__
|
||||
text_ctrl->OSXDisableAllSmartSubstitutions();
|
||||
#endif // __WXOSX__
|
||||
text_ctrl->SetInitialSize(text_ctrl->GetBestSize());
|
||||
text_ctrl->SetBackgroundColour(background_color.colorForStates(state_handler.states()));
|
||||
text_ctrl->SetForegroundColour(text_color.colorForStates(state_handler.states()));
|
||||
if (parent) {
|
||||
SetBackgroundColour(parent->GetBackgroundColour());
|
||||
SetForegroundColour(parent->GetForegroundColour());
|
||||
}
|
||||
state_handler.attach_child(text_ctrl);
|
||||
text_ctrl->Bind(wxEVT_KILL_FOCUS, [this](auto &e) {
|
||||
OnEdit();
|
||||
@@ -74,18 +75,17 @@ void TextInput::Create(wxWindow * parent,
|
||||
e.SetId(GetId());
|
||||
ProcessEventLocally(e);
|
||||
});
|
||||
text_ctrl->Bind(wxEVT_RIGHT_DOWN, [this](auto &e) {}); // disable context menu
|
||||
text_ctrl->Bind(wxEVT_TEXT, [this](auto &e) {
|
||||
e.SetId(GetId());
|
||||
ProcessEventLocally(e);
|
||||
});
|
||||
text_ctrl->Bind(wxEVT_RIGHT_DOWN, [](auto &e) {}); // disable context menu
|
||||
if (!icon.IsEmpty()) {
|
||||
this->icon = ScalableBitmap(this, icon.ToStdString(), 16);
|
||||
this->drop_down_icon = ScalableBitmap(this, icon.ToStdString(), 16);
|
||||
}
|
||||
messureSize();
|
||||
}
|
||||
|
||||
void TextInput::SetCornerRadius(double radius)
|
||||
{
|
||||
this->radius = radius;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void TextInput::SetLabel(const wxString& label)
|
||||
{
|
||||
@@ -94,10 +94,54 @@ void TextInput::SetLabel(const wxString& label)
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void TextInput::SetIcon(const wxBitmap &icon)
|
||||
bool TextInput::SetBackgroundColour(const wxColour& colour)
|
||||
{
|
||||
this->icon.get_bitmap() = icon;
|
||||
Rescale();
|
||||
const int clr_background_disabled = Slic3r::GUI::wxGetApp().dark_mode() ? clr_background_disabled_dark : clr_background_disabled_light;
|
||||
const StateColor clr_state( std::make_pair(clr_background_disabled, (int)StateColor::Disabled),
|
||||
std::make_pair(clr_background_focused, (int)StateColor::Checked),
|
||||
std::make_pair(colour, (int)StateColor::Focused),
|
||||
std::make_pair(colour, (int)StateColor::Normal));
|
||||
|
||||
SetBackgroundColor(clr_state);
|
||||
if (text_ctrl)
|
||||
text_ctrl->SetBackgroundColour(colour);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TextInput::SetForegroundColour(const wxColour& colour)
|
||||
{
|
||||
const StateColor clr_state( std::make_pair(clr_foreground_disabled, (int)StateColor::Disabled),
|
||||
std::make_pair(colour, (int)StateColor::Normal));
|
||||
|
||||
SetLabelColor(clr_state);
|
||||
SetTextColor (clr_state);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void TextInput::SetValue(const wxString& value)
|
||||
{
|
||||
if (text_ctrl)
|
||||
text_ctrl->SetValue(value);
|
||||
}
|
||||
|
||||
wxString TextInput::GetValue()
|
||||
{
|
||||
if (text_ctrl)
|
||||
return text_ctrl->GetValue();
|
||||
return wxEmptyString;
|
||||
}
|
||||
|
||||
void TextInput::SetSelection(long from, long to)
|
||||
{
|
||||
if (text_ctrl)
|
||||
text_ctrl->SetSelection(from, to);
|
||||
}
|
||||
|
||||
void TextInput::SetIcon(const wxBitmapBundle& icon_in)
|
||||
{
|
||||
icon = icon_in;
|
||||
}
|
||||
|
||||
void TextInput::SetLabelColor(StateColor const &color)
|
||||
@@ -110,16 +154,37 @@ void TextInput::SetTextColor(StateColor const& color)
|
||||
{
|
||||
text_color= color;
|
||||
state_handler.update_binds();
|
||||
if (text_ctrl)
|
||||
text_ctrl->SetForegroundColour(text_color.colorForStates(state_handler.states()));
|
||||
}
|
||||
|
||||
void TextInput::SetBGColor(StateColor const& color)
|
||||
{
|
||||
background_color = color;
|
||||
state_handler.update_binds();
|
||||
}
|
||||
|
||||
void TextInput::SetCtrlSize(wxSize const& size)
|
||||
{
|
||||
StaticBox::SetInitialSize(size);
|
||||
Rescale();
|
||||
}
|
||||
|
||||
void TextInput::Rescale()
|
||||
{
|
||||
if (!this->icon.name().empty())
|
||||
this->icon.msw_rescale();
|
||||
if (text_ctrl)
|
||||
text_ctrl->SetInitialSize(text_ctrl->GetBestSize());
|
||||
messureSize();
|
||||
Refresh();
|
||||
}
|
||||
|
||||
bool TextInput::SetFont(const wxFont& font)
|
||||
{
|
||||
bool ret = StaticBox::SetFont(font);
|
||||
if (text_ctrl)
|
||||
return ret && text_ctrl->SetFont(font);
|
||||
return ret;
|
||||
}
|
||||
bool TextInput::Enable(bool enable)
|
||||
{
|
||||
bool result = text_ctrl->Enable(enable) && wxWindow::Enable(enable);
|
||||
@@ -151,16 +216,21 @@ void TextInput::DoSetSize(int x, int y, int width, int height, int sizeFlags)
|
||||
if (sizeFlags & wxSIZE_USE_EXISTING) return;
|
||||
wxSize size = GetSize();
|
||||
wxPoint textPos = {5, 0};
|
||||
if (this->icon.get_bitmap().IsOk()) {
|
||||
wxSize szIcon = this->icon.GetSize();
|
||||
if (this->icon.IsOk()) {
|
||||
wxSize szIcon = get_preferred_size(icon, m_parent);
|
||||
textPos.x += szIcon.x;
|
||||
}
|
||||
wxSize dd_icon_size = wxSize(0,0);
|
||||
if (this->drop_down_icon.bmp().IsOk())
|
||||
dd_icon_size = this->drop_down_icon.GetSize();
|
||||
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;
|
||||
wxClientDC dc(this);
|
||||
const int r_shift = int((dd_icon_size.x == 0 ? 3. : 2.) * dc.GetContentScaleFactor());
|
||||
textSize.x = size.x - textPos.x - labelSize.x - dd_icon_size.x - r_shift;
|
||||
text_ctrl->SetSize(textSize);
|
||||
text_ctrl->SetPosition({textPos.x, (size.y - textSize.y) / 2});
|
||||
}
|
||||
@@ -192,28 +262,38 @@ void TextInput::render(wxDC& dc)
|
||||
bool align_right = GetWindowStyle() & wxRIGHT;
|
||||
// start draw
|
||||
wxPoint pt = {5, 0};
|
||||
if (icon.get_bitmap().IsOk()) {
|
||||
wxSize szIcon = icon.GetSize();
|
||||
if (icon.IsOk()) {
|
||||
wxSize szIcon = get_preferred_size(icon, m_parent);
|
||||
pt.y = (size.y - szIcon.y) / 2;
|
||||
dc.DrawBitmap(icon.get_bitmap(), pt);
|
||||
pt.x += szIcon.x + 0;
|
||||
#ifdef __WXGTK3__
|
||||
dc.DrawBitmap(icon.GetBitmap(szIcon), pt);
|
||||
#else
|
||||
dc.DrawBitmap(icon.GetBitmapFor(m_parent), pt);
|
||||
#endif
|
||||
pt.x += szIcon.x + 5;
|
||||
}
|
||||
|
||||
// drop_down_icon draw
|
||||
wxPoint pt_r = {size.x, 0};
|
||||
if (drop_down_icon.bmp().IsOk()) {
|
||||
wxSize szIcon = drop_down_icon.GetSize();
|
||||
pt_r.x -= szIcon.x + 2;
|
||||
pt_r.y = (size.y - szIcon.y) / 2;
|
||||
dc.DrawBitmap(drop_down_icon.get_bitmap(), pt_r);
|
||||
}
|
||||
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;
|
||||
} else {
|
||||
if (pt.x + labelSize.x > pt_r.x)
|
||||
text = wxControl::Ellipsize(text, dc, wxELLIPSIZE_END, pt_r.x - pt.x);
|
||||
pt.y = (size.y - labelSize.y) / 2;
|
||||
}
|
||||
dc.SetTextForeground(label_color.colorForStates(states));
|
||||
if(align_right)
|
||||
dc.SetFont(GetFont());
|
||||
else
|
||||
dc.SetFont(Label::Body_12);
|
||||
dc.DrawText(text, pt);
|
||||
}
|
||||
}
|
||||
@@ -222,17 +302,10 @@ 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;
|
||||
}
|
||||
const wxSize textSize = text_ctrl->GetSize();
|
||||
const wxSize iconSize = drop_down_icon.bmp().IsOk() ? drop_down_icon.GetSize() : wxSize(0, 0);
|
||||
size.y = ((textSize.y > iconSize.y) ? textSize.y : iconSize.y) + 8;
|
||||
wxSize minSize = size;
|
||||
minSize.x = GetMinWidth();
|
||||
SetMinSize(minSize);
|
||||
|
||||
Reference in New Issue
Block a user