-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbrokenstatemenu.cpp
More file actions
82 lines (67 loc) · 2.22 KB
/
Copy pathbrokenstatemenu.cpp
File metadata and controls
82 lines (67 loc) · 2.22 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
76
77
78
79
80
81
82
#include "brokenstatemenu.h"
#include "text_renderer.h"
BrokenStateMenu::BrokenStateMenu(Widget* parent, std::string firsttext, std::string secondtext, std::string query) : Widget(parent) {
id = icu::UnicodeString::fromUTF8("BrokenStateMenu");
Q = query;
firstbutton = new Button(this, icu::UnicodeString::fromUTF8(firsttext), [&](Button* btn, int x, int y, int av_width, int av_height, int w, int h){
// position
btn->t_x = t_x+t_w/2-w/2;
btn->t_y = t_y+TextRenderer::get_text_height()+App::text_padding*2;
}, [&](Button* btn){
// onclick
if (first_callback) {
first_callback();
}
});
firstbutton->border = true;
firstbutton->rounded = true;
secondbutton = new Button(this, icu::UnicodeString::fromUTF8(secondtext), [&](Button* btn, int x, int y, int av_width, int av_height, int w, int h){
// position
btn->t_x = t_x+t_w/2-w/2;
btn->t_y = firstbutton->t_y+firstbutton->t_h+App::text_padding;
}, [&](Button* btn){
// onclick
if (second_callback) {
second_callback();
}
});
secondbutton->border = true;
secondbutton->rounded = true;
char_1 = std::tolower(firsttext.at(0));
char_2 = std::tolower(secondtext.at(0));
}
void BrokenStateMenu::render() {
App::DrawRect(t_x, t_y, t_w, t_h, App::theme.hover_background_color);
auto txt = icu::UnicodeString::fromUTF8(Q);
TextRenderer::draw_text(t_x+t_w/2-TextRenderer::get_text_width(txt.length())/2, t_y+App::text_padding, txt, App::theme.main_text_color);
Widget::render();
}
bool BrokenStateMenu::on_key_event(int key, int scancode, int action, int mods) {
if (!is_visible || !parent) {
return false;
}
return false;
}
bool BrokenStateMenu::on_char_event(unsigned int codepoint) {
if (!is_visible || !parent || this != App::activeLeafNode) {
return false;
}
if (char_1 == char_2) {
return true;
}
char input_char = std::tolower(static_cast<char>(codepoint));
if (input_char == char_1) {
first_callback();
return true;
} else if (input_char == char_2) {
second_callback();
return true;
}
return true;
}
bool BrokenStateMenu::on_mouse_button_event(int button, int action, int mods) {
if (cursor_in_this && action == GLFW_PRESS) {
App::setActiveLeafNode(this);
}
return Widget::on_mouse_button_event(button, action, mods);
}