-
Notifications
You must be signed in to change notification settings - Fork 0
/
EditPollsterFrame.cpp
75 lines (61 loc) · 2.12 KB
/
EditPollsterFrame.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "EditPollsterFrame.h"
#include "CheckInput.h"
#include "ColourInput.h"
#include "FloatInput.h"
#include "General.h"
#include "TextInput.h"
using namespace std::placeholders; // for function object parameter binding
constexpr int ControlPadding = 4;
enum ControlId
{
Ok,
Name,
Colour
};
EditPollsterFrame::EditPollsterFrame(Function function, OkCallback callback, Pollster pollster)
: wxDialog(NULL, 0, (function == Function::New ? "New Pollster" : "Edit Pollster"), wxDefaultPosition, wxSize(500, 400)),
pollster(pollster), callback(callback)
{
int currentY = ControlPadding;
createControls(currentY);
setFinalWindowHeight(currentY);
}
void EditPollsterFrame::createControls(int& y)
{
createNameInput(y);
createColourInput(y);
createOkCancelButtons(y);
}
void EditPollsterFrame::createNameInput(int& y)
{
auto nameCallback = [this](std::string s) -> void {pollster.name = s; };
nameInput.reset(new TextInput(this, ControlId::Name, "Name:", pollster.name, wxPoint(2, y), nameCallback));
y += nameInput->Height + ControlPadding;
}
void EditPollsterFrame::createColourInput(int& y)
{
wxColour currentColour(pollster.colour);
auto colourCallback = [this](wxColour c) -> void {pollster.colour = c.GetRGB(); };
colourInput.reset(new ColourInput(this, ControlId::Colour, "Colour:", currentColour, wxPoint(2, y), colourCallback));
y += colourInput->Height + ControlPadding;
}
void EditPollsterFrame::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, &EditPollsterFrame::OnOK, this, ControlId::Ok);
y += TextInput::Height + ControlPadding;
}
void EditPollsterFrame::setFinalWindowHeight(int y)
{
SetClientSize(wxSize(GetClientSize().x, y));
}
void EditPollsterFrame::OnOK(wxCommandEvent&)
{
// Call the function that was passed when this frame was opened.
callback(pollster);
// Then close this dialog.
Close();
}