Code cleaning and last msw_rescale() improvements
This commit is contained in:
parent
415877d79e
commit
12133f9599
@ -64,6 +64,12 @@ public:
|
|||||||
m_prev_scale_factor = m_scale_factor;
|
m_prev_scale_factor = m_scale_factor;
|
||||||
m_normal_font = get_default_font_for_dpi(dpi);
|
m_normal_font = get_default_font_for_dpi(dpi);
|
||||||
|
|
||||||
|
/* Because of default window font is a primary display font,
|
||||||
|
* We should set correct font for window before getting em_unit value.
|
||||||
|
*/
|
||||||
|
#ifndef __WXOSX__ // Don't call SetFont under OSX to avoid name cutting in ObjectList
|
||||||
|
this->SetFont(m_normal_font);
|
||||||
|
#endif
|
||||||
// initialize default width_unit according to the width of the one symbol ("m") of the currently active font of this window.
|
// initialize default width_unit according to the width of the one symbol ("m") of the currently active font of this window.
|
||||||
m_em_unit = std::max<size_t>(10, this->GetTextExtent("m").x - 1);
|
m_em_unit = std::max<size_t>(10, this->GetTextExtent("m").x - 1);
|
||||||
|
|
||||||
@ -139,19 +145,7 @@ private:
|
|||||||
// check if new scale is differ from previous
|
// check if new scale is differ from previous
|
||||||
bool is_new_scale_factor() const { return fabs(m_scale_factor - m_prev_scale_factor) > 0.001; }
|
bool is_new_scale_factor() const { return fabs(m_scale_factor - m_prev_scale_factor) > 0.001; }
|
||||||
|
|
||||||
// recursive function for scaling fonts for all controls in Window
|
// function for a font scaling of the window
|
||||||
void scale_controls_fonts(wxWindow *window, const float scale_f)
|
|
||||||
{
|
|
||||||
auto children = window->GetChildren();
|
|
||||||
|
|
||||||
for (auto child : children) {
|
|
||||||
scale_controls_fonts(child, scale_f);
|
|
||||||
child->SetFont(child->GetFont().Scaled(scale_f));
|
|
||||||
}
|
|
||||||
|
|
||||||
window->Layout();
|
|
||||||
}
|
|
||||||
|
|
||||||
void scale_win_font(wxWindow *window, const int font_point_size)
|
void scale_win_font(wxWindow *window, const int font_point_size)
|
||||||
{
|
{
|
||||||
wxFont new_font(window->GetFont());
|
wxFont new_font(window->GetFont());
|
||||||
@ -175,22 +169,18 @@ private:
|
|||||||
void rescale(const wxRect &suggested_rect)
|
void rescale(const wxRect &suggested_rect)
|
||||||
{
|
{
|
||||||
this->Freeze();
|
this->Freeze();
|
||||||
// const float relative_scale_factor = m_scale_factor / m_prev_scale_factor;
|
|
||||||
|
|
||||||
// rescale fonts of all controls
|
// rescale fonts of all controls
|
||||||
// scale_controls_fonts(this, relative_scale_factor);
|
|
||||||
scale_controls_fonts(this, m_new_font_point_size);
|
scale_controls_fonts(this, m_new_font_point_size);
|
||||||
|
// rescale current window font
|
||||||
// this->SetFont(this->GetFont().Scaled(relative_scale_factor));
|
|
||||||
scale_win_font(this, m_new_font_point_size);
|
scale_win_font(this, m_new_font_point_size);
|
||||||
|
|
||||||
|
|
||||||
// rescale normal_font value
|
// set normal application font as a current window font
|
||||||
// m_normal_font = m_normal_font.Scaled(relative_scale_factor);
|
|
||||||
m_normal_font = this->GetFont();
|
m_normal_font = this->GetFont();
|
||||||
|
|
||||||
// An analog of em_unit value from GUI_App.
|
// update em_unit value for new window font
|
||||||
m_em_unit = std::max<size_t>(10, 10 * m_scale_factor);
|
m_em_unit = std::max<size_t>(10, this->GetTextExtent("m").x - 1);
|
||||||
|
|
||||||
// rescale missed controls sizes and images
|
// rescale missed controls sizes and images
|
||||||
on_dpi_changed(suggested_rect);
|
on_dpi_changed(suggested_rect);
|
||||||
|
@ -38,10 +38,12 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_S
|
|||||||
{
|
{
|
||||||
// Fonts were created by the DPIFrame constructor for the monitor, on which the window opened.
|
// Fonts were created by the DPIFrame constructor for the monitor, on which the window opened.
|
||||||
wxGetApp().update_fonts(this);
|
wxGetApp().update_fonts(this);
|
||||||
|
/*
|
||||||
#ifndef __WXOSX__ // Don't call SetFont under OSX to avoid name cutting in ObjectList
|
#ifndef __WXOSX__ // Don't call SetFont under OSX to avoid name cutting in ObjectList
|
||||||
this->SetFont(this->normal_font());
|
this->SetFont(this->normal_font());
|
||||||
#endif
|
#endif
|
||||||
|
// Font is already set in DPIFrame constructor
|
||||||
|
*/
|
||||||
// Load the icon either from the exe, or from the ico file.
|
// Load the icon either from the exe, or from the ico file.
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user