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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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);
}
}
|