-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSource.cpp
154 lines (108 loc) · 4.73 KB
/
Source.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include "VanityUI.h"
#include <iostream>
int main(int argc, char* argv[])
{
Vanity::Setup(1920, 1080);
Vanity::DisableVsync();
// Create a rendering context via Ivory. Can also pass an existing renderer to the Ivory Setup() method instead.
SDL_Renderer* renderer = Vanity::CreateRenderingContext("Vanity UI");
SDL_Color black = { 0,0,0,255 };
Label* l = Vanity::CreateLabel("Div 3");
Button* b = Vanity::CreateButton("Page 2");
auto tb = Vanity::CreateTextbox("Text char limit", 350);
//auto img = Vanity::CreateImage("db3991d70eff2556d448c9d911e71a11_400x400.jpeg", 600, 0, 50, 50);
auto cb = Vanity::CreateCheckbox(550);
auto sl = Vanity::CreateSlider(650, 500);
tb->SetBackgroundImage("db3991d70eff2556d448c9d911e71a11_400x400.jpeg");
auto div = Vanity::CreateDivision(0, 0, 600, 600);
auto div2 = Vanity::CreateDivision(100, 100, 200, 200);
auto div3 = Vanity::CreateDivision(100, 100, 200, 200);
auto div4 = Vanity::CreateDivision(500, 0, 200, 200);
div->AddChild(div2);
div2->AddChild(div3);
div4->SetColor({ 250,0,0,255 });
auto btnGiveFocus = Vanity::CreateButton("Give focus to textbox");
btnGiveFocus->SetWidth(200);
div3->AddChild(btnGiveFocus)->AddChild(b)->AddChild(div4)->AddChild(tb)->AddChild(l)->AddChild(cb);
auto autoLayoutBtn1 = Vanity::CreateButton("absolute layout", 100, 50);
auto autoLayoutBtn3 = Vanity::CreateButton("auto layout");
auto autoLayoutBtn4 = Vanity::CreateButton("auto layout 2");
auto autoLayoutBtn2 = Vanity::CreateTextbox("Textbox", 50, 50);
autoLayoutBtn3->SetWidth("50%");
auto div5ForAutoLayout = Vanity::CreateDivision(100, 100);
auto div6 = Vanity::CreateDivision(150, 150, 300, 300);
auto btn1 = Vanity::CreateButton("test", 0, 0, 290);
auto txt1 = Vanity::CreateTextbox("Textbox", 0, 50);
auto sli1 = Vanity::CreateSlider(0, 100);
auto sli2 = Vanity::CreateSlider(0, 100);
auto div1 = Vanity::CreateDivision(0, 150, 30, 30);
auto chk1 = Vanity::CreateCheckbox(0, 200);
auto chk2 = Vanity::CreateCheckbox(0, 50);
auto img = Vanity::CreateImage("db3991d70eff2556d448c9d911e71a11_400x400.jpeg", 0, 300);
auto lbl = Vanity::CreateLabel("Label", 0, 420);
div6->AddChild(btn1)->AddChild(div1)->AddChild(sli1)->AddChild(txt1)->AddChild(chk1)->AddChild(img)->AddChild(lbl);
div5ForAutoLayout->AddChild(autoLayoutBtn1)->AddChild(autoLayoutBtn2)
->AddChild(autoLayoutBtn4)->AddChild(div6)->AddChild(sli2);
div5ForAutoLayout->SetColor({ 0, 255, 0, 255 });
div6->SetColor({ 255, 0, 0, 255 });
//div6->SetPadding({ 0, 0, 0, 0 });
//div5ForAutoLayout->SetPadding({ 0, 0, 0, 0 });
//btn1->SetDimensions("20%", "50%");
auto btn = Vanity::CreateButton("Back to page 1");
//b->SetDimensions("50%", "100%");
b->SetAnimation(-100, 300, "linear", 3000);
b->Animate();
Page* p = Vanity::CreatePage();
Page* p2 = Vanity::CreatePage();
//p->AddElement(div)->AddElement(sl);
p->AddElement(div5ForAutoLayout);
auto knappForTest = Vanity::CreateButton("Knapp for testing");
p->AddElement(div6);
div6->AddChild(knappForTest);
p->AddElement(autoLayoutBtn3);
p->AddElement(chk2);
p2->AddElement(btn);
Vanity::DisplayPage(p);
//div6->HorizontallyAlignElementsCenter();
//div6->VerticallyAlignElementsCenter();
//div6->AlignElementsTop();
//div6->AlignElementsRight();
//div6->AlignElementsLeft();
//div6->AlignElementsBottom();
//btn1->AlignRight();
//btn1->AlignLeft();
while (Vanity::IsRunning()) {
Vanity::Prepare();
//tb->SetValue(std::to_string(sl->GetValue()));
if (b->Clicked()) {
std::cout << "Button pressed!" << std::endl;
Vanity::DisplayPage(p2);
}
if (btn1->Clicked()) {
//Vanity::DisplayPage(p);
std::cout << "Button clicked" << std::endl;
//btn1->GetParent()->AlignElementsRight();
//btn1->HorizontallyAlignCenter();
}
if (btnGiveFocus->Clicked()) {
tb->Focus();
}
if (txt1->Clicked())
std::cout << "Textbox clicked" << std::endl;
if (img->Clicked())
std::cout << "Image clicked" << std::endl;
if (sli1->Clicked())
std::cout << "Slider clicked" << std::endl;
if (div6->Clicked()) {
std::cout << "Division clicked" << std::endl;
}
if (chk1->Clicked())
std::cout << "Checkbox clicked" << std::endl;
if (lbl->Clicked())
std::cout << "Label clicked" << std::endl;
Vanity::Render();
//SDL_RenderPresent(renderer);
}
//SDL_Delay(10000);
return 0;
}