summaryrefslogtreecommitdiff
path: root/src/ui.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui.c')
-rw-r--r--src/ui.c98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/ui.c b/src/ui.c
new file mode 100644
index 0000000..7f1dc52
--- /dev/null
+++ b/src/ui.c
@@ -0,0 +1,98 @@
+#include <limits.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "nuklear.h"
+#include <nfd.h>
+
+#include "constants.h"
+#include "logger.h"
+#include "process_url.h"
+#include "ui.h"
+
+static nk_size pct;
+static nfdchar_t *outPath;
+
+void load_ui(struct ui_struct *ui) {
+ static char text[USHRT_MAX], box_buffer[UINT16_MAX], status_string[UCHAR_MAX];
+ float logGroup_height =
+ nk_window_get_height(ui->ctx) - 80 - 45 - 50 - 35 - 80;
+ ui->logger->extend_box =
+ (logGroup_height - 15) <
+ ((ui->logger->box_lines + 1) * (ui->logger->font_height + 2));
+
+ poll_status(ui->stat);
+ if (ui->stat->total) {
+ pct = (ui->stat->cur) * 100 / (ui->stat->total);
+ sprintf(status_string, "%lu/%lu, %lu%%", ui->stat->cur, ui->stat->total,
+ pct);
+ }
+ if (ui->stat->is_done) {
+ (ui->stat->total) = 0; // To prevent nuklear further updating status_string
+ }
+
+ nk_layout_row_dynamic(ui->ctx, 80, 1);
+ nk_label(ui->ctx, "Hinata", NK_TEXT_CENTERED);
+
+ nk_layout_row_template_begin(ui->ctx, 45);
+ nk_layout_row_template_push_static(ui->ctx, 5);
+ nk_layout_row_template_push_dynamic(ui->ctx);
+ nk_layout_row_template_push_static(ui->ctx, 5);
+ nk_layout_row_template_push_static(ui->ctx, 100);
+ nk_layout_row_template_push_static(ui->ctx, 5);
+ nk_layout_row_template_end(ui->ctx);
+
+ SPACER;
+ nk_edit_string_zero_terminated(ui->ctx, NK_EDIT_FIELD | NK_EDIT_AUTO_SELECT,
+ text, USHRT_MAX - 1, nk_filter_ascii);
+ SPACER;
+ if (nk_button_label(ui->ctx, "下载")) {
+ // Clear logger text
+ clear_log();
+
+ nfdresult_t result = NFD_PickFolder(&outPath, "");
+ if (result == NFD_OKAY) {
+ DEBUG_PRINT("[NFD] outPath: %s\n", outPath);
+ } else if (result == NFD_ERROR) {
+ LOG("NFD", "Error: %s\n", NFD_GetError());
+ }
+
+ if (outPath) {
+ append_log("Got URL: %s\n", text);
+ add_url(text, outPath, NULL, NULL);
+ } else {
+ LOG("NFD", "Please specify a valid file PATH to write to!\n");
+ }
+ }
+ SPACER;
+
+ nk_layout_row_dynamic(ui->ctx, 50, 1);
+ nk_label(ui->ctx, status_string, NK_TEXT_CENTERED);
+
+ nk_layout_row_template_begin(ui->ctx, 35);
+ nk_layout_row_template_push_static(ui->ctx, 5);
+ nk_layout_row_template_push_dynamic(ui->ctx);
+ nk_layout_row_template_push_static(ui->ctx, 5);
+ nk_layout_row_template_end(ui->ctx);
+ SPACER;
+ if (nk_progress(ui->ctx, &pct, MAX_VALUE, !NK_MODIFIABLE)) {
+ // the value of the progress bar changed, the new value is stored in
+ // currentValue
+ }
+ SPACER;
+
+ nk_layout_row_dynamic(ui->ctx, logGroup_height, 1);
+ ui->ctx->style.window.group_padding = nk_vec2(0, 0);
+ if (nk_group_scrolled_begin(ui->ctx, ui->logger->scrollbar, "LogGroup", 0)) {
+ nk_layout_row_dynamic(
+ ui->ctx,
+ MAX(logGroup_height - 15,
+ (ui->logger->box_lines + 1) * (ui->logger->font_height + 2)),
+ 1);
+ nk_edit_buffer(ui->ctx, NK_EDIT_BOX | NK_EDIT_READ_ONLY | NK_EDIT_MULTILINE,
+ ui->logger->text_edit, nk_filter_default);
+ nk_group_scrolled_end(ui->ctx);
+ }
+}