mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-12 16:39:02 +08:00
WIP (NewUI with fonts): Improvements some controls
* SpinInput : Code refactoring * BitmapToggleButton : * Create wxBitmapToggleButton if control doesn't have a label and wxToggleButton otherwise * Linux specific: Calculate default size from label size + Tab: Linux specific: Set background color for tree_ctrl and don't set background color for Tab
This commit is contained in:
parent
1f0b834a70
commit
9cf971769d
@ -86,7 +86,7 @@ Tab::Tab(wxBookCtrlBase* parent, const wxString& title, Preset::Type type) :
|
|||||||
|
|
||||||
#ifdef __WXMSW__
|
#ifdef __WXMSW__
|
||||||
wxGetApp().UpdateDarkUI(this);
|
wxGetApp().UpdateDarkUI(this);
|
||||||
#else
|
#elif __WXOSX__
|
||||||
SetBackgroundColour(parent->GetBackgroundColour());
|
SetBackgroundColour(parent->GetBackgroundColour());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -296,6 +296,9 @@ void Tab::create_preset_tab()
|
|||||||
m_treectrl = new wxTreeCtrl(panel, wxID_ANY, wxDefaultPosition, wxSize(20 * m_em_unit, -1),
|
m_treectrl = new wxTreeCtrl(panel, wxID_ANY, wxDefaultPosition, wxSize(20 * m_em_unit, -1),
|
||||||
wxTR_NO_BUTTONS | wxTR_HIDE_ROOT | wxTR_SINGLE | wxTR_NO_LINES | wxBORDER_SUNKEN | wxWANTS_CHARS);
|
wxTR_NO_BUTTONS | wxTR_HIDE_ROOT | wxTR_SINGLE | wxTR_NO_LINES | wxBORDER_SUNKEN | wxWANTS_CHARS);
|
||||||
m_treectrl->SetFont(wxGetApp().normal_font());
|
m_treectrl->SetFont(wxGetApp().normal_font());
|
||||||
|
#ifdef __linux__
|
||||||
|
m_treectrl->SetBackgroundColour(m_parent->GetBackgroundColour());
|
||||||
|
#endif
|
||||||
m_left_sizer->Add(m_treectrl, 1, wxEXPAND);
|
m_left_sizer->Add(m_treectrl, 1, wxEXPAND);
|
||||||
// Index of the last icon inserted into m_treectrl
|
// Index of the last icon inserted into m_treectrl
|
||||||
m_icon_count = -1;
|
m_icon_count = -1;
|
||||||
|
@ -73,7 +73,7 @@ class SubstitutionManager
|
|||||||
std::function<void()> m_cb_hide_delete_all_btn{ nullptr };
|
std::function<void()> m_cb_hide_delete_all_btn{ nullptr };
|
||||||
|
|
||||||
std::vector<std::string> m_substitutions;
|
std::vector<std::string> m_substitutions;
|
||||||
std::vector<wxCheckBox*> m_chb_match_single_lines;
|
std::vector<wxWindow*> m_chb_match_single_lines;
|
||||||
|
|
||||||
void validate_length();
|
void validate_length();
|
||||||
bool is_compatible_with_ui();
|
bool is_compatible_with_ui();
|
||||||
|
@ -4,17 +4,17 @@
|
|||||||
|
|
||||||
BitmapToggleButton::BitmapToggleButton(wxWindow* parent, const wxString& label, wxWindowID id)
|
BitmapToggleButton::BitmapToggleButton(wxWindow* parent, const wxString& label, wxWindowID id)
|
||||||
{
|
{
|
||||||
|
if (label.IsEmpty())
|
||||||
|
wxBitmapToggleButton::Create(parent, id, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE | wxBU_EXACTFIT);
|
||||||
|
else {
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
long style = wxBORDER_NONE | wxBU_EXACTFIT;
|
wxSize def_size = wxSize(parent->GetTextExtent(label).GetX() + 20, 20);
|
||||||
if (label.IsEmpty())
|
|
||||||
style = style | wxBU_NOTEXT;
|
|
||||||
// Call Create() from wxToggleButton instead of wxBitmapToggleButton to allow add Label text under Linux
|
|
||||||
wxToggleButton::Create(parent, id, label, wxDefaultPosition, wxDefaultSize, style);
|
|
||||||
#else
|
#else
|
||||||
wxBitmapToggleButton::Create(parent, id, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE | wxBU_EXACTFIT);
|
wxSize def_size = wxDefaultSize;
|
||||||
if (!label.IsEmpty())
|
|
||||||
SetLabel(label);
|
|
||||||
#endif
|
#endif
|
||||||
|
// Call Create() from wxToggleButton instead of wxBitmapToggleButton to allow add Label text under Linux
|
||||||
|
wxToggleButton::Create(parent, id, label, wxDefaultPosition, def_size, wxBORDER_NONE | wxBU_EXACTFIT);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __WXMSW__
|
#ifdef __WXMSW__
|
||||||
if (parent) {
|
if (parent) {
|
||||||
@ -22,7 +22,7 @@ BitmapToggleButton::BitmapToggleButton(wxWindow* parent, const wxString& label,
|
|||||||
SetForegroundColour(parent->GetForegroundColour());
|
SetForegroundColour(parent->GetForegroundColour());
|
||||||
}
|
}
|
||||||
#elif __linux__
|
#elif __linux__
|
||||||
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
|
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Bind(wxEVT_TOGGLEBUTTON, [this](auto& e) {
|
Bind(wxEVT_TOGGLEBUTTON, [this](auto& e) {
|
||||||
@ -39,9 +39,14 @@ BitmapToggleButton::BitmapToggleButton(wxWindow* parent, const wxString& label,
|
|||||||
void BitmapToggleButton::update_size()
|
void BitmapToggleButton::update_size()
|
||||||
{
|
{
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
|
wxSize bmp_sz = GetBitmap().GetSize();
|
||||||
|
wxSize sz = GetSize();
|
||||||
if (GetLabel().IsEmpty())
|
if (GetLabel().IsEmpty())
|
||||||
SetSize(GetBitmap().GetSize());
|
SetSize(bmp_sz);
|
||||||
else
|
else
|
||||||
|
SetSize(sz.x, bmp_sz.y);
|
||||||
|
#else
|
||||||
|
wxSize best_sz = GetBestSize();
|
||||||
|
SetSize(best_sz);
|
||||||
#endif
|
#endif
|
||||||
SetSize(GetBestSize());
|
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,6 @@ void DropDown::Invalidate(bool clear)
|
|||||||
|
|
||||||
void DropDown::SetSelection(int n)
|
void DropDown::SetSelection(int n)
|
||||||
{
|
{
|
||||||
assert(n < (int) texts.size());
|
|
||||||
if (n >= (int) texts.size())
|
if (n >= (int) texts.size())
|
||||||
n = -1;
|
n = -1;
|
||||||
if (selection == n) return;
|
if (selection == n) return;
|
||||||
|
@ -73,8 +73,8 @@ void SpinInput::Create(wxWindow *parent,
|
|||||||
text_ctrl->Bind(wxEVT_TEXT_ENTER, &SpinInput::onTextEnter, this);
|
text_ctrl->Bind(wxEVT_TEXT_ENTER, &SpinInput::onTextEnter, this);
|
||||||
text_ctrl->Bind(wxEVT_KEY_DOWN, &SpinInput::keyPressed, this);
|
text_ctrl->Bind(wxEVT_KEY_DOWN, &SpinInput::keyPressed, this);
|
||||||
text_ctrl->Bind(wxEVT_RIGHT_DOWN, [this](auto &e) {}); // disable context menu
|
text_ctrl->Bind(wxEVT_RIGHT_DOWN, [this](auto &e) {}); // disable context menu
|
||||||
button_inc = createButton(true);
|
button_inc = create_button(ButtonId::btnIncrease);
|
||||||
button_dec = createButton(false);
|
button_dec = create_button(ButtonId::btnDecrease);
|
||||||
delta = 0;
|
delta = 0;
|
||||||
timer.Bind(wxEVT_TIMER, &SpinInput::onTimer, this);
|
timer.Bind(wxEVT_TIMER, &SpinInput::onTimer, this);
|
||||||
|
|
||||||
@ -265,11 +265,11 @@ void SpinInput::render(wxDC& dc)
|
|||||||
// draw seperator of buttons
|
// draw seperator of buttons
|
||||||
wxPoint pt = button_inc->GetPosition();
|
wxPoint pt = button_inc->GetPosition();
|
||||||
pt.y = size.y / 2;
|
pt.y = size.y / 2;
|
||||||
pt.x += 1;
|
|
||||||
dc.SetPen(wxPen(border_color.defaultColor()));
|
dc.SetPen(wxPen(border_color.defaultColor()));
|
||||||
|
|
||||||
const double scale = dc.GetContentScaleFactor();
|
const double scale = dc.GetContentScaleFactor();
|
||||||
dc.DrawLine(pt, pt + wxSize{button_inc->GetSize().x - int(3. * scale), 0});
|
const int btn_w = button_inc->GetSize().GetWidth();
|
||||||
|
dc.DrawLine(pt, pt + wxSize{ btn_w - int(scale), 0});
|
||||||
// draw label
|
// draw label
|
||||||
auto label = GetLabel();
|
auto label = GetLabel();
|
||||||
if (!label.IsEmpty()) {
|
if (!label.IsEmpty()) {
|
||||||
@ -308,16 +308,16 @@ void SpinInput::messureSize()
|
|||||||
button_dec->SetPosition({size.x - btnSize.x - int(3. * scale), size.y / 2 + 1});
|
button_dec->SetPosition({size.x - btnSize.x - int(3. * scale), size.y / 2 + 1});
|
||||||
}
|
}
|
||||||
|
|
||||||
Button *SpinInput::createButton(bool inc)
|
Button *SpinInput::create_button(ButtonId id)
|
||||||
{
|
{
|
||||||
auto btn = new Button(this, "", inc ? "spin_inc_act" : "spin_dec_act", wxBORDER_NONE, wxSize(12, 7));
|
auto btn = new Button(this, "", id == ButtonId::btnIncrease ? "spin_inc_act" : "spin_dec_act", wxBORDER_NONE, wxSize(12, 7));
|
||||||
btn->SetCornerRadius(0);
|
btn->SetCornerRadius(0);
|
||||||
btn->SetInactiveIcon(inc ? "spin_inc" : "spin_dec");
|
btn->SetInactiveIcon(id == ButtonId::btnIncrease ? "spin_inc" : "spin_dec");
|
||||||
btn->DisableFocusFromKeyboard();
|
btn->DisableFocusFromKeyboard();
|
||||||
btn->SetSelected(false);
|
btn->SetSelected(false);
|
||||||
|
|
||||||
btn->Bind(wxEVT_LEFT_DOWN, [=](auto &e) {
|
btn->Bind(wxEVT_LEFT_DOWN, [=](auto &e) {
|
||||||
delta = inc ? 1 : -1;
|
delta = id == ButtonId::btnIncrease ? 1 : -1;
|
||||||
SetValue(val + delta);
|
SetValue(val + delta);
|
||||||
text_ctrl->SetFocus();
|
text_ctrl->SetFocus();
|
||||||
btn->CaptureMouse();
|
btn->CaptureMouse();
|
||||||
@ -326,7 +326,7 @@ Button *SpinInput::createButton(bool inc)
|
|||||||
sendSpinEvent();
|
sendSpinEvent();
|
||||||
});
|
});
|
||||||
btn->Bind(wxEVT_LEFT_DCLICK, [=](auto &e) {
|
btn->Bind(wxEVT_LEFT_DCLICK, [=](auto &e) {
|
||||||
delta = inc ? 1 : -1;
|
delta = id == ButtonId::btnIncrease ? 1 : -1;
|
||||||
btn->CaptureMouse();
|
btn->CaptureMouse();
|
||||||
SetValue(val + delta);
|
SetValue(val + delta);
|
||||||
sendSpinEvent();
|
sendSpinEvent();
|
||||||
|
@ -24,6 +24,12 @@ class SpinInput : public wxNavigationEnabled<StaticBox>
|
|||||||
static const int SpinInputWidth = 200;
|
static const int SpinInputWidth = 200;
|
||||||
static const int SpinInputHeight = 50;
|
static const int SpinInputHeight = 50;
|
||||||
|
|
||||||
|
enum class ButtonId
|
||||||
|
{
|
||||||
|
btnIncrease,
|
||||||
|
btnDecrease
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SpinInput();
|
SpinInput();
|
||||||
|
|
||||||
@ -90,7 +96,7 @@ private:
|
|||||||
|
|
||||||
void messureSize();
|
void messureSize();
|
||||||
|
|
||||||
Button *createButton(bool inc);
|
Button *create_button(ButtonId id);
|
||||||
|
|
||||||
// some useful events
|
// some useful events
|
||||||
void mouseWheelMoved(wxMouseEvent& event);
|
void mouseWheelMoved(wxMouseEvent& event);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user