Experiments with font size

This commit is contained in:
YuSanka 2023-01-30 17:06:27 +01:00 committed by Oleksandra Yushchenko
parent 4475753247
commit 4764a701c1
10 changed files with 101 additions and 16 deletions

View File

@ -1322,7 +1322,7 @@ bool GUI_App::on_init_inner()
if (!delayed_error_load_presets.empty()) if (!delayed_error_load_presets.empty())
show_error(nullptr, delayed_error_load_presets); show_error(nullptr, delayed_error_load_presets);
mainframe = new MainFrame(); mainframe = new MainFrame(app_config->has("font_size") ? atoi(app_config->get("font_size").c_str()) : -1);
// hide settings tabs after first Layout // hide settings tabs after first Layout
if (is_editor()) if (is_editor())
mainframe->select_tab(size_t(0)); mainframe->select_tab(size_t(0));
@ -1810,7 +1810,7 @@ void GUI_App::recreate_GUI(const wxString& msg_name)
dlg.Update(10, _L("Recreating") + dots); dlg.Update(10, _L("Recreating") + dots);
MainFrame *old_main_frame = mainframe; MainFrame *old_main_frame = mainframe;
mainframe = new MainFrame(); mainframe = new MainFrame(app_config->has("font_size") ? atoi(app_config->get("font_size").c_str()) : -1);
if (is_editor()) if (is_editor())
// hide settings tabs after first Layout // hide settings tabs after first Layout
mainframe->select_tab(size_t(0)); mainframe->select_tab(size_t(0));

View File

@ -82,7 +82,7 @@ template<class P> class DPIAware : public P
{ {
public: public:
DPIAware(wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &pos=wxDefaultPosition, DPIAware(wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &pos=wxDefaultPosition,
const wxSize &size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE, const wxString &name=wxFrameNameStr) const wxSize &size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE, const wxString &name= wxFrameNameStr, const int font_point_size = -1)
: P(parent, id, title, pos, size, style, name) : P(parent, id, title, pos, size, style, name)
{ {
int dpi = get_dpi_for_window(this); int dpi = get_dpi_for_window(this);
@ -90,6 +90,9 @@ public:
m_prev_scale_factor = m_scale_factor; m_prev_scale_factor = m_scale_factor;
m_normal_font = get_default_font_for_dpi(this, dpi); m_normal_font = get_default_font_for_dpi(this, dpi);
if (font_point_size > 0)
m_normal_font.SetPointSize(font_point_size);
/* Because of default window font is a primary display font, /* Because of default window font is a primary display font,
* We should set correct font for window before getting em_unit value. * We should set correct font for window before getting em_unit value.
*/ */

View File

@ -122,8 +122,8 @@ static wxIcon main_frame_icon(GUI_App::EAppMode app_mode)
#endif // _WIN32 #endif // _WIN32
} }
MainFrame::MainFrame() : MainFrame::MainFrame(const int font_point_size) :
DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, "mainframe"), DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, "mainframe", font_point_size),
m_printhost_queue_dlg(new PrintHostQueueDialog(this)) m_printhost_queue_dlg(new PrintHostQueueDialog(this))
, m_recent_projects(9) , m_recent_projects(9)
, m_settings_dialog(this) , m_settings_dialog(this)
@ -1540,6 +1540,7 @@ void MainFrame::init_menubar_as_editor()
// assign menubar to frame after appending items, otherwise special items // assign menubar to frame after appending items, otherwise special items
// will not be handled correctly // will not be handled correctly
m_menubar = new wxMenuBar(); m_menubar = new wxMenuBar();
m_menubar->SetFont(this->normal_font());
m_menubar->Append(fileMenu, _L("&File")); m_menubar->Append(fileMenu, _L("&File"));
if (editMenu) m_menubar->Append(editMenu, _L("&Edit")); if (editMenu) m_menubar->Append(editMenu, _L("&Edit"));
m_menubar->Append(windowMenu, _L("&Window")); m_menubar->Append(windowMenu, _L("&Window"));
@ -2237,7 +2238,7 @@ std::string MainFrame::get_dir_name(const wxString &full_name) const
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
SettingsDialog::SettingsDialog(MainFrame* mainframe) SettingsDialog::SettingsDialog(MainFrame* mainframe)
:DPIFrame(NULL, wxID_ANY, wxString(SLIC3R_APP_NAME) + " - " + _L("Settings"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, "settings_dialog"), :DPIFrame(NULL, wxID_ANY, wxString(SLIC3R_APP_NAME) + " - " + _L("Settings"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, "settings_dialog", mainframe->normal_font().GetPointSize()),
//: DPIDialog(mainframe, wxID_ANY, wxString(SLIC3R_APP_NAME) + " - " + _L("Settings"), wxDefaultPosition, wxDefaultSize, //: DPIDialog(mainframe, wxID_ANY, wxString(SLIC3R_APP_NAME) + " - " + _L("Settings"), wxDefaultPosition, wxDefaultSize,
// wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMINIMIZE_BOX | wxMAXIMIZE_BOX, "settings_dialog"), // wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMINIMIZE_BOX | wxMAXIMIZE_BOX, "settings_dialog"),
m_main_frame(mainframe) m_main_frame(mainframe)

View File

@ -139,7 +139,7 @@ protected:
virtual void on_sys_color_changed() override; virtual void on_sys_color_changed() override;
public: public:
MainFrame(); MainFrame(const int font_point_size);
~MainFrame() = default; ~MainFrame() = default;
void update_layout(); void update_layout();

View File

@ -136,7 +136,7 @@ static void add_msg_content(wxWindow* parent, wxBoxSizer* content_sizer, wxStrin
msg_lines++; msg_lines++;
} }
wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); wxFont font = wxGetApp().normal_font();//wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
wxFont monospace = wxGetApp().code_font(); wxFont monospace = wxGetApp().code_font();
wxColour text_clr = wxGetApp().get_label_clr_default(); wxColour text_clr = wxGetApp().get_label_clr_default();
wxColour bgr_clr = parent->GetBackgroundColour(); wxColour bgr_clr = parent->GetBackgroundColour();

View File

@ -4,6 +4,7 @@
#include "Plater.hpp" #include "Plater.hpp"
#include "MsgDialog.hpp" #include "MsgDialog.hpp"
#include "I18N.hpp" #include "I18N.hpp"
#include "format.hpp"
#include "libslic3r/AppConfig.hpp" #include "libslic3r/AppConfig.hpp"
#include <wx/notebook.h> #include <wx/notebook.h>
#include "Notebook.hpp" #include "Notebook.hpp"
@ -549,6 +550,7 @@ void PreferencesDialog::build()
create_settings_mode_widget(); create_settings_mode_widget();
create_settings_text_color_widget(); create_settings_text_color_widget();
create_settings_mode_color_widget(); create_settings_mode_color_widget();
// create_settings_font_widget();
m_optgroup_other = create_options_tab(_L("Other"), tabs); m_optgroup_other = create_options_tab(_L("Other"), tabs);
m_optgroup_other->m_on_change = [this](t_config_option_key opt_key, boost::any value) { m_optgroup_other->m_on_change = [this](t_config_option_key opt_key, boost::any value) {
@ -580,6 +582,7 @@ void PreferencesDialog::build()
activate_options_tab(m_optgroup_other); activate_options_tab(m_optgroup_other);
create_downloader_path_sizer(); create_downloader_path_sizer();
create_settings_font_widget();
#if ENABLE_ENVIRONMENT_MAP #if ENABLE_ENVIRONMENT_MAP
// Add "Render" tab // Add "Render" tab
@ -694,7 +697,7 @@ void PreferencesDialog::accept(wxEvent&)
bool update_filament_sidebar = (m_values.find("no_templates") != m_values.end()); bool update_filament_sidebar = (m_values.find("no_templates") != m_values.end());
std::vector<std::string> options_to_recreate_GUI = { "no_defaults", "tabs_as_menu", "sys_menu_enabled" }; std::vector<std::string> options_to_recreate_GUI = { "no_defaults", "tabs_as_menu", "sys_menu_enabled", "font_size" };
for (const std::string& option : options_to_recreate_GUI) { for (const std::string& option : options_to_recreate_GUI) {
if (m_values.find(option) != m_values.end()) { if (m_values.find(option) != m_values.end()) {
@ -943,7 +946,6 @@ void PreferencesDialog::create_icon_size_slider()
void PreferencesDialog::create_settings_mode_widget() void PreferencesDialog::create_settings_mode_widget()
{ {
wxWindow* parent = m_optgroup_gui->parent(); wxWindow* parent = m_optgroup_gui->parent();
wxGetApp().UpdateDarkUI(parent);
wxString title = L("Layout Options"); wxString title = L("Layout Options");
wxStaticBox* stb = new wxStaticBox(parent, wxID_ANY, _(title)); wxStaticBox* stb = new wxStaticBox(parent, wxID_ANY, _(title));
@ -1045,6 +1047,74 @@ void PreferencesDialog::create_settings_mode_color_widget()
append_preferences_option_to_searcher(m_optgroup_gui, opt_key, title); append_preferences_option_to_searcher(m_optgroup_gui, opt_key, title);
} }
void PreferencesDialog::create_settings_font_widget()
{
wxWindow* parent = m_optgroup_other->parent();
wxGetApp().UpdateDarkUI(parent);
const wxString title = L("Application font size");
wxStaticBox* stb = new wxStaticBox(parent, wxID_ANY, _(title));
if (!wxOSX) stb->SetBackgroundStyle(wxBG_STYLE_PAINT);
const std::string opt_key = "font_size";
m_blinkers[opt_key] = new BlinkingBitmap(parent);
wxSizer* stb_sizer = new wxStaticBoxSizer(stb, wxHORIZONTAL);
wxStaticText* font_example = new wxStaticText(parent, wxID_ANY, "Application text");
int val = wxGetApp().normal_font().GetPointSize();
wxSpinCtrl* size_sc = new wxSpinCtrl(parent, wxID_ANY, format_wxstr("%1%", val), wxDefaultPosition, wxSize(15*em_unit(), -1), wxTE_PROCESS_ENTER | wxSP_ARROW_KEYS
#ifdef _WIN32
| wxBORDER_SIMPLE
#endif
, 8, 20);
wxGetApp().UpdateDarkUI(size_sc);
auto apply_font = [this, font_example, opt_key](const int val, const wxFont& font) {
font_example->SetFont(font);
m_values[opt_key] = format("%1%", val);
refresh_og(m_optgroup_other);
};
auto change_value = [size_sc, apply_font](wxCommandEvent& evt) {
const int val = size_sc->GetValue();
wxFont font = wxGetApp().normal_font();
font.SetPointSize(val);
apply_font(val, font);
};
size_sc->Bind(wxEVT_SPINCTRL, change_value);
size_sc->Bind(wxEVT_TEXT_ENTER, change_value);
auto revert_btn = new ScalableButton(parent, wxID_ANY, "undo");
revert_btn->SetToolTip(_L("Revert font to default"));
revert_btn->Bind(wxEVT_BUTTON, [size_sc, apply_font](wxEvent& event) {
wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
const int val = font.GetPointSize();
size_sc->SetValue(val);
apply_font(val, font);
});
parent->Bind(wxEVT_UPDATE_UI, [size_sc](wxUpdateUIEvent& evt) {
const int def_size = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT).GetPointSize();
evt.Enable(def_size != size_sc->GetValue());
}, revert_btn->GetId());
stb_sizer->Add(new wxStaticText(parent, wxID_ANY, _L("Font size") + ":"), 0, wxALIGN_CENTER_VERTICAL | wxLEFT, em_unit());
stb_sizer->Add(size_sc, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxLEFT, em_unit());
stb_sizer->Add(revert_btn, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, em_unit());
wxBoxSizer* font_sizer = new wxBoxSizer(wxVERTICAL);
font_sizer->Add(font_example, 1, wxALIGN_CENTER_HORIZONTAL);
stb_sizer->Add(font_sizer, 1, wxALIGN_CENTER_VERTICAL);
auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(m_blinkers[opt_key], 0, wxRIGHT, 2);
sizer->Add(stb_sizer, 1, wxALIGN_CENTER_VERTICAL);
m_optgroup_other->sizer->Add(sizer, 1, wxEXPAND | wxTOP, em_unit());
append_preferences_option_to_searcer(m_optgroup_other, opt_key, title);
}
void PreferencesDialog::create_downloader_path_sizer() void PreferencesDialog::create_downloader_path_sizer()
{ {
wxWindow* parent = m_optgroup_other->parent(); wxWindow* parent = m_optgroup_other->parent();

View File

@ -91,10 +91,12 @@ protected:
void layout(); void layout();
void clear_cache(); void clear_cache();
void refresh_og(std::shared_ptr<ConfigOptionsGroup> og); void refresh_og(std::shared_ptr<ConfigOptionsGroup> og);
void refresh_og(ConfigOptionsGroup* og);
void create_icon_size_slider(); void create_icon_size_slider();
void create_settings_mode_widget(); void create_settings_mode_widget();
void create_settings_text_color_widget(); void create_settings_text_color_widget();
void create_settings_mode_color_widget(); void create_settings_mode_color_widget();
void create_settings_font_widget();
void create_downloader_path_sizer(); void create_downloader_path_sizer();
void init_highlighter(const t_config_option_key& opt_key); void init_highlighter(const t_config_option_key& opt_key);
std::vector<ConfigOptionsGroup*> optgroups(); std::vector<ConfigOptionsGroup*> optgroups();

View File

@ -311,11 +311,13 @@ SavePresetDialog::~SavePresetDialog()
void SavePresetDialog::build(std::vector<Preset::Type> types, std::string suffix, bool template_filament) void SavePresetDialog::build(std::vector<Preset::Type> types, std::string suffix, bool template_filament)
{ {
this->SetFont(wxGetApp().normal_font());
#if defined(__WXMSW__) #if defined(__WXMSW__)
// ys_FIXME! temporary workaround for correct font scaling // ys_FIXME! temporary workaround for correct font scaling
// Because of from wxWidgets 3.1.3 auto rescaling is implemented for the Fonts, // Because of from wxWidgets 3.1.3 auto rescaling is implemented for the Fonts,
// From the very beginning set dialog font to the wxSYS_DEFAULT_GUI_FONT // From the very beginning set dialog font to the wxSYS_DEFAULT_GUI_FONT
this->SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); // this->SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
#else #else
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
#endif // __WXMSW__ #endif // __WXMSW__

View File

@ -265,6 +265,7 @@ void Tab::create_preset_tab()
// tree // tree
m_treectrl = new wxTreeCtrl(panel, wxID_ANY, wxDefaultPosition, wxSize(20 * m_em_unit, -1), m_treectrl = new wxTreeCtrl(panel, wxID_ANY, wxDefaultPosition, wxSize(20 * m_em_unit, -1),
wxTR_NO_BUTTONS | wxTR_HIDE_ROOT | wxTR_SINGLE | wxTR_NO_LINES | wxBORDER_SUNKEN | wxWANTS_CHARS); wxTR_NO_BUTTONS | wxTR_HIDE_ROOT | wxTR_SINGLE | wxTR_NO_LINES | wxBORDER_SUNKEN | wxWANTS_CHARS);
m_treectrl->SetFont(wxGetApp().normal_font());
m_left_sizer->Add(m_treectrl, 1, wxEXPAND); m_left_sizer->Add(m_treectrl, 1, wxEXPAND);
// Index of the last icon inserted into m_treectrl // Index of the last icon inserted into m_treectrl
m_icon_count = -1; m_icon_count = -1;

View File

@ -837,7 +837,8 @@ void UnsavedChangesDialog::build(Preset::Type type, PresetCollection* dependent_
// ys_FIXME! temporary workaround for correct font scaling // ys_FIXME! temporary workaround for correct font scaling
// Because of from wxWidgets 3.1.3 auto rescaling is implemented for the Fonts, // Because of from wxWidgets 3.1.3 auto rescaling is implemented for the Fonts,
// From the very beginning set dialog font to the wxSYS_DEFAULT_GUI_FONT // From the very beginning set dialog font to the wxSYS_DEFAULT_GUI_FONT
this->SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); // this->SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
this->SetFont(wxGetApp().normal_font());
#endif // __WXMSW__ #endif // __WXMSW__
int border = 10; int border = 10;
@ -850,7 +851,8 @@ void UnsavedChangesDialog::build(Preset::Type type, PresetCollection* dependent_
add_new_value_column = false; add_new_value_column = false;
m_action_line = new wxStaticText(this, wxID_ANY, ""); m_action_line = new wxStaticText(this, wxID_ANY, "");
m_action_line->SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT).Bold()); // m_action_line->SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT).Bold());
m_action_line->SetFont(wxGetApp().bold_font());
m_tree = new DiffViewCtrl(this, wxSize(em * (add_new_value_column ? 80 : 60), em * 30)); m_tree = new DiffViewCtrl(this, wxSize(em * (add_new_value_column ? 80 : 60), em * 30));
m_tree->AppendToggleColumn_(L"\u2714" , DiffModel::colToggle, wxLinux ? 9 : 6); m_tree->AppendToggleColumn_(L"\u2714" , DiffModel::colToggle, wxLinux ? 9 : 6);
@ -910,7 +912,8 @@ void UnsavedChangesDialog::build(Preset::Type type, PresetCollection* dependent_
cancel_btn->Bind(wxEVT_BUTTON, [this](wxEvent&) { this->EndModal(wxID_CANCEL); }); cancel_btn->Bind(wxEVT_BUTTON, [this](wxEvent&) { this->EndModal(wxID_CANCEL); });
m_info_line = new wxStaticText(this, wxID_ANY, ""); m_info_line = new wxStaticText(this, wxID_ANY, "");
m_info_line->SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT).Bold()); // m_info_line->SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT).Bold());
m_info_line->SetFont(wxGetApp().bold_font());
m_info_line->Hide(); m_info_line->Hide();
if (!m_app_config_key.empty()) { if (!m_app_config_key.empty()) {
@ -1362,6 +1365,7 @@ FullCompareDialog::FullCompareDialog(const wxString& option_name, const wxString
: wxDialog(nullptr, wxID_ANY, option_name, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) : wxDialog(nullptr, wxID_ANY, option_name, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
{ {
wxGetApp().UpdateDarkUI(this); wxGetApp().UpdateDarkUI(this);
this->SetFont(wxGetApp().normal_font());
int border = 10; int border = 10;
bool has_new_value_column = !new_value_header.IsEmpty(); bool has_new_value_column = !new_value_header.IsEmpty();
@ -1528,7 +1532,8 @@ void DiffPresetDialog::create_show_all_presets_chb()
void DiffPresetDialog::create_info_lines() void DiffPresetDialog::create_info_lines()
{ {
const wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT).Bold(); // const wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT).Bold();
const wxFont font = GetFont().Bold();
m_top_info_line = new wxStaticText(this, wxID_ANY, _L("Select presets to compare")); m_top_info_line = new wxStaticText(this, wxID_ANY, _L("Select presets to compare"));
m_top_info_line->SetFont(font); m_top_info_line->SetFont(font);
@ -1668,7 +1673,8 @@ DiffPresetDialog::DiffPresetDialog(MainFrame* mainframe)
// ys_FIXME! temporary workaround for correct font scaling // ys_FIXME! temporary workaround for correct font scaling
// Because of from wxWidgets 3.1.3 auto rescaling is implemented for the Fonts, // Because of from wxWidgets 3.1.3 auto rescaling is implemented for the Fonts,
// From the very beginning set dialog font to the wxSYS_DEFAULT_GUI_FONT // From the very beginning set dialog font to the wxSYS_DEFAULT_GUI_FONT
this->SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); // this->SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
this->SetFont(mainframe->normal_font());
#endif // __WXMSW__ #endif // __WXMSW__
// Init bundles // Init bundles