-
Notifications
You must be signed in to change notification settings - Fork 0
/
GeneralSettingsFrame.cpp
60 lines (47 loc) · 1.58 KB
/
GeneralSettingsFrame.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "GeneralSettingsFrame.h"
#include "TextInput.h"
#include "General.h"
constexpr int ControlPadding = 4;
enum ControlId
{
Ok,
ElectionName
};
GeneralSettingsFrame::GeneralSettingsFrame(OkCallback okCallback, GeneralSettingsData data)
: wxDialog(NULL, 0, "General Settings", wxDefaultPosition, wxSize(500, 400)),
okCallback(okCallback), data(data)
{
int currentY = ControlPadding;
createControls(currentY);
setFinalWindowHeight(currentY);
}
void GeneralSettingsFrame::createControls(int& y)
{
createElectionNameInput(y);
createOkCancelButtons(y);
}
void GeneralSettingsFrame::createElectionNameInput(int& y)
{
auto callback = [this](std::string s) {data.electionName = s; };
electionNameInput.reset(new TextInput(this, ControlId::ElectionName, "Election name: ", data.electionName,
wxPoint(2, y), callback));
y += electionNameInput->Height + ControlPadding;
}
void GeneralSettingsFrame::createOkCancelButtons(int& y)
{
// Create the OK and cancel buttons.
okButton = new wxButton(this, ControlId::Ok, "OK", wxPoint(67, y), wxSize(100, TextInput::Height));
cancelButton = new wxButton(this, wxID_CANCEL, "Cancel", wxPoint(233, y), wxSize(100, TextInput::Height));
// Bind events to the functions that should be carried out by them.
Bind(wxEVT_BUTTON, &GeneralSettingsFrame::OnOK, this, ControlId::Ok);
y += TextInput::Height + ControlPadding;
}
void GeneralSettingsFrame::setFinalWindowHeight(int y)
{
SetClientSize(wxSize(GetClientSize().x, y));
}
void GeneralSettingsFrame::OnOK(wxCommandEvent& WXUNUSED(event)) {
okCallback(data);
// Then close this dialog.
Close();
}