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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
#include "application.h"
#include "ui/window.h"
#include "ui/events/ui_event.h"
#include "ui/controls/linear_layout.h"
#include "ui/controls/text_block.h"
#include "ui/controls/toggle_button.h"
#include "ui/controls/button.h"
#include "ui/controls/text_box.h"
using cru::String;
using cru::Application;
using cru::ui::Window;
using cru::ui::Alignment;
using cru::ui::LayoutSideParams;
using cru::ui::Thickness;
using cru::ui::ControlList;
using cru::ui::CreateWithLayout;
using cru::ui::controls::LinearLayout;
using cru::ui::controls::TextBlock;
using cru::ui::controls::ToggleButton;
using cru::ui::controls::Button;
using cru::ui::controls::TextBox;
int APIENTRY wWinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPWSTR lpCmdLine,
int nCmdShow) {
Application application(hInstance);
Window window;
/*
window.native_message_event.AddHandler([](cru::ui::events::WindowNativeMessageEventArgs& args)
{
if (args.GetWindowMessage().msg == WM_PAINT)
{
OutputDebugStringW(L"Paint!\n");
//args.SetResult(0);
}
});
*/
/*
// test1
cru::ui::controls::TextBlock text_block;
text_block.SetText(L"Hello world!");
text_block.SetSize(cru::ui::Size(200, 30));
window.AddChild(&text_block);
std::array<D2D_COLOR_F, 4> colors =
{
D2D1::ColorF(D2D1::ColorF::Blue),
D2D1::ColorF(D2D1::ColorF::Yellow),
D2D1::ColorF(D2D1::ColorF::Green),
D2D1::ColorF(D2D1::ColorF::Red)
};
std::random_device rd; // only used once to initialise (seed) engine
std::mt19937 rng(rd()); // random-number engine used (Mersenne-Twister in this case)
std::uniform_int_distribution<decltype(colors.size())> uni(0, colors.size() - 1); // guaranteed unbiased
window.draw_event.AddHandler([&](cru::ui::events::DrawEventArgs& args) {
auto device_context = args.GetDeviceContext();
ID2D1SolidColorBrush* brush;
device_context->CreateSolidColorBrush(colors[uni(rng)], &brush);
device_context->FillRectangle(D2D1::RectF(100.0f, 100.0f, 300.0f, 200.0f), brush);
brush->Release();
});
cru::SetTimeout(2.0, [&window]() {
window.Repaint();
auto task = cru::SetInterval(0.5, [&window]() {
window.Repaint();
});
cru::SetTimeout(4, [task]() {
task->Cancel();
task->Cancel(); // test for idempotency.
});
});
*/
/*
//test 2
const auto layout = CreateWithLayout<LinearLayout>(LayoutSideParams::Exactly(500), LayoutSideParams::Content());
layout->mouse_click_event.AddHandler([layout](cru::ui::events::MouseButtonEventArgs& args)
{
if (args.GetSender() == args.GetOriginalSender())
layout->AddChild(TextBlock::Create(L"Layout is clicked!"));
});
{
const auto inner_layout = CreateWithLayout<LinearLayout>(LayoutSideParams::Content(Alignment::End), LayoutSideParams::Content(), LinearLayout::Orientation::Horizontal);
inner_layout->AddChild(TextBlock::Create(L"Toggle debug border"));
const auto toggle_button = ToggleButton::Create();
toggle_button->toggle_event.AddHandler([&window](cru::ui::events::ToggleEventArgs& args)
{
window.SetDebugDrawControlBorder(args.GetNewState());
});
inner_layout->AddChild(toggle_button);
layout->AddChild(inner_layout);
}
{
const auto button = Button::Create();
button->AddChild(MarginContainer::Create(Thickness(20, 5), { TextBlock::Create(L"button") }));
layout->AddChild(button);
}
{
const auto text_block = CreateWithLayout<TextBlock>(LayoutSideParams::Exactly(200), LayoutSideParams::Exactly(80), L"Hello World!!!");
text_block->mouse_click_event.AddHandler([layout](cru::ui::events::MouseButtonEventArgs& args)
{
layout->AddChild(TextBlock::Create(L"Hello world is clicked!"));
});
layout->AddChild(text_block);
}
{
const auto text_block = CreateWithLayout<TextBlock>(LayoutSideParams::Stretch(), LayoutSideParams::Stretch(), L"This is a very very very very very long sentence!!!");
text_block->SetSelectable(true);
layout->AddChild(text_block);
}
layout->AddChild(CreateWithLayout<TextBlock>(LayoutSideParams::Content(Alignment::Start), LayoutSideParams::Content(), L"This is a little short sentence!!!"));
layout->AddChild(CreateWithLayout<TextBlock>(LayoutSideParams::Content(Alignment::End), LayoutSideParams::Stretch(), L"By crupest!!!"));
window.AddChild(layout);
*/
/*
window.AddChild(
CreateWithLayout<Border>(LayoutSideParams::Exactly(200), LayoutSideParams::Content(),
std::initializer_list<cru::ui::Control*>{
CreateWithLayout<TextBox>(LayoutSideParams::Stretch(), LayoutSideParams::Content())
}
));
*/
const auto linear_layout = CreateWithLayout<LinearLayout>(Thickness(50, 50), Thickness(50, 50), LinearLayout::Orientation::Vertical, ControlList({
Button::Create({
TextBlock::Create(L"Button")
}),
TextBox::Create()
}));
linear_layout->SetBordered(true);
window.AddChild(linear_layout);
//window.SetDebugDrawControlBorder(true);
window.Show();
return application.Run();
}
|