summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorA404M <ahmadmahmoudiprogrammer@gmail.com>2024-12-28 08:03:23 +0330
committerA404M <ahmadmahmoudiprogrammer@gmail.com>2024-12-28 08:03:23 +0330
commitd7802371b56734446a16962363322282ba772257 (patch)
tree8b5a62d12b080381e4a512b107e675a3ad14186b /src/main.c
parent55d29d0df8681efe01e88e0475c8512c44ec4bc4 (diff)
added many stuff which I can't even remember
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c89
1 files changed, 73 insertions, 16 deletions
diff --git a/src/main.c b/src/main.c
index 549ddf5..61ee8e1 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,56 +1,113 @@
#include <stdint.h>
#include <stdio.h>
+#include <string.h>
#include <unistd.h>
#include "ui/color.h"
+#include "ui/text.h"
#include "ui/tui.h"
+#include "utils/time.h"
constexpr COLOR BACKGROUND_COLOR = color_hex(0xFF2B2A33);
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; }
+
+char search[1000] = "";
+
+void on_search_text_add(char c) {
+ if (c == '\n') {
+ // TODO: do something
+ } else if (c == '\b') {
+ size_t len = strlen(search);
+ if (len != 0) {
+ search[len - 1] = '\0';
+ }
+ } else {
+ strncat(search, &c, 1);
+ }
+}
+
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, 1, NULL, color_init(0xFF42414D)),
- tui_make_box(10, 1,
+ 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))),
+ "Search", color_init(0xFF000000),
+ TEXT_STYLE_NORMAL)),
color_init(0xFFC4C3C9))))),
COLOR_NO_COLOR),
1, 1, 10, 10);
}
-// WIDGET *search_header() {}
+bool selectedArray[] = {
+ false, false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false,
+};
+
+WIDGET *search_result(int 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))))),
+ 0, 1, 0, 0);
+}
+
+WIDGET *search_body() {
+ return tui_make_padding(
+ tui_make_column(tui_make_widget_array(
+ search_result(0), search_result(1), search_result(2),
+ search_result(3), search_result(4), search_result(5))),
+ 0, 0, 10, 10);
+}
WIDGET *fps_counter(uint64_t last_frame) {
char fps_text[3 + 1 + 20 + 1];
- sprintf(fps_text, "fps %ld",
- (last_frame == 0) ? 0 : (NANO_TO_SECOND / last_frame));
+ if (show_fps) {
+ sprintf(fps_text, "%ld fps",
+ (last_frame == 0) ? 0 : (NANO_TO_SECOND / last_frame));
+ } else {
+ sprintf(fps_text, "%ld us", last_frame / 1000);
+ }
return tui_make_padding(
- tui_make_box(MIN_WIDTH, 1, tui_make_text(fps_text, COLOR_FPS_TEXT),
- COLOR_FPS_BACK),
+ tui_make_button(
+ tui_make_box(MIN_WIDTH, MIN_HEIGHT,
+ tui_make_padding(tui_make_text(fps_text, COLOR_FPS_TEXT,
+ TEXT_STYLE_NORMAL),
+ 0, 0, 1, 1),
+ COLOR_FPS_BACK),
+ on_click),
0, 0, 2, 2);
}
WIDGET *ui_build(TUI *tui) {
return tui_make_box(
MAX_WIDTH, MAX_HEIGHT,
- tui_make_column(tui_make_widget_array(
- fps_counter(tui->last_frame), search_box(),
- tui_make_row(tui_make_widget_array(tui_make_center(tui_make_box(
- MIN_WIDTH, MIN_HEIGHT,
- tui_make_padding(tui_make_text("Hi here", color_init(0xFF0000FF)),
- 2, 2, 2, 2),
- color_init(0xFFFFFFFF))))))),
+ tui_make_column(tui_make_widget_array(fps_counter(tui->last_frame),
+ search_box(), search_body())),
BACKGROUND_COLOR);
}
int main() {
TUI *tui = tui_init();
- tui_start_app(tui, ui_build, 144);
+ tui_start_app(tui, ui_build, FRAME_UNLIMITED);
tui_delete(tui);