Compare commits
No commits in common. "0119429514502010b1092e8a2da178d1636bf6fb" and "1a882baab60df711ee825c1ddfd5eeaf8278f0ef" have entirely different histories.
0119429514
...
1a882baab6
@ -6,7 +6,6 @@
|
||||
#include <cstring>
|
||||
#include <curses.h>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <menu.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <panel.h>
|
||||
@ -42,13 +41,11 @@ SOFTWARE.
|
||||
#define NLINES 10
|
||||
#define NCOLS 40
|
||||
|
||||
#define DEFAULT_X_OFFSET 10
|
||||
#define DEFAULT_Y_OFFSET 2
|
||||
|
||||
void init_wins(WINDOW **wins, int n, json marks_json);
|
||||
void win_show(WINDOW *win, char *label, int label_color, int width);
|
||||
|
||||
void marks_page() {
|
||||
|
||||
// DONT FORGET TO UNCOMMENT
|
||||
// json resp_from_api = bakaapi::get_grades();
|
||||
std::ifstream f("test-data/marks2.json");
|
||||
@ -73,8 +70,6 @@ void marks_page() {
|
||||
noecho();
|
||||
keypad(stdscr, TRUE);
|
||||
|
||||
std::clog << COLS << " " << LINES << std::endl;
|
||||
|
||||
/* Initialize all the colors */
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
init_pair(i, i, COLOR_BLACK);
|
||||
@ -124,39 +119,42 @@ void init_wins(WINDOW **wins, int n, json marks_json) {
|
||||
int x, y, i;
|
||||
char label[1500];
|
||||
|
||||
y = DEFAULT_Y_OFFSET;
|
||||
x = DEFAULT_X_OFFSET;
|
||||
y = 2;
|
||||
x = 10;
|
||||
uint8_t curent_color = 0;
|
||||
for (i = 0; i < n; ++i) {
|
||||
wins[i] = newwin(NLINES, NCOLS, y, x);
|
||||
{
|
||||
std::string sub_name = marks_json["Subjects"][i]["Subject"]["Name"];
|
||||
std::string sub_avg_s = marks_json["Subjects"][i]["AverageText"];
|
||||
|
||||
// Calculate label and max_text_length to determine window width
|
||||
std::string sub_name = marks_json["Subjects"][i]["Subject"]["Name"];
|
||||
std::string sub_avg_s = marks_json["Subjects"][i]["AverageText"];
|
||||
sprintf(label, "%s - avg: %s", sub_name.c_str(), sub_avg_s.c_str());
|
||||
sprintf(label, "%s - avg: %s", sub_name.c_str(), sub_avg_s.c_str());
|
||||
}
|
||||
curent_color++;
|
||||
if (curent_color >= 7) {
|
||||
curent_color = 1;
|
||||
}
|
||||
|
||||
// search what mark or label is longest
|
||||
size_t max_text_length = strlen(label);
|
||||
for (int j = 0; j < marks_json["Subjects"][i]["Marks"].size(); j++) {
|
||||
std::string caption = marks_json["Subjects"][i]["Marks"][j]["Caption"];
|
||||
std::string theme = marks_json["Subjects"][i]["Marks"][j]["Theme"];
|
||||
caption = rm_tr_le_whitespace(caption);
|
||||
theme = rm_tr_le_whitespace(theme);
|
||||
max_text_length =
|
||||
std::max({max_text_length, caption.length(), theme.length()});
|
||||
for (int i = 0; i < marks_json["Subjects"][n]["Marks"][i].size(); i++) {
|
||||
size_t tocomp =
|
||||
rm_tr_le_whitespace(marks_json["Subjects"][n]["Marks"][i]["Caption"])
|
||||
.length();
|
||||
if (max_text_length < tocomp) {
|
||||
max_text_length = tocomp;
|
||||
}
|
||||
tocomp =
|
||||
rm_tr_le_whitespace(marks_json["Subjects"][n]["Marks"][i]["Theme"])
|
||||
.length();
|
||||
if (max_text_length < tocomp) {
|
||||
max_text_length = tocomp;
|
||||
}
|
||||
}
|
||||
|
||||
int width = max_text_length + 4;
|
||||
|
||||
// hanndle windows overflowing off screen
|
||||
if (x + width > COLS) {
|
||||
x = DEFAULT_X_OFFSET;
|
||||
y += NLINES + 10;
|
||||
}
|
||||
|
||||
wins[i] = newwin(NLINES, NCOLS, y, x);
|
||||
win_show(wins[i], label, curent_color + 1, width);
|
||||
|
||||
curent_color = (curent_color + 1) % 7;
|
||||
x += width + 5;
|
||||
win_show(wins[i], label, curent_color, width);
|
||||
x += width + 10;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user