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:
Ocraftyone 2023-12-21 03:27:02 -05:00 committed by GitHub
parent 401ac1adef
commit 53d752b606
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 148 additions and 93 deletions

View file

@ -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();