MSW specific: Fixed rescaling for the BitmapComboBox control and Notebook tab buttons
This commit is contained in:
parent
558336f325
commit
4b5cf004bd
9 changed files with 58 additions and 8 deletions
|
@ -166,7 +166,7 @@ int BitmapComboBox::Append(const wxString& item)
|
|||
//2. But then set width to 0 value for no using of bitmap left and right spacing
|
||||
//3. Set this empty bitmap to the at list one item and BitmapCombobox will be recreated correct
|
||||
|
||||
wxBitmap bitmap(1, this->GetFont().GetPixelSize().y + 2);
|
||||
wxBitmap bitmap(1, int(1.6 * wxGetApp().em_unit() + 1));
|
||||
bitmap.SetWidth(0);
|
||||
|
||||
OnAddBitmap(bitmap);
|
||||
|
@ -260,6 +260,21 @@ void BitmapComboBox::DrawBackground_(wxDC& dc, const wxRect& rect, int WXUNUSED(
|
|||
dc.DrawRectangle(rect);
|
||||
}
|
||||
}
|
||||
|
||||
void BitmapComboBox::Rescale()
|
||||
{
|
||||
// Next workaround: To correct scaling of a BitmapCombobox
|
||||
// we need to refill control with new bitmaps
|
||||
const wxString selection = this->GetValue();
|
||||
std::vector<wxString> items;
|
||||
for (int i = 0; i < GetCount(); i++)
|
||||
items.push_back(GetString(i));
|
||||
|
||||
this->Clear();
|
||||
for (const wxString& item : items)
|
||||
Append(item);
|
||||
this->SetValue(selection);
|
||||
}
|
||||
#endif
|
||||
|
||||
}}
|
||||
|
|
|
@ -54,6 +54,8 @@ void OnDrawItem(wxDC& dc, const wxRect& rect, int item, int flags) const overrid
|
|||
#ifdef _WIN32
|
||||
bool MSWOnDraw(WXDRAWITEMSTRUCT* item) override;
|
||||
void DrawBackground_(wxDC& dc, const wxRect& rect, int WXUNUSED(item), int flags) const;
|
||||
public:
|
||||
void Rescale();
|
||||
#endif
|
||||
|
||||
};
|
||||
|
|
|
@ -1296,6 +1296,9 @@ void Choice::msw_rescale()
|
|||
field->SetValue(selection) :
|
||||
field->SetSelection(idx);
|
||||
#else
|
||||
#ifdef _WIN32
|
||||
field->Rescale();
|
||||
#endif
|
||||
auto size = wxSize(def_width_wider() * m_em_unit, wxDefaultCoord);
|
||||
if (m_opt.height >= 0) size.SetHeight(m_opt.height * m_em_unit);
|
||||
if (m_opt.width >= 0) size.SetWidth(m_opt.width * m_em_unit);
|
||||
|
|
|
@ -106,6 +106,9 @@ void msw_rescale_word_local_combo(choice_ctrl* combo)
|
|||
|
||||
combo->SetValue(selection);
|
||||
#else
|
||||
#ifdef _WIN32
|
||||
combo->Rescale();
|
||||
#endif
|
||||
combo->SetMinSize(wxSize(15 * wxGetApp().em_unit(), -1));
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -402,6 +402,10 @@ void Preview::refresh_print()
|
|||
|
||||
void Preview::msw_rescale()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
m_choice_view_type->Rescale();
|
||||
m_choice_view_type->SetMinSize(m_choice_view_type->GetSize());
|
||||
#endif
|
||||
// rescale slider
|
||||
if (m_layers_slider != nullptr) m_layers_slider->msw_rescale();
|
||||
if (m_moves_slider != nullptr) m_moves_slider->msw_rescale();
|
||||
|
|
|
@ -17,13 +17,20 @@ ButtonsListCtrl::ButtonsListCtrl(wxWindow *parent, bool add_mode_buttons/* = fal
|
|||
SetDoubleBuffered(true);
|
||||
#endif //__WINDOWS__
|
||||
|
||||
int em = em_unit(this);// Slic3r::GUI::wxGetApp().em_unit();
|
||||
m_btn_margin = std::lround(0.3 * em);
|
||||
m_line_margin = std::lround(0.1 * em);
|
||||
|
||||
m_sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
this->SetSizer(m_sizer);
|
||||
|
||||
m_buttons_sizer = new wxFlexGridSizer(4, m_btn_margin, m_btn_margin);
|
||||
m_sizer->Add(m_buttons_sizer, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxBOTTOM, m_btn_margin);
|
||||
|
||||
if (add_mode_buttons) {
|
||||
m_mode_sizer = new ModeSizer(this, int(0.5 * em_unit(this)));
|
||||
m_mode_sizer = new ModeSizer(this, m_btn_margin);
|
||||
m_sizer->AddStretchSpacer(20);
|
||||
m_sizer->Add(m_mode_sizer, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5);
|
||||
m_sizer->Add(m_mode_sizer, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxBOTTOM, m_btn_margin);
|
||||
}
|
||||
|
||||
this->Bind(wxEVT_PAINT, &ButtonsListCtrl::OnPaint, this);
|
||||
|
@ -53,12 +60,12 @@ void ButtonsListCtrl::OnPaint(wxPaintEvent&)
|
|||
const wxColour& clr = idx == m_selection ? btn_marker_color : default_btn_bg;
|
||||
dc.SetPen(clr);
|
||||
dc.SetBrush(clr);
|
||||
dc.DrawRectangle(pos.x, sz.y - 3, size.x, 3);
|
||||
dc.DrawRectangle(pos.x, pos.y + size.y, size.x, sz.y - size.y);
|
||||
}
|
||||
|
||||
dc.SetPen(btn_marker_color);
|
||||
dc.SetBrush(btn_marker_color);
|
||||
dc.DrawRectangle(1, sz.y - 1, sz.x, 1);
|
||||
dc.DrawRectangle(1, sz.y - m_line_margin, sz.x, m_line_margin);
|
||||
}
|
||||
|
||||
void ButtonsListCtrl::UpdateMode()
|
||||
|
@ -71,6 +78,14 @@ void ButtonsListCtrl::Rescale()
|
|||
m_mode_sizer->msw_rescale();
|
||||
for (ScalableButton* btn : m_pageButtons)
|
||||
btn->msw_rescale();
|
||||
|
||||
int em = em_unit(this);
|
||||
m_btn_margin = std::lround(0.3 * em);
|
||||
m_line_margin = std::lround(0.1 * em);
|
||||
m_buttons_sizer->SetVGap(m_btn_margin);
|
||||
m_buttons_sizer->SetHGap(m_btn_margin);
|
||||
|
||||
m_sizer->Layout();
|
||||
}
|
||||
|
||||
void ButtonsListCtrl::SetSelection(int sel)
|
||||
|
@ -95,7 +110,7 @@ bool ButtonsListCtrl::InsertPage(size_t n, const wxString& text, bool bSelect/*
|
|||
});
|
||||
Slic3r::GUI::wxGetApp().UpdateDarkUI(btn);
|
||||
m_pageButtons.insert(m_pageButtons.begin() + n, btn);
|
||||
m_sizer->Insert(n, new wxSizerItem(btn, 0, wxEXPAND | wxRIGHT | wxBOTTOM, 3));
|
||||
m_buttons_sizer->Insert(n, new wxSizerItem(btn));
|
||||
m_sizer->Layout();
|
||||
return true;
|
||||
}
|
||||
|
@ -104,7 +119,7 @@ void ButtonsListCtrl::RemovePage(size_t n)
|
|||
{
|
||||
ScalableButton* btn = m_pageButtons[n];
|
||||
m_pageButtons.erase(m_pageButtons.begin() + n);
|
||||
m_sizer->Remove(n);
|
||||
m_buttons_sizer->Remove(n);
|
||||
btn->Reparent(nullptr);
|
||||
btn->Destroy();
|
||||
m_sizer->Layout();
|
||||
|
|
|
@ -29,9 +29,12 @@ public:
|
|||
|
||||
private:
|
||||
wxWindow* m_parent;
|
||||
wxFlexGridSizer* m_buttons_sizer;
|
||||
wxBoxSizer* m_sizer;
|
||||
std::vector<ScalableButton*> m_pageButtons;
|
||||
int m_selection {-1};
|
||||
int m_btn_margin;
|
||||
int m_line_margin;
|
||||
ModeSizer* m_mode_sizer {nullptr};
|
||||
};
|
||||
|
||||
|
|
|
@ -694,7 +694,9 @@ void ModeButton::focus_button(const bool focus)
|
|||
// ----------------------------------------------------------------------------
|
||||
|
||||
ModeSizer::ModeSizer(wxWindow *parent, int hgap/* = 0*/) :
|
||||
wxFlexGridSizer(3, 0, hgap)
|
||||
wxFlexGridSizer(3, 0, hgap),
|
||||
m_parent(parent),
|
||||
m_hgap_unscaled((double)(hgap)/em_unit(parent))
|
||||
{
|
||||
SetFlexibleDirection(wxHORIZONTAL);
|
||||
|
||||
|
@ -739,6 +741,7 @@ void ModeSizer::set_items_border(int border)
|
|||
|
||||
void ModeSizer::msw_rescale()
|
||||
{
|
||||
this->SetHGap(std::lround(m_hgap_unscaled * em_unit(m_parent)));
|
||||
for (size_t m = 0; m < m_mode_btns.size(); m++)
|
||||
m_mode_btns[m]->msw_rescale();
|
||||
}
|
||||
|
|
|
@ -315,6 +315,8 @@ public:
|
|||
|
||||
private:
|
||||
std::vector<ModeButton*> m_mode_btns;
|
||||
wxWindow* m_parent {nullptr};
|
||||
double m_hgap_unscaled;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue