getting rid of magic numbers

master
denes 8 years ago
parent 8dc6b415fd
commit 242415e779
Signed by: denes
GPG Key ID: A7D50EAD42F9FC9F

@ -61,6 +61,8 @@ public:
static constexpr size_t TERM_MAX_X = 80; static constexpr size_t TERM_MAX_X = 80;
static constexpr size_t TERM_MAX_Y = 24; static constexpr size_t TERM_MAX_Y = 24;
static constexpr int KEY_ESC = 27; static constexpr int KEY_ESC = 27;
static constexpr size_t current_window_width = TERM_MAX_X/4;
static constexpr size_t current_window_height = TERM_MAX_Y-2;
void static init() void static init()
{ {
@ -96,20 +98,20 @@ public:
{ {
menu_ = new_menu((ITEM **)items_); menu_ = new_menu((ITEM **)items_);
current_win_ = newwin(10, 40, 1, 0); current_win_ = newwin(current_window_height, current_window_width, 1, 0);
keypad(current_win_, TRUE); keypad(current_win_, TRUE);
set_menu_win(menu_, current_win_); set_menu_win(menu_, current_win_);
set_menu_sub(menu_, derwin(current_win_, 6, 38, 3, 1)); set_menu_sub(menu_, derwin(current_win_, current_window_height-4, current_window_width-2, 3, 1));
set_menu_format(menu_, 6, 1); set_menu_format(menu_, current_window_height-4, 1);
set_menu_mark(menu_, " "); set_menu_mark(menu_, " ");
box(current_win_, 0, 0); box(current_win_, 0, 0);
mvwaddch(current_win_, 2, 0, ACS_LTEE); mvwaddch(current_win_, 2, 0, ACS_LTEE);
mvwhline(current_win_, 2, 1, ACS_HLINE, 38); mvwhline(current_win_, 2, 1, ACS_HLINE, current_window_width-2);
mvwaddch(current_win_, 2, 39, ACS_RTEE); mvwaddch(current_win_, 2, current_window_width-1, ACS_RTEE);
mvprintw(TERM_MAX_Y-1, 0, "ESC to exit, cursor keys to navigate"); mvprintw(TERM_MAX_Y-1, 0, "ESC to exit, cursor keys to navigate");
refresh(); refresh();
@ -143,6 +145,7 @@ public:
const std::string prev = history_.back(); const std::string prev = history_.back();
history_.pop_back(); history_.pop_back();
update(prev); update(prev);
break;
} }
case KEY_RIGHT: { case KEY_RIGHT: {
std::string next = item_name(current_item(menu_)); std::string next = item_name(current_item(menu_));
@ -225,8 +228,12 @@ private:
int max_y, max_x; int max_y, max_x;
getmaxyx(win, max_y, max_x); getmaxyx(win, max_y, max_x);
mvwprintw(win, line, border, "%s", std::string(max_x-border*2,' ').c_str()); const int usable_x = max_x-border*2 -1;
mvwprintw(win, line, (max_x - s.length()) / 2, "%s", s.c_str()); const int x = std::max(2, (int)((max_x - s.length()) / 2));
const std::string s1 = s.length() > usable_x ? std::string(s, 0, usable_x) : s;
mvwprintw(win, line, border, "%s", std::string(usable_x+1,' ').c_str());
mvwprintw(win, line, x, "%s", s1.c_str());
refresh(); refresh();
} }

Loading…
Cancel
Save