Fixed rescale of the MainFrame/SettingsDialog after switching between settings layouts on the 2 monitors with different DPI

This commit is contained in:
YuSanka 2020-09-04 10:08:54 +02:00
parent c49221c621
commit ba87a4fd9a
2 changed files with 40 additions and 1 deletions

View File

@ -231,6 +231,7 @@ private:
} }
#endif // wxVERSION_EQUAL_OR_GREATER_THAN #endif // wxVERSION_EQUAL_OR_GREATER_THAN
*/ */
m_force_rescale = false;
#if !wxVERSION_EQUAL_OR_GREATER_THAN(3,1,3) #if !wxVERSION_EQUAL_OR_GREATER_THAN(3,1,3)
// rescale fonts of all controls // rescale fonts of all controls
scale_controls_fonts(this, m_new_font_point_size); scale_controls_fonts(this, m_new_font_point_size);

View File

@ -310,8 +310,10 @@ void MainFrame::update_layout()
m_plater_page = nullptr; m_plater_page = nullptr;
} }
/*
if (m_layout == ESettingsLayout::Dlg) if (m_layout == ESettingsLayout::Dlg)
rescale_dialog_after_dpi_change(*this, m_settings_dialog, ERescaleTarget::Mainframe); rescale_dialog_after_dpi_change(*this, m_settings_dialog, ERescaleTarget::Mainframe);
*/
clean_sizer(m_main_sizer); clean_sizer(m_main_sizer);
clean_sizer(m_settings_dialog.GetSizer()); clean_sizer(m_settings_dialog.GetSizer());
@ -347,6 +349,14 @@ void MainFrame::update_layout()
if (m_layout != ESettingsLayout::Unknown) if (m_layout != ESettingsLayout::Unknown)
restore_to_creation(); restore_to_creation();
enum class State {
noUpdate,
fromDlg,
toDlg
};
State update_scaling_state = m_layout == ESettingsLayout::Dlg ? State::fromDlg :
layout == ESettingsLayout::Dlg ? State::toDlg : State::noUpdate;
m_layout = layout; m_layout = layout;
// From the very beginning the Print settings should be selected // From the very beginning the Print settings should be selected
@ -384,7 +394,7 @@ void MainFrame::update_layout()
m_tabpanel->Reparent(&m_settings_dialog); m_tabpanel->Reparent(&m_settings_dialog);
m_settings_dialog.GetSizer()->Add(m_tabpanel, 1, wxEXPAND); m_settings_dialog.GetSizer()->Add(m_tabpanel, 1, wxEXPAND);
rescale_dialog_after_dpi_change(*this, m_settings_dialog, ERescaleTarget::SettingsDialog); // rescale_dialog_after_dpi_change(*this, m_settings_dialog, ERescaleTarget::SettingsDialog);
m_tabpanel->Show(); m_tabpanel->Show();
m_plater->Show(); m_plater->Show();
@ -400,6 +410,34 @@ void MainFrame::update_layout()
#endif // ENABLE_GCODE_VIEWER #endif // ENABLE_GCODE_VIEWER
} }
if (update_scaling_state != State::noUpdate)
{
int mainframe_dpi = get_dpi_for_window(this);
int dialog_dpi = get_dpi_for_window(&m_settings_dialog);
if (mainframe_dpi != dialog_dpi) {
wxSize oldDPI = update_scaling_state == State::fromDlg ? wxSize(dialog_dpi, dialog_dpi) : wxSize(mainframe_dpi, mainframe_dpi);
wxSize newDPI = update_scaling_state == State::toDlg ? wxSize(dialog_dpi, dialog_dpi) : wxSize(mainframe_dpi, mainframe_dpi);
if (update_scaling_state == State::fromDlg)
this->enable_force_rescale();
else
(&m_settings_dialog)->enable_force_rescale();
wxWindow* win { nullptr };
if (update_scaling_state == State::fromDlg)
win = this;
else
win = &m_settings_dialog;
#if wxVERSION_EQUAL_OR_GREATER_THAN(3,1,3)
m_tabpanel->MSWUpdateOnDPIChange(oldDPI, newDPI);
win->GetEventHandler()->AddPendingEvent(wxDPIChangedEvent(oldDPI, newDPI));
#else
win->GetEventHandler()->AddPendingEvent(DpiChangedEvent(EVT_DPI_CHANGED_SLICER, newDPI, win->GetRect()));
#endif // wxVERSION_EQUAL_OR_GREATER_THAN
}
}
//#ifdef __APPLE__ //#ifdef __APPLE__
// // Using SetMinSize() on Mac messes up the window position in some cases // // Using SetMinSize() on Mac messes up the window position in some cases
// // cf. https://groups.google.com/forum/#!topic/wx-users/yUKPBBfXWO0 // // cf. https://groups.google.com/forum/#!topic/wx-users/yUKPBBfXWO0