Make Custom GCode Editor resizable (#9405)
Some checks are pending
Build all / Build All (push) Waiting to run
Build all / Flatpak (push) Waiting to run

* Make gcode editor window resizable

* Make param list expands with the window

* Make dialog shrinkable and give it a proper initial size

* Revert "Hardcode Location of Add Button"

This reverts commit aef74ab005.

* Make sure the dialog fits inside current screen

* Fix compile error
This commit is contained in:
Noisyfox 2025-05-09 23:00:27 +08:00 committed by GitHub
parent 0c4f778ddb
commit 0cc495b425
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 29 additions and 6 deletions

View file

@ -35,7 +35,7 @@ namespace GUI {
//------------------------------------------
EditGCodeDialog::EditGCodeDialog(wxWindow* parent, const std::string& key, const std::string& value) :
DPIDialog(parent, wxID_ANY, format_wxstr(_L("Edit Custom G-code (%1%)"), key), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE/* | wxRESIZE_BORDER*/)
DPIDialog(parent, wxID_ANY, format_wxstr(_L("Edit Custom G-code (%1%)"), key), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
{
SetFont(wxGetApp().normal_font());
SetBackgroundColour(*wxWHITE);
@ -68,15 +68,15 @@ EditGCodeDialog::EditGCodeDialog(wxWindow* parent, const std::string& key, const
param_sizer->Add(m_search_bar, 0, wxEXPAND | wxALL, border);
m_params_list = new ParamsViewCtrl(this, wxSize(em * 45, em * 70));
m_params_list = new ParamsViewCtrl(this, wxDefaultSize);
m_params_list->SetFont(wxGetApp().code_font());
wxGetApp().UpdateDarkUI(m_params_list);
param_sizer->Add(m_params_list, 0, wxEXPAND | wxALL, border);
param_sizer->Add(m_params_list, 1, wxEXPAND | wxALL, border);
m_add_btn = new ScalableButton(this, wxID_ANY, "add_copies");
m_add_btn->SetToolTip(_L("Add selected placeholder to G-code"));
m_gcode_editor = new wxTextCtrl(this, wxID_ANY, value, wxDefaultPosition, wxSize(em * 75, em * 70), wxTE_MULTILINE
m_gcode_editor = new wxTextCtrl(this, wxID_ANY, value, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE
#ifdef _WIN32
| wxBORDER_SIMPLE
#endif
@ -86,12 +86,12 @@ EditGCodeDialog::EditGCodeDialog(wxWindow* parent, const std::string& key, const
wxGetApp().UpdateDarkUI(m_gcode_editor);
grid_sizer->Add(param_sizer, 1, wxEXPAND);
grid_sizer->Add(m_add_btn, 0, wxTOP, m_params_list->GetSize().y/2);
grid_sizer->Add(m_add_btn, 0, wxALIGN_CENTER_VERTICAL);
grid_sizer->Add(m_gcode_editor, 2, wxEXPAND);
grid_sizer->AddGrowableRow(0, 1);
grid_sizer->AddGrowableCol(0, 1);
grid_sizer->AddGrowableCol(2, 1);
grid_sizer->AddGrowableCol(2, 2);
m_param_label = new wxStaticText(this, wxID_ANY, _L("Select placeholder"));
m_param_label->SetFont(wxGetApp().bold_font());
@ -115,6 +115,9 @@ EditGCodeDialog::EditGCodeDialog(wxWindow* parent, const std::string& key, const
topSizer->SetSizeHints(this);
this->Fit();
fit_in_display(*this, {100 * em, 70 * em});
this->Layout();
this->CenterOnScreen();

View file

@ -18,6 +18,7 @@
#include <wx/dcclient.h>
#include <wx/font.h>
#include <wx/fontutil.h>
#include <wx/display.h>
#include "libslic3r/Config.hpp"
@ -481,5 +482,18 @@ bool generate_image(const std::string &filename, wxImage &image, wxSize img_size
std::deque<wxDialog*> dialogStack;
void fit_in_display(wxTopLevelWindow& window, wxSize desired_size)
{
const auto display_size = wxDisplay(window.GetParent()).GetClientArea();
if (desired_size.GetWidth() > display_size.GetWidth()) {
desired_size.SetWidth(display_size.GetWidth() * 4 / 5);
}
if (desired_size.GetHeight() > display_size.GetHeight()) {
desired_size.SetHeight(display_size.GetHeight() * 4 / 5);
}
window.SetSize(desired_size);
}
}
}

View file

@ -498,6 +498,12 @@ int get_dpi_for_window(const wxWindow *window);
void dataview_remove_insets(wxDataViewCtrl* dv);
#endif
/// <summary>
/// Make sure the given window fits inside current display
/// </summary>
void fit_in_display(wxTopLevelWindow& window, wxSize desired_size);
}}
#endif