Clean up some qnav layout logic
@@ -110,25 +110,30 @@ void qnav_stack_push(Qblock* qb, int height, int width) {
}
#endif
int top = 0, left = 0;
- int totalheight = height + 2, totalwidth = width + 3;
+ int total_h = height + 2, total_w = width + 3;
if (qnav_stack.count > 0) {
WINDOW* w = qnav_stack.blocks[qnav_stack.count - 1]->outer_window;
int prev_y, prev_x, prev_h, prev_w;
getbegyx(w, prev_y, prev_x);
getmaxyx(w, prev_h, prev_w);
+ // Start by trying to position the item to the right of the previous item.
left = prev_x + prev_w + 0;
int term_h, term_w;
getmaxyx(stdscr, term_h, term_w);
// Check if we'll run out of room if we position the new item to the right
// of the existing item (with the same Y position.)
- if (left + totalwidth > term_w) {
+ if (left + total_w > term_w) {
// If we have enough room if we position just below the previous item in
// the stack, do that instead of positioning to the right of it.
- if (prev_x + totalwidth <= term_w &&
- totalheight < term_h - (prev_y + prev_h)) {
+ if (prev_x + total_w <= term_w && total_h < term_h - (prev_y + prev_h)) {
top = prev_y + prev_h;
left = prev_x;
}
+ // If the item doesn't fit there, but it's less wide than the terminal,
+ // right-align it to the edge of the terminal.
+ else if (total_w < term_w) {
+ left = term_w - total_w;
+ }
// Otherwise, just start the layout over at Y=0,X=0
else {
left = 0;
@@ -137,7 +142,7 @@ void qnav_stack_push(Qblock* qb, int height, int width) {
}
qnav_stack.blocks[qnav_stack.count] = qb;
++qnav_stack.count;
- qb->outer_window = newwin(totalheight, totalwidth, top, left);
+ qb->outer_window = newwin(total_h, total_w, top, left);
qb->content_window = derwin(qb->outer_window, height, width, 1, 1);
qnav_stack.stack_changed = true;
}
