-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfocus_demo.cpp
75 lines (66 loc) · 1.72 KB
/
focus_demo.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 <SDL.h>
#include "dui.hpp"
void
yesOrNo(dui::Target target, bool value)
{
if (value) {
dui::label(target,
"Yes",
{5},
dui::themeFor<dui::Label>().withText({20, 128, 100, 255}));
} else {
dui::label(target,
"No",
{5},
dui::themeFor<dui::Label>().withText({200, 100, 20, 255}));
}
}
int
main(int argc, char** argv)
{
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "%s\n", SDL_GetError());
return 1;
}
SDL_Window* window = nullptr;
SDL_Renderer* renderer = nullptr;
if (SDL_CreateWindowAndRenderer(
800, 600, SDL_WINDOW_SHOWN, &window, &renderer) < 0) {
fprintf(stderr, "%s\n", SDL_GetError());
return 1;
}
// The ui state
dui::State state{renderer};
for (;;) {
bool mouseFocus = state.wantsMouse();
bool keyboardFocus = state.wantsKeyboard();
SDL_Event ev;
while (SDL_PollEvent(&ev)) {
state.event(ev);
if (ev.type == SDL_QUIT) {
return 0;
}
}
// UI
auto f = dui::frame(state);
dui::label(f, "This doesn't take focus", {350, 200});
dui::button(f, "This takes focus", {350, 220});
if (auto p = dui::panel(f, "mainPanel", {10, 10, 300, 500})) {
;
dui::label(p, "Mouse Focus");
yesOrNo(p, mouseFocus);
dui::label(p, "Keyboard Focus");
yesOrNo(p, keyboardFocus);
dui::button(p, "dummy button");
static std::string dummyText{"Ahoy"};
dui::textField(p, "dummy text", &dummyText);
}
// Render
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_RenderFillRect(renderer, nullptr);
f.render();
SDL_RenderPresent(renderer);
SDL_Delay(1);
}
return 1;
}