mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-13 23:15:58 +08:00
WIP (NewUI with fonts): Next improvements for fonts.
* Fixed new font applying for TreeCtrl and DataViewCtrl * Fixed update of the em_unit in respect to the new font size + MSW specific: Fixed re-scaling of the non-standard buttons
This commit is contained in:
parent
a4767695ea
commit
f27ad88d55
@ -154,7 +154,14 @@ bool BitmapTextRenderer::Render(wxRect rect, wxDC *dc, int state)
|
|||||||
// workaround for Windows DarkMode : Don't respect to the state & wxDATAVIEW_CELL_SELECTED to avoid update of the text color
|
// workaround for Windows DarkMode : Don't respect to the state & wxDATAVIEW_CELL_SELECTED to avoid update of the text color
|
||||||
RenderText(m_value.GetText(), xoffset, rect, dc, state & wxDATAVIEW_CELL_SELECTED ? 0 :state);
|
RenderText(m_value.GetText(), xoffset, rect, dc, state & wxDATAVIEW_CELL_SELECTED ? 0 :state);
|
||||||
#else
|
#else
|
||||||
|
{
|
||||||
|
wxDataViewCtrl* const view = GetView();
|
||||||
|
if (GetAttr().HasFont())
|
||||||
|
dc->SetFont(GetAttr().GetEffectiveFont(view->GetFont()));
|
||||||
|
else
|
||||||
|
dc->SetFont(view->GetFont());
|
||||||
RenderText(m_value.GetText(), xoffset, rect, dc, state);
|
RenderText(m_value.GetText(), xoffset, rect, dc, state);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -165,22 +172,22 @@ wxSize BitmapTextRenderer::GetSize() const
|
|||||||
if (!m_value.GetText().empty())
|
if (!m_value.GetText().empty())
|
||||||
{
|
{
|
||||||
wxSize size;
|
wxSize size;
|
||||||
|
wxDataViewCtrl* const view = GetView();
|
||||||
|
wxClientDC dc(view);
|
||||||
|
if (GetAttr().HasFont())
|
||||||
|
dc.SetFont(GetAttr().GetEffectiveFont(view->GetFont()));
|
||||||
|
else
|
||||||
|
dc.SetFont(view->GetFont());
|
||||||
|
|
||||||
#if defined(SUPPORTS_MARKUP) && defined(wxHAS_GENERIC_DATAVIEWCTRL)
|
#if defined(SUPPORTS_MARKUP) && defined(wxHAS_GENERIC_DATAVIEWCTRL)
|
||||||
if (m_markupText)
|
if (m_markupText)
|
||||||
{
|
|
||||||
wxDataViewCtrl* const view = GetView();
|
|
||||||
wxClientDC dc(view);
|
|
||||||
if (GetAttr().HasFont())
|
|
||||||
dc.SetFont(GetAttr().GetEffectiveFont(view->GetFont()));
|
|
||||||
|
|
||||||
size = m_markupText->Measure(dc);
|
size = m_markupText->Measure(dc);
|
||||||
|
|
||||||
int lines = m_value.GetText().Freq('\n') + 1;
|
|
||||||
size.SetHeight(size.GetHeight() * lines);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
#endif // SUPPORTS_MARKUP && wxHAS_GENERIC_DATAVIEWCTRL
|
#endif // SUPPORTS_MARKUP && wxHAS_GENERIC_DATAVIEWCTRL
|
||||||
size = GetTextExtent(m_value.GetText());
|
size = dc.GetTextExtent(m_value.GetText());
|
||||||
|
|
||||||
|
int lines = m_value.GetText().Freq('\n') + 1;
|
||||||
|
size.SetHeight(size.GetHeight() * lines);
|
||||||
|
|
||||||
if (m_value.GetBitmap().IsOk())
|
if (m_value.GetBitmap().IsOk())
|
||||||
size.x += m_value.GetBitmap().GetWidth() + 4;
|
size.x += m_value.GetBitmap().GetWidth() + 4;
|
||||||
|
@ -94,17 +94,13 @@ 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) {
|
if (font_point_size > 0)
|
||||||
m_font_size = font_point_size;
|
|
||||||
m_normal_font.SetPointSize(font_point_size);
|
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.
|
||||||
*/
|
*/
|
||||||
#ifndef __WXOSX__ // Don't call SetFont under OSX to avoid name cutting in ObjectList
|
|
||||||
this->SetFont(m_normal_font);
|
this->SetFont(m_normal_font);
|
||||||
#endif
|
|
||||||
this->CenterOnParent();
|
this->CenterOnParent();
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
update_dark_ui(this);
|
update_dark_ui(this);
|
||||||
@ -113,7 +109,13 @@ public:
|
|||||||
// Linux specific issue : get_dpi_for_window(this) still doesn't responce to the Display's scale in new wxWidgets(3.1.3).
|
// Linux specific issue : get_dpi_for_window(this) still doesn't responce to the Display's scale in new wxWidgets(3.1.3).
|
||||||
// So, calculate the m_em_unit value from the font size, as before
|
// So, calculate the m_em_unit value from the font size, as before
|
||||||
#if !defined(__WXGTK__)
|
#if !defined(__WXGTK__)
|
||||||
m_em_unit = std::max<size_t>(10/*m_font_size*/, int(m_scale_factor * m_font_size));
|
#ifdef _WIN32
|
||||||
|
const double font_to_em_koef = 10./9.;// Default font point size on Windows is 9 pt
|
||||||
|
#else // ifdef __WXOSX__
|
||||||
|
const double font_to_em_koef = 10./11.;// Default font point size on OSX is 11 pt
|
||||||
|
#endif
|
||||||
|
m_em_unit_from_font_size = int(font_to_em_koef * m_normal_font.GetPointSize());
|
||||||
|
m_em_unit = std::max<int>(10, int(m_scale_factor * m_em_unit_from_font_size));
|
||||||
#else
|
#else
|
||||||
// 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);
|
||||||
@ -198,7 +200,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
float m_scale_factor;
|
float m_scale_factor;
|
||||||
int m_em_unit;
|
int m_em_unit;
|
||||||
int m_font_size {10};
|
int m_em_unit_from_font_size {10};
|
||||||
|
|
||||||
wxFont m_normal_font;
|
wxFont m_normal_font;
|
||||||
float m_prev_scale_factor;
|
float m_prev_scale_factor;
|
||||||
@ -247,7 +249,7 @@ private:
|
|||||||
m_normal_font = this->GetFont();
|
m_normal_font = this->GetFont();
|
||||||
|
|
||||||
// update em_unit value for new window font
|
// update em_unit value for new window font
|
||||||
m_em_unit = std::max<int>(m_font_size, int(m_scale_factor * m_font_size));
|
m_em_unit = std::max<int>(10, int(m_scale_factor * m_em_unit_from_font_size));
|
||||||
|
|
||||||
// rescale missed controls sizes and images
|
// rescale missed controls sizes and images
|
||||||
on_dpi_changed(suggested_rect);
|
on_dpi_changed(suggested_rect);
|
||||||
|
@ -2305,15 +2305,7 @@ SettingsDialog::SettingsDialog(MainFrame* mainframe)
|
|||||||
if (wxGetApp().is_gcode_viewer())
|
if (wxGetApp().is_gcode_viewer())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
#if defined(__WXMSW__)
|
// this->SetFont(wxGetApp().normal_font());
|
||||||
// ys_FIXME! temporary workaround for correct font scaling
|
|
||||||
// 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
|
|
||||||
this->SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
|
|
||||||
#else
|
|
||||||
this->SetFont(wxGetApp().normal_font());
|
|
||||||
// this->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
|
|
||||||
#endif // __WXMSW__
|
|
||||||
|
|
||||||
// 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
|
||||||
|
@ -3712,6 +3712,7 @@ void Tab::rebuild_page_tree()
|
|||||||
continue;
|
continue;
|
||||||
auto itemId = m_treectrl->AppendItem(rootItem, translate_category(p->title(), m_type), p->iconID());
|
auto itemId = m_treectrl->AppendItem(rootItem, translate_category(p->title(), m_type), p->iconID());
|
||||||
m_treectrl->SetItemTextColour(itemId, p->get_item_colour());
|
m_treectrl->SetItemTextColour(itemId, p->get_item_colour());
|
||||||
|
m_treectrl->SetItemFont(itemId, wxGetApp().normal_font());
|
||||||
if (translate_category(p->title(), m_type) == selected)
|
if (translate_category(p->title(), m_type) == selected)
|
||||||
item = itemId;
|
item = itemId;
|
||||||
}
|
}
|
||||||
|
@ -839,13 +839,7 @@ UnsavedChangesDialog::UnsavedChangesDialog(Preset::Type type, PresetCollection*
|
|||||||
|
|
||||||
void UnsavedChangesDialog::build(Preset::Type type, PresetCollection* dependent_presets, const std::string& new_selected_preset, const wxString& header)
|
void UnsavedChangesDialog::build(Preset::Type type, PresetCollection* dependent_presets, const std::string& new_selected_preset, const wxString& header)
|
||||||
{
|
{
|
||||||
#if defined(__WXMSW__)
|
|
||||||
// ys_FIXME! temporary workaround for correct font scaling
|
|
||||||
// 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
|
|
||||||
// this->SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
|
|
||||||
this->SetFont(wxGetApp().normal_font());
|
this->SetFont(wxGetApp().normal_font());
|
||||||
#endif // __WXMSW__
|
|
||||||
|
|
||||||
int border = 10;
|
int border = 10;
|
||||||
int em = em_unit();
|
int em = em_unit();
|
||||||
@ -1338,7 +1332,7 @@ void UnsavedChangesDialog::on_dpi_changed(const wxRect& suggested_rect)
|
|||||||
{
|
{
|
||||||
int em = em_unit();
|
int em = em_unit();
|
||||||
|
|
||||||
msw_buttons_rescale(this, em, { wxID_CANCEL, m_save_btn_id, m_move_btn_id, m_continue_btn_id });
|
msw_buttons_rescale(this, em, { wxID_CANCEL, m_save_btn_id, m_move_btn_id, m_continue_btn_id }, 1.5);
|
||||||
|
|
||||||
const wxSize& size = wxSize(70 * em, 30 * em);
|
const wxSize& size = wxSize(70 * em, 30 * em);
|
||||||
SetMinSize(size);
|
SetMinSize(size);
|
||||||
@ -1485,6 +1479,7 @@ void DiffPresetDialog::create_presets_sizer()
|
|||||||
auto add_preset_combobox = [collection, sizer, new_type, this](PresetComboBox** cb_, PresetBundle* preset_bundle) {
|
auto add_preset_combobox = [collection, sizer, new_type, this](PresetComboBox** cb_, PresetBundle* preset_bundle) {
|
||||||
*cb_ = new PresetComboBox(this, new_type, wxSize(em_unit() * 35, -1), preset_bundle);
|
*cb_ = new PresetComboBox(this, new_type, wxSize(em_unit() * 35, -1), preset_bundle);
|
||||||
PresetComboBox*cb = (*cb_);
|
PresetComboBox*cb = (*cb_);
|
||||||
|
cb->SetFont(this->GetFont());
|
||||||
cb->show_modif_preset_separately();
|
cb->show_modif_preset_separately();
|
||||||
cb->set_selection_changed_function([this, new_type, preset_bundle, cb](int selection) {
|
cb->set_selection_changed_function([this, new_type, preset_bundle, cb](int selection) {
|
||||||
std::string preset_name = Preset::remove_suffix_modified(cb->GetString(selection).ToUTF8().data());
|
std::string preset_name = Preset::remove_suffix_modified(cb->GetString(selection).ToUTF8().data());
|
||||||
@ -1549,6 +1544,7 @@ void DiffPresetDialog::create_info_lines()
|
|||||||
void DiffPresetDialog::create_tree()
|
void DiffPresetDialog::create_tree()
|
||||||
{
|
{
|
||||||
m_tree = new DiffViewCtrl(this, wxSize(em_unit() * 65, em_unit() * 40));
|
m_tree = new DiffViewCtrl(this, wxSize(em_unit() * 65, em_unit() * 40));
|
||||||
|
m_tree->SetFont(this->GetFont());
|
||||||
m_tree->AppendToggleColumn_(L"\u2714", DiffModel::colToggle, wxLinux ? 9 : 6);
|
m_tree->AppendToggleColumn_(L"\u2714", DiffModel::colToggle, wxLinux ? 9 : 6);
|
||||||
m_tree->AppendBmpTextColumn("", DiffModel::colIconText, 35);
|
m_tree->AppendBmpTextColumn("", DiffModel::colIconText, 35);
|
||||||
m_tree->AppendBmpTextColumn(_L("Left Preset Value"), DiffModel::colOldValue, 15);
|
m_tree->AppendBmpTextColumn(_L("Left Preset Value"), DiffModel::colOldValue, 15);
|
||||||
@ -1670,17 +1666,9 @@ void DiffPresetDialog::complete_dialog_creation()
|
|||||||
}
|
}
|
||||||
|
|
||||||
DiffPresetDialog::DiffPresetDialog(MainFrame* mainframe)
|
DiffPresetDialog::DiffPresetDialog(MainFrame* mainframe)
|
||||||
: DPIDialog(mainframe, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER),
|
: DPIDialog(mainframe, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER, "diff_presets_dialog", mainframe->normal_font().GetPointSize()),
|
||||||
m_pr_technology(wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology())
|
m_pr_technology(wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology())
|
||||||
{
|
{
|
||||||
#if defined(__WXMSW__)
|
|
||||||
// ys_FIXME! temporary workaround for correct font scaling
|
|
||||||
// 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
|
|
||||||
// this->SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
|
|
||||||
this->SetFont(mainframe->normal_font());
|
|
||||||
#endif // __WXMSW__
|
|
||||||
|
|
||||||
// Init bundles
|
// Init bundles
|
||||||
|
|
||||||
assert(wxGetApp().preset_bundle);
|
assert(wxGetApp().preset_bundle);
|
||||||
|
@ -372,9 +372,9 @@ void edit_tooltip(wxString& tooltip)
|
|||||||
/* Function for rescale of buttons in Dialog under MSW if dpi is changed.
|
/* Function for rescale of buttons in Dialog under MSW if dpi is changed.
|
||||||
* btn_ids - vector of buttons identifiers
|
* btn_ids - vector of buttons identifiers
|
||||||
*/
|
*/
|
||||||
void msw_buttons_rescale(wxDialog* dlg, const int em_unit, const std::vector<int>& btn_ids)
|
void msw_buttons_rescale(wxDialog* dlg, const int em_unit, const std::vector<int>& btn_ids, double height_koef/* = 1.*/)
|
||||||
{
|
{
|
||||||
const wxSize& btn_size = wxSize(-1, int(2.5f * em_unit + 0.5f));
|
const wxSize& btn_size = wxSize(-1, int(2.5 * em_unit * height_koef + 0.5f));
|
||||||
|
|
||||||
for (int btn_id : btn_ids) {
|
for (int btn_id : btn_ids) {
|
||||||
// There is a case [FirmwareDialog], when we have wxControl instead of wxButton
|
// There is a case [FirmwareDialog], when we have wxControl instead of wxButton
|
||||||
|
@ -50,7 +50,7 @@ void enable_menu_item(wxUpdateUIEvent& evt, std::function<bool()> const cb_condi
|
|||||||
class wxDialog;
|
class wxDialog;
|
||||||
|
|
||||||
void edit_tooltip(wxString& tooltip);
|
void edit_tooltip(wxString& tooltip);
|
||||||
void msw_buttons_rescale(wxDialog* dlg, const int em_unit, const std::vector<int>& btn_ids);
|
void msw_buttons_rescale(wxDialog* dlg, const int em_unit, const std::vector<int>& btn_ids, double height_koef = 1.);
|
||||||
int em_unit(wxWindow* win);
|
int em_unit(wxWindow* win);
|
||||||
int mode_icon_px_size();
|
int mode_icon_px_size();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user