ref: df162ea4a01ebdc77060c99ef76240f3809df54a
parent: abbb42a4e481d05ec3b445728c61a4dabb3b337f
author: cancel <cancel@cancel.fm>
date: Thu Dec 13 19:52:37 EST 2018
Add active/inactive indicator for qnav blocks
--- a/term_util.c
+++ b/term_util.c
@@ -58,11 +58,13 @@
}
qnav_stack.blocks[qnav_stack.count] = out;
++qnav_stack.count;
+ out->title = NULL;
out->outer_window = newwin(height + 2, width + 3, 0, left);
out->content_window = derwin(out->outer_window, height, width, 1, 1);
out->tag = tag;
qnav_stack.stack_changed = true;
}
+
Qnav_block* qnav_top_block() {
if (qnav_stack.count == 0)
return NULL;
@@ -83,23 +85,40 @@
qnav_stack.blocks[qnav_stack.count] = NULL;
qnav_stack.stack_changed = true;
}
-void qnav_draw_box(Qnav_block* qb) { box(qb->outer_window, 0, 0); }
-void qnav_draw_title(Qnav_block* qb, char const* title) {
+void qnav_draw_box_attr(Qnav_block* qb, unsigned int attr) {
+ wborder(qb->outer_window, ACS_VLINE | attr, ACS_VLINE | attr,
+ ACS_HLINE | attr, ACS_HLINE | attr, ACS_ULCORNER | attr,
+ ACS_URCORNER | attr, ACS_LLCORNER | attr, ACS_LRCORNER | attr);
+}
+void qnav_draw_box(Qnav_block* qb) { qnav_draw_box_attr(qb, A_DIM); }
+void qnav_draw_title(Qnav_block* qb, char const* title, int attr) {
wmove(qb->outer_window, 0, 2);
+ attr_t attrs = A_NORMAL;
+ short pair = 0;
+ wattr_get(qb->outer_window, &attrs, &pair, NULL);
+ wattrset(qb->outer_window, attr);
wprintw(qb->outer_window, title);
+ wattr_set(qb->outer_window, attrs, pair, NULL);
}
+void qnav_set_title(Qnav_block* qb, char const* title) { qb->title = title; }
+
+void qnav_print_frame(Qnav_block* qb, bool active) {
+ qnav_draw_box_attr(qb, active ? A_BOLD : A_DIM);
+ if (qb->title) {
+ qnav_draw_title(qb, qb->title, active ? A_BOLD : A_DIM);
+ }
+}
+
WINDOW* qmsg_window(Qmsg* qm) { return qm->nav_block.content_window; }
void qmsg_set_title(Qmsg* qm, char const* title) {
- Qnav_block* qb = &qm->nav_block;
- qnav_draw_title(qb, title);
+ qnav_set_title(&qm->nav_block, title);
}
Qmsg* qmsg_push(int height, int width) {
Qmsg* qm = malloc(sizeof(Qmsg));
qnav_stack_push(Qnav_type_qmsg, height, width, &qm->nav_block);
- qnav_draw_box(&qm->nav_block);
return qm;
}
--- a/term_util.h
+++ b/term_util.h
@@ -48,6 +48,7 @@
Qnav_type_tag tag;
WINDOW* outer_window;
WINDOW* content_window;
+ char const* title;
} Qnav_block;
typedef struct {
@@ -88,10 +89,10 @@
void qnav_init();
void qnav_deinit();
-void qnav_draw_box(Qnav_block* qb);
-void qnav_draw_title(Qnav_block* qb, char const* title);
+void qnav_set_title(Qnav_block* qb, char const* title);
Qnav_block* qnav_top_block();
void qnav_stack_pop();
+void qnav_print_frame(Qnav_block* qb, bool active);
Qmsg* qmsg_push(int height, int width);
WINDOW* qmsg_window(Qmsg* qm);
--- a/tui_main.c
+++ b/tui_main.c
@@ -1459,8 +1459,7 @@
qmenu_add_spacer(qm);
qmenu_add_choice(qm, "Quit", Main_menu_quit);
qmenu_push_to_nav(qm);
- qnav_draw_box(&qm->nav_block);
- qnav_draw_title(&qm->nav_block, "ORCA");
+ qnav_set_title(&qm->nav_block, "ORCA");
}
void push_controls_msg() {
@@ -1731,7 +1730,6 @@
if (qnav_stack.stack_changed) {
werase(stdscr);
drew_any = true;
- qnav_stack.stack_changed = false;
}
if (ged_is_draw_dirty(&ged_state) || drew_any) {
werase(cont_window);
@@ -1741,10 +1739,14 @@
}
for (Usz i = 0; i < qnav_stack.count; ++i) {
Qnav_block* qb = qnav_stack.blocks[i];
+ if (qnav_stack.stack_changed) {
+ qnav_print_frame(qb, i == qnav_stack.count - 1);
+ }
touchwin(qb->outer_window);
wnoutrefresh(qb->outer_window);
drew_any = true;
}
+ qnav_stack.stack_changed = false;
if (drew_any)
doupdate();
diff = stm_laptime(&last_time);