summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorA404M <ahmadmahmoudiprogrammer@gmail.com>2024-12-28 09:35:59 +0330
committerA404M <ahmadmahmoudiprogrammer@gmail.com>2024-12-28 09:35:59 +0330
commit5a94037a19cee399d951b0e54937cffa82edecc2 (patch)
tree39b2a9aa3002a28d30f9b98d8b1ca5123b88b87f /src/main.c
parentd7802371b56734446a16962363322282ba772257 (diff)
fixed crashing on resizingHEADmaster
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c67
1 files changed, 40 insertions, 27 deletions
diff --git a/src/main.c b/src/main.c
index 61ee8e1..5834805 100644
--- a/src/main.c
+++ b/src/main.c
@@ -13,11 +13,11 @@ constexpr COLOR COLOR_FPS_BACK = color_hex(0xFFCCCCCC);
constexpr COLOR COLOR_FPS_TEXT = color_hex(0xFF000000);
bool show_fps = true;
-void on_click(MOUSE_ACTION) { show_fps = !show_fps; }
+void on_click(MOUSE_ACTION, void *) { show_fps = !show_fps; }
char search[1000] = "";
-void on_search_text_add(char c) {
+void on_search_text_add(char c, void *) {
if (c == '\n') {
// TODO: do something
} else if (c == '\b') {
@@ -32,19 +32,20 @@ void on_search_text_add(char c) {
WIDGET *search_box() {
return tui_make_padding(
- tui_make_box(MAX_WIDTH, 1,
- tui_make_center(tui_make_row(tui_make_widget_array(
- tui_make_box(MAX_WIDTH, MAX_HEIGHT,
- tui_make_text_input(
- search, color_init(0xFFFFFFFF),
- TEXT_STYLE_NORMAL, on_search_text_add),
- color_init(0xFF42414D)),
- tui_make_box(10, MAX_HEIGHT,
- tui_make_center(tui_make_text(
- "Search", color_init(0xFF000000),
- TEXT_STYLE_NORMAL)),
- color_init(0xFFC4C3C9))))),
- COLOR_NO_COLOR),
+ tui_make_box(
+ MAX_WIDTH, 1,
+ tui_make_center(tui_make_row(tui_make_widget_array(
+ tui_make_box(MAX_WIDTH, MAX_HEIGHT,
+ tui_make_text_input(search, color_init(0xFFFFFFFF),
+ TEXT_STYLE_NORMAL,
+ on_search_text_add, NULL),
+ color_init(0xFF42414D)),
+ tui_make_box(
+ 10, MAX_HEIGHT,
+ tui_make_center(tui_make_text(
+ "Search", color_init(0xFF000000), TEXT_STYLE_NORMAL)),
+ color_init(0xFFC4C3C9))))),
+ COLOR_NO_COLOR),
1, 1, 10, 10);
}
@@ -52,20 +53,32 @@ bool selectedArray[] = {
false, false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false,
};
+size_t selectedArray_size = sizeof(selectedArray) / sizeof(*selectedArray);
-WIDGET *search_result(int index) {
+void search_result_on_click(MOUSE_ACTION, void *data) {
+ for (size_t i = 0; i < selectedArray_size; ++i) {
+ selectedArray[i] = false;
+ }
+ selectedArray[(size_t)data] = true;
+}
+
+WIDGET *search_result(size_t index) {
bool isSelected = selectedArray[index];
return tui_make_padding(
- tui_make_row(tui_make_widget_array(
- isSelected ? tui_make_box(1, 5, NULL, color_init(0xFF0000FF))
- : tui_make_box(0, 5, NULL, COLOR_NO_COLOR),
- isSelected ? tui_make_box(1, 0, NULL, COLOR_NO_COLOR) : NULL,
- tui_make_column(tui_make_widget_array(
- tui_make_text("https://something.something/",
- color_init(0xFFE8E6E3), TEXT_STYLE_ITALIC),
- tui_make_text("Hello", color_init(0xFF7093E0), TEXT_STYLE_BOLD),
- tui_make_text("Hello this is somehing which can be seen",
- color_init(0xFFE8E6E3), TEXT_STYLE_SHADOWED))))),
+ tui_make_button(
+ tui_make_row(tui_make_widget_array(
+ isSelected ? tui_make_box(1, 5, NULL, color_init(0xFF0000FF))
+ : tui_make_box(0, 5, NULL, COLOR_NO_COLOR),
+ isSelected ? tui_make_box(1, 0, NULL, COLOR_NO_COLOR) : NULL,
+ tui_make_column(tui_make_widget_array(
+ tui_make_text("https://something.something/",
+ color_init(0xFFE8E6E3), TEXT_STYLE_ITALIC),
+ tui_make_text("Hello", color_init(0xFF7093E0),
+ TEXT_STYLE_BOLD),
+ tui_make_text("Hello this is somehing which can be seen",
+ color_init(0xFFE8E6E3),
+ TEXT_STYLE_SHADOWED))))),
+ search_result_on_click, (void *)index),
0, 1, 0, 0);
}
@@ -92,7 +105,7 @@ WIDGET *fps_counter(uint64_t last_frame) {
TEXT_STYLE_NORMAL),
0, 0, 1, 1),
COLOR_FPS_BACK),
- on_click),
+ on_click, NULL),
0, 0, 2, 2);
}