WIP of Fixing of the re-scaling

+ TopBar: Deleted unused code
This commit is contained in:
YuSanka 2024-04-26 16:45:14 +02:00 committed by Lukas Matena
parent 95bb0b4748
commit 26d52595a8
3 changed files with 29 additions and 19 deletions

View File

@ -404,7 +404,7 @@ void MainFrame::update_layout()
{ {
m_plater->Reparent(m_tabpanel); m_plater->Reparent(m_tabpanel);
m_plater->Layout(); m_plater->Layout();
m_tabpanel->InsertNewPage(0, m_plater, _L("Plater"), std::string("plater"), true); // m_tabpanel->InsertNewPage(0, m_plater, _L("Plater"), std::string("plater"), true);
m_main_sizer->Add(m_tabpanel, 1, wxEXPAND | wxTOP, 1); m_main_sizer->Add(m_tabpanel, 1, wxEXPAND | wxTOP, 1);
m_plater->Show(); m_plater->Show();
@ -476,6 +476,9 @@ void MainFrame::update_layout()
} }
#endif //__WXMSW__ #endif //__WXMSW__
if (m_layout == ESettingsLayout::Old)
m_tabpanel->InsertNewPage(0, m_plater, _L("Plater"), "", true);
Layout(); Layout();
Thaw(); Thaw();
} }
@ -1050,7 +1053,8 @@ void MainFrame::on_dpi_changed(const wxRect& suggested_rect)
this->SetFont(this->normal_font()); this->SetFont(this->normal_font());
#ifdef _WIN32 #ifdef _WIN32
// update common mode sizer if (m_tmp_top_bar->IsShown())
m_tmp_top_bar->Rescale();
m_tabpanel->Rescale(); m_tabpanel->Rescale();
#endif #endif
@ -1062,6 +1066,10 @@ void MainFrame::on_dpi_changed(const wxRect& suggested_rect)
for (auto tab : wxGetApp().tabs_list) for (auto tab : wxGetApp().tabs_list)
tab->msw_rescale(); tab->msw_rescale();
wxGetApp().searcher().dlg_msw_rescale();
return; // #ysFIXME - delete_after_testing - It looks like next code is no need any more
// Workarounds for correct Window rendering after rescale // Workarounds for correct Window rendering after rescale
/* Even if Window is maximized during moving, /* Even if Window is maximized during moving,
@ -1082,8 +1090,6 @@ void MainFrame::on_dpi_changed(const wxRect& suggested_rect)
this->SetSize(sz); this->SetSize(sz);
this->Maximize(is_maximized); this->Maximize(is_maximized);
wxGetApp().searcher().dlg_msw_rescale();
} }
void MainFrame::on_sys_color_changed() void MainFrame::on_sys_color_changed()
@ -2242,8 +2248,9 @@ void SettingsDialog::on_dpi_changed(const wxRect& suggested_rect)
if (wxGetApp().is_gcode_viewer()) if (wxGetApp().is_gcode_viewer())
return; return;
const int& em = em_unit(); // #ysFIXME - delete_after_testing
const wxSize& size = wxSize(85 * em, 50 * em); // const int& em = em_unit();
// const wxSize& size = wxSize(85 * em, 50 * em);
#ifdef _WIN32 #ifdef _WIN32
m_tabpanel->Rescale(); m_tabpanel->Rescale();
@ -2253,9 +2260,10 @@ void SettingsDialog::on_dpi_changed(const wxRect& suggested_rect)
for (auto tab : wxGetApp().tabs_list) for (auto tab : wxGetApp().tabs_list)
tab->msw_rescale(); tab->msw_rescale();
SetMinSize(size); // #ysFIXME - delete_after_testing
Fit(); // SetMinSize(size);
Refresh(); // Fit();
// Refresh();
} }

View File

@ -170,7 +170,7 @@ TopBarItemsCtrl::ButtonWithPopup::ButtonWithPopup(wxWindow* parent, const wxStri
:TopBarItemsCtrl::Button(parent, label, icon_name, 24, size) :TopBarItemsCtrl::Button(parent, label, icon_name, 24, size)
{ {
if (size != wxDefaultSize) if (size != wxDefaultSize)
m_fixed_width = size.x; m_fixed_width = size.x * 0.1;
this->SetLabel(label); this->SetLabel(label);
} }
@ -193,7 +193,7 @@ void TopBarItemsCtrl::ButtonWithPopup::SetLabel(const wxString& label)
const int label_width = GetTextExtent(text).GetWidth(); const int label_width = GetTextExtent(text).GetWidth();
bool resize_and_layout{ false }; bool resize_and_layout{ false };
if (m_fixed_width != wxDefaultCoord) { if (m_fixed_width != wxDefaultCoord) {
const int text_width = m_fixed_width - 2 * btn_height; const int text_width = m_fixed_width * em_unit(this) - 2 * btn_height;
if (label_width > text_width || GetMinSize().GetWidth() <= btn_height) { if (label_width > text_width || GetMinSize().GetWidth() <= btn_height) {
wxWindowDC wdc(this); wxWindowDC wdc(this);
text = wxControl::Ellipsize(text, wdc, wxELLIPSIZE_END, text_width); text = wxControl::Ellipsize(text, wdc, wxELLIPSIZE_END, text_width);
@ -215,7 +215,7 @@ void TopBarItemsCtrl::ButtonWithPopup::SetLabel(const wxString& label)
#endif #endif
ScalableButton::SetLabel(full_label); ScalableButton::SetLabel(full_label);
if (resize_and_layout) { if (resize_and_layout) {
SetMinSize(wxSize(m_fixed_width, btn_height)); SetMinSize(wxSize(m_fixed_width * em_unit(this), btn_height));
GetParent()->Layout(); GetParent()->Layout();
} }
} }
@ -225,11 +225,12 @@ void TopBarItemsCtrl::UpdateAccountButton(bool avatar/* = false*/)
auto user_account = wxGetApp().plater()->get_user_account(); auto user_account = wxGetApp().plater()->get_user_account();
const wxString user_name = user_account->is_logged() ? from_u8(user_account->get_username()) : _L("Anonymous"); const wxString user_name = user_account->is_logged() ? from_u8(user_account->get_username()) : _L("Anonymous");
m_account_btn->SetLabel(m_collapsed_btns ? "" : user_name); m_account_btn->SetLabel(m_collapsed_btns ? "" : user_name);
const int icon_sz = 24;
#ifdef __linux__ #ifdef __linux__
if (avatar) { if (avatar) {
if (user_account->is_logged()) { if (user_account->is_logged()) {
boost::filesystem::path path = user_account->get_avatar_path(true); boost::filesystem::path path = user_account->get_avatar_path(true);
ScalableBitmap new_logo(this, path, m_account_btn->GetBitmapSize()); ScalableBitmap new_logo(this, path, wxSize(icon_sz, icon_sz));
if (new_logo.IsOk()) if (new_logo.IsOk())
m_account_btn->SetBitmap_(new_logo); m_account_btn->SetBitmap_(new_logo);
else else
@ -243,14 +244,14 @@ void TopBarItemsCtrl::UpdateAccountButton(bool avatar/* = false*/)
if (avatar) { if (avatar) {
if (user_account->is_logged()) { if (user_account->is_logged()) {
boost::filesystem::path path = user_account->get_avatar_path(true); boost::filesystem::path path = user_account->get_avatar_path(true);
ScalableBitmap new_logo(this, path, m_account_btn->GetBitmapSize()); ScalableBitmap new_logo(this, path, wxSize(icon_sz, icon_sz));
if (new_logo.IsOk()) if (new_logo.IsOk())
m_account_btn->SetBitmapBundle(new_logo.bmp()); m_account_btn->SetBitmapBundle(new_logo.bmp());
else else
m_account_btn->SetBitmapBundle(*get_bmp_bundle("user", 24)); m_account_btn->SetBitmapBundle(*get_bmp_bundle("user", icon_sz));
} }
else { else {
m_account_btn->SetBitmapBundle(*get_bmp_bundle("user", 24)); m_account_btn->SetBitmapBundle(*get_bmp_bundle("user", icon_sz));
} }
} }
#endif #endif
@ -365,7 +366,6 @@ void TopBarItemsCtrl::update_margins()
{ {
int em = em_unit(this); int em = em_unit(this);
m_btn_margin = std::lround(0.9 * em); m_btn_margin = std::lround(0.9 * em);
m_line_margin = std::lround(0.1 * em);
} }
wxPoint TopBarItemsCtrl::ButtonWithPopup::get_popup_pos() wxPoint TopBarItemsCtrl::ButtonWithPopup::get_popup_pos()
@ -478,7 +478,7 @@ TopBarItemsCtrl::TopBarItemsCtrl(wxWindow *parent, TopBarMenus* menus/* = nullpt
m_menus->Popup(this, &m_menus->workspaces, m_workspace_btn->get_popup_pos()); m_menus->Popup(this, &m_menus->workspaces, m_workspace_btn->get_popup_pos());
}); });
m_account_btn = new ButtonWithPopup(this, _L("Anonymous"), "user", wxSize(18 * em_unit(this), -1)); m_account_btn = new ButtonWithPopup(this, _L("Anonymous"), "user", wxSize(180, -1));
right_sizer->Add(m_account_btn, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxRIGHT, m_btn_margin); right_sizer->Add(m_account_btn, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxRIGHT, m_btn_margin);
m_account_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent& event) { m_account_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent& event) {
@ -529,6 +529,9 @@ void TopBarItemsCtrl::Rescale()
m_buttons_sizer->SetVGap(m_btn_margin); m_buttons_sizer->SetVGap(m_btn_margin);
m_buttons_sizer->SetHGap(m_btn_margin); m_buttons_sizer->SetHGap(m_btn_margin);
// call Layout before update buttons width to process recaling of the buttons
m_sizer->Layout();
update_btns_width(); update_btns_width();
UpdateSearchSizeAndPosition(); UpdateSearchSizeAndPosition();
m_sizer->Layout(); m_sizer->Layout();

View File

@ -105,7 +105,6 @@ private:
std::vector<Button*> m_pageButtons; std::vector<Button*> m_pageButtons;
int m_selection {-1}; int m_selection {-1};
int m_btn_margin; int m_btn_margin;
int m_line_margin;
void update_margins(); void update_margins();
}; };