Adds a fix to scale the Frequency dialog.

The dialog layout uses a sizer to scale the content automatically.  The layout wasn't very good using sizers alone as width of the dialog was being set too narrow for the title string.  The width is set manually to either the [title string width + 35%] or the [content string width +10%], whichever's the greater.
This commit is contained in:
James Watson 2020-04-05 20:41:08 +03:00 committed by vsonnier
parent 853484ff82
commit 2f4e9a9e74

View File

@ -14,8 +14,10 @@ wxEND_EVENT_TABLE()
FrequencyDialog::FrequencyDialog(wxWindow * parent, wxWindowID id, const wxString & title, DemodulatorInstancePtr demod, const wxPoint & position, FrequencyDialog::FrequencyDialog(wxWindow * parent, wxWindowID id, const wxString & title, DemodulatorInstancePtr demod, const wxPoint & position,
const wxSize & size, long style, FrequencyDialogTarget targetMode, wxString initString) : const wxSize & size, long style, FrequencyDialogTarget targetMode, wxString initString) :
wxDialog(parent, id, title, position, size, style) { wxDialog(parent, id, title, wxDefaultPosition, wxDefaultSize, style) {
wxString freqStr; wxString freqStr;
wxSizer *dialogsizer = new wxBoxSizer( wxVERTICAL );
int titleX, textCtrlX;
activeDemod = demod; activeDemod = demod;
@ -52,13 +54,9 @@ FrequencyDialog::FrequencyDialog(wxWindow * parent, wxWindowID id, const wxStrin
freqStr = std::to_string((int)wxGetApp().getGain(wxGetApp().getActiveGainEntry())); freqStr = std::to_string((int)wxGetApp().getGain(wxGetApp().getActiveGainEntry()));
} }
} }
dialogText = new wxTextCtrl(this, wxID_FREQ_INPUT, freqStr, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
dialogText = new wxTextCtrl(this, wxID_FREQ_INPUT, freqStr, wxPoint(6, 1), wxSize(size.GetWidth() - 20, size.GetHeight() - 70),
wxTE_PROCESS_ENTER);
dialogText->SetFont(wxFont(15, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD)); dialogText->SetFont(wxFont(15, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD));
Centre();
if (initString != "" && initString.length() == 1) { if (initString != "" && initString.length() == 1) {
dialogText->SetValue(initString); dialogText->SetValue(initString);
dialogText->SetSelection(2, 2); dialogText->SetSelection(2, 2);
@ -69,6 +67,16 @@ FrequencyDialog::FrequencyDialog(wxWindow * parent, wxWindowID id, const wxStrin
} }
dialogText->SetSelection(-1, -1); dialogText->SetSelection(-1, -1);
} }
// Set the textControl width to the [title + 35%] or the [content +10%],
// whichever's the greater.
textCtrlX = dialogText->GetTextExtent(initString).GetWidth();
titleX = this->GetTextExtent(title).GetWidth();
dialogText->SetMinSize(wxSize(max(int(1.35 * titleX), int(1.1 * textCtrlX)), -1));
dialogsizer->Add( dialogText, wxSizerFlags(1).Expand().Border(wxALL, 5));
SetSizerAndFit(dialogsizer);
} }