I'm creating a wxWidgets C++ calculator application. I have a series of wxTextCtrl
's for the main expression text and other stuff. They are, of course, positioned using sizers so that they grow larger or smaller as I resize the window. However, if I maximize the window, their size successfully updates, but not if I then minimize it.
My app in a normal state:
Maximized application:
And when I minimize it back:
The wxTextCtrl
's sizes eventually update and correct themselves when I resize the window, but this bug is kind of annoying.
Here's the code where these controls are defined:
text_controls.cpp
#include "main.h"
void Main::AddTextControls()
{
auto sizer = new wxBoxSizer(wxVERTICAL);
Chronology = new wxTextCtrl(this, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxTE_READONLY | wxNO_BORDER | wxTE_RIGHT);
Chronology->SetBackgroundColour(wxColour(235, 235, 235));
Chronology->SetForegroundColour(wxColour(105, 105, 105));
Chronology->Bind(wxEVT_SIZE, [this](wxSizeEvent& evt) {
evt.Skip();
Chronology->SetFont(
wxFontInfo(wxSize(0, Chronology->GetSize().y / 1.5))
.Family(wxFONTFAMILY_SWISS)
.FaceName("Calibri Light")
);
});
sizer->Add(Chronology, 4, wxEXPAND);
Expression = new wxTextCtrl(this, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxTE_READONLY | wxNO_BORDER | wxTE_RIGHT);
Expression->SetForegroundColour(wxColour(55, 55, 55));
Expression->Bind(wxEVT_TEXT, &Main::OnTextChange, this);
Expression->Bind(wxEVT_SIZE, [this](wxSizeEvent& evt) {
evt.Skip();
Expression->SetFont(
wxFontInfo(wxSize(0, Expression->GetSize().y / 1.3))
.Family(wxFONTFAMILY_SWISS)
.FaceName("Calibri")
.Bold()
);
});
sizer->Add(Expression, 10, wxEXPAND);
//memoria
auto memSizer = new wxBoxSizer(wxHORIZONTAL);
MemText = new wxTextCtrl(this, wxID_ANY, "Memoria", wxDefaultPosition, wxDefaultSize, wxTE_READONLY | wxNO_BORDER);
MemText->SetBackgroundColour(wxColour(55, 55, 55));
MemText->SetForegroundColour(wxColour(119, 119, 119));
MemText->Bind(wxEVT_SIZE, [this](wxSizeEvent& evt) {
evt.Skip();
MemText->SetFont(
wxFontInfo(wxSize(0, MemText->GetSize().y / 1.3))
.Family(wxFONTFAMILY_SWISS)
.FaceName("Corbel")
);
});
memSizer->Add(MemText, 25, wxEXPAND);
Memory = new wxTextCtrl(this, wxID_ANY, "0", wxDefaultPosition, wxDefaultSize, wxTE_READONLY | wxNO_BORDER | wxTE_RIGHT);
Memory->SetBackgroundColour(wxColour(55, 55, 55));
Memory->SetForegroundColour(wxColour(105, 105, 105));
Memory->Bind(wxEVT_SIZE, [this](wxSizeEvent& evt) {
evt.Skip();
Memory->SetFont(
wxFontInfo(wxSize(0, Memory->GetSize().y / 1.3))
.Family(wxFONTFAMILY_SWISS)
.FaceName("Calibri Light")
);
});
memSizer->Add(Memory, 100, wxEXPAND);
sizer->Add(memSizer, 3, wxEXPAND);
MainSizer->Add(sizer, 30, wxEXPAND);
}
Anybody got a solution? Also, I'm very new to wxWidgets.
EDIT: Followed a suggestion and added this snippet to my main frame constructor:
Main::Main() : wxFrame(nullptr, wxID_ANY, "IKE Calculator", wxDefaultPosition, wxSize(525, 650), wxDEFAULT_FRAME_STYLE)
{
this->SetMinSize(wxSize(325, 450));
FrameSize = this->GetSize();
MainSizer = new wxBoxSizer(wxVERTICAL);
this->Bind(wxEVT_SIZE, [this](wxSizeEvent& evt) {
evt.Skip();
CallAfter(Layout()); //will be called later
});
this->SetBackgroundColour(wxColour(70, 73, 101));
AddTextControls();
AddMainButtons();
AddButtons();
this->SetSizer(MainSizer);
MainSizer->Layout();
}
Getting a C2064
error in VS2019: The term doesn't return a function that accepts 0 arguments
.
EDIT:
Changed CallAfter(Layout());
to CallAfter(&Main::Layout);
and I'm getting the same error.