#include #include #include #include #include #include "nuklear.h" #include "tinyfiledialogs.h" #include "constants.h" #include "logger.h" #include "ui.h" #include "utils/size_info.h" static nk_size pct; static bool show_app_about; static char *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) - 30 - 85 - 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); size_info_t info_cur = num2sizeinfo((unsigned long)ui->stat->cur); size_info_t info_total = num2sizeinfo((unsigned long)ui->stat->total); sprintf(status_string, "%.2Lf%s/%.2Lf%s, %hhu%%", info_cur.n, info_cur.unit_str, info_total.n, info_total.unit_str, (unsigned char)pct); } if (ui->stat->is_done) { (ui->stat->total) = 0; // To prevent nuklear further updating status_string } nk_menubar_begin(ui->ctx); nk_layout_row_begin(ui->ctx, NK_STATIC, 30, 1); nk_layout_row_push(ui->ctx, 100); if (nk_menu_begin_label(ui->ctx, "MENU", NK_TEXT_CENTERED, nk_vec2(100, 200))) { nk_layout_row_dynamic(ui->ctx, 30, 1); if (nk_menu_item_label(ui->ctx, "About", NK_TEXT_CENTERED)) show_app_about = nk_true; nk_menu_end(ui->ctx); } nk_layout_row_end(ui->ctx); nk_menubar_end(ui->ctx); if (show_app_about) { /* about popup */ static struct nk_rect s = {100, 100, 600, 300}; if (nk_popup_begin(ui->ctx, NK_POPUP_STATIC, "About", NK_WINDOW_CLOSABLE, s)) { nk_layout_row_dynamic(ui->ctx, 30, 1); nk_label(ui->ctx, "A cross-platform multi-thread downloader", NK_TEXT_LEFT); nk_label(ui->ctx, "By Mole Shang", NK_TEXT_LEFT); SPACER; nk_label(ui->ctx, "hinata is licensed under LGPL-3.0.", NK_TEXT_LEFT); nk_label(ui->ctx, "For further information, checkout", NK_TEXT_LEFT); nk_label(ui->ctx, ".", NK_TEXT_LEFT); nk_popup_end(ui->ctx); } else show_app_about = nk_false; } 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(); outPath = tinyfd_selectFolderDialog("Pick a download folder: ", NULL); if (outPath) { DEBUG_PRINT("tinyfd gets outPath: %s\n", outPath); append_log("Got URL: %s\n", text); add_url(text, outPath, NULL, 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); } }