-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
75 lines (62 loc) · 2.14 KB
/
main.cpp
File metadata and controls
75 lines (62 loc) · 2.14 KB
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 <nana/gui.hpp>
#include <nana/gui/widgets/label.hpp>
#include <nana/gui/widgets/button.hpp>
#include "NickGenerator.h"
#include <string>
using namespace menma;
int main()
{
using namespace nana;
//Define a form.
form fm;
NickGenerator nick;//create generation object
std::string nickname="noname";//nickname
int length=3;//length of name, default value is 3
//Define a label and display a text.
label lab{fm, "<bold black size=16>Random Nick Generator</>"};
lab.format(true);
//Define a label and display a text.
label nick_lab{fm, "<bold blue size=14>noname</>"};
nick_lab.format(true);
//Define a label and display a text.
label length_label{fm, "<bold blue size=14>3</>"};
length_label.format(true);
//Define a button and answer the click event.
button btn{fm, "Quit"};
btn.events().click([&fm]{
fm.close();
});
button button_gen{fm,"Generate"};
button_gen.events().click([&fm,&nick,&nickname,&nick_lab,&length]{
nickname=nick.getNick(length);
nick_lab.caption("<bold blue size=14>"+nickname+"</>");
});
//capture used variable
button button_up{fm,"up"};
button_up.events().click([&fm,&length,&length_label]{
if(length<=10)
length++;
length_label.caption("<bold blue size=14>"+std::to_string(length)+"</>");
});
//capture used variable
button button_down{fm,"down"};
button_down.events().click([&fm,&length,&length_label]{
if(length>1)
length--;
length_label.caption("<bold blue size=14>"+std::to_string(length)+"</>");
});
//Layout management
fm.div("vert <text2><<><weight=80% text><>><<><text_length><>><weight=24<up><gen><down>><<><button><>>");
fm["text2"]<<lab;
fm["button"] << btn;
fm["gen"]<<button_gen;//add button
fm["up"]<<button_up;//add button
fm["down"]<< button_down;// add button down
fm["text"]<< nick_lab;// add label
fm["text_length"]<<length_label;//size of words
fm.collocate();
//Show the form
fm.show();
//Start to event loop process, it blocks until the form is closed.
exec();
}