mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-12-02 15:21:03 -07:00
Fix wx issues from upgrade (#3032)
* fix top bar resizing
* Attempt to fix bitmap bundle scaling issues
* Revert "Attempt to fix bitmap bundle scaling issues"
This reverts commit e94ba58d90.
* Fix AboutDialog and partially fix SwitchButton
* Fix switch button scaling on windows
* Fix dropdown icon size
* fixed sdcard/recording/timelapse icon size in device page
* Set use_legacy_bmp to true by default to it's back compatible
---------
Co-authored-by: Noisyfox <timemanager.rick@gmail.com>
Co-authored-by: SoftFever <softfeverever@gmail.com>
This commit is contained in:
parent
401ac1adef
commit
53d752b606
9 changed files with 148 additions and 93 deletions
|
|
@ -9,8 +9,8 @@
|
|||
|
||||
SwitchButton::SwitchButton(wxWindow* parent, wxWindowID id)
|
||||
: wxBitmapToggleButton(parent, id, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE | wxBU_EXACTFIT)
|
||||
, m_on(this, "toggle_on", 16, false, false, true)
|
||||
, m_off(this, "toggle_off", 16, false, false, true)
|
||||
, m_on(this, "toggle_on", {28, 16})
|
||||
, m_off(this, "toggle_off", {28, 16})
|
||||
, text_color(std::pair{0xfffffe, (int) StateColor::Checked}, std::pair{0x6B6B6B, (int) StateColor::Normal})
|
||||
, track_color(0xD9D9D9)
|
||||
, thumb_color(std::pair{0x009688, (int) StateColor::Checked}, std::pair{0xD9D9D9, (int) StateColor::Normal})
|
||||
|
|
@ -101,7 +101,8 @@ void SwitchButton::Rescale()
|
|||
for (int i = 0; i < 2; ++i) {
|
||||
wxMemoryDC memdc(&dc);
|
||||
#ifdef __WXMSW__
|
||||
wxBitmap bmp(trackSize.x, trackSize.y);
|
||||
wxBitmap bmp;
|
||||
bmp.CreateWithDIPSize(ToDIP(trackSize), GetDPIScaleFactor());
|
||||
memdc.SelectObject(bmp);
|
||||
memdc.SetBackground(wxBrush(GetBackgroundColour()));
|
||||
memdc.Clear();
|
||||
|
|
@ -145,4 +146,5 @@ void SwitchButton::Rescale()
|
|||
void SwitchButton::update()
|
||||
{
|
||||
SetBitmap((GetValue() ? m_on : m_off).bmp());
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ void TextInput::Create(wxWindow * parent,
|
|||
});
|
||||
text_ctrl->Bind(wxEVT_RIGHT_DOWN, [this](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();
|
||||
}
|
||||
|
|
@ -96,9 +96,7 @@ void TextInput::SetLabel(const wxString& label)
|
|||
|
||||
void TextInput::SetIcon(const wxBitmapBundle &icon_in)
|
||||
{
|
||||
this->icon = ScalableBitmap();
|
||||
this->icon.bmp() = icon_in;
|
||||
Rescale();
|
||||
icon = icon_in;
|
||||
}
|
||||
|
||||
void TextInput::SetLabelColor(StateColor const &color)
|
||||
|
|
@ -115,8 +113,9 @@ void TextInput::SetTextColor(StateColor const& color)
|
|||
|
||||
void TextInput::Rescale()
|
||||
{
|
||||
if (!this->icon.name().empty())
|
||||
this->icon.sys_color_changed();
|
||||
if (text_ctrl)
|
||||
text_ctrl->SetInitialSize(text_ctrl->GetBestSize());
|
||||
|
||||
messureSize();
|
||||
Refresh();
|
||||
}
|
||||
|
|
@ -152,16 +151,22 @@ 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.bmp().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});
|
||||
}
|
||||
|
|
@ -193,12 +198,26 @@ void TextInput::render(wxDC& dc)
|
|||
bool align_right = GetWindowStyle() & wxRIGHT;
|
||||
// start draw
|
||||
wxPoint pt = {5, 0};
|
||||
if (icon.bmp().IsOk()) {
|
||||
wxSize szIcon = get_preferred_size(icon.bmp(), m_parent);
|
||||
if (icon.IsOk()) {
|
||||
wxSize szIcon = get_preferred_size(icon, m_parent);
|
||||
pt.y = (size.y - szIcon.y) / 2;
|
||||
dc.DrawBitmap(icon.get_bitmap(), pt);
|
||||
#ifdef __WXGTK3__
|
||||
dc.DrawBitmap(icon.GetBitmap(szIcon), pt);
|
||||
#else
|
||||
dc.DrawBitmap(icon.GetBitmapFor(m_parent), pt);
|
||||
#endif
|
||||
pt.x += szIcon.x + 0;
|
||||
}
|
||||
|
||||
// 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();
|
||||
|
|
|
|||
|
|
@ -8,10 +8,11 @@ class TextInput : public wxNavigationEnabled<StaticBox>
|
|||
{
|
||||
|
||||
wxSize labelSize;
|
||||
ScalableBitmap icon;
|
||||
wxBitmapBundle icon;
|
||||
ScalableBitmap drop_down_icon;
|
||||
StateColor label_color;
|
||||
StateColor text_color;
|
||||
wxTextCtrl * text_ctrl;
|
||||
wxTextCtrl* text_ctrl{nullptr};
|
||||
|
||||
static const int TextInputWidth = 200;
|
||||
static const int TextInputHeight = 50;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue