std::string string_input_popup(std::string title, int width, std::string input, std::string desc, std::string identifier, int max_length ) { nc_color title_color = c_ltred; nc_color desc_color = c_green; std::vector<std::string> descformatted; int titlesize = utf8_width(title.c_str()); int startx = titlesize + 2; if ( max_length == 0 ) { max_length = width; } int w_height = 3; int iPopupWidth = (width == 0) ? FULL_SCREEN_WIDTH : width + titlesize + 4; if (iPopupWidth > FULL_SCREEN_WIDTH) { iPopupWidth = FULL_SCREEN_WIDTH; } if ( desc.size() > 0 ) { int twidth = utf8_width(desc.c_str()); if ( twidth > iPopupWidth - 4 ) { twidth = iPopupWidth - 4; } descformatted = foldstring(desc, twidth); w_height += descformatted.size(); } int starty = 1 + descformatted.size(); if ( max_length == 0 ) { max_length = 1024; } int w_y = (TERMY - w_height) / 2; int w_x = ((TERMX > iPopupWidth) ? (TERMX - iPopupWidth) / 2 : 0); WINDOW *w = newwin(w_height, iPopupWidth, w_y, ((TERMX > iPopupWidth) ? (TERMX - iPopupWidth) / 2 : 0)); wborder(w, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX, LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX ); int endx = iPopupWidth - 3; for(int i = 0; i < descformatted.size(); i++ ) { mvwprintz(w, 1 + i, 1, desc_color, "%s", descformatted[i].c_str() ); } mvwprintz(w, starty, 1, title_color, "%s", title.c_str() ); long key = 0; int pos = -1; std::string ret = string_input_win(w, input, max_length, startx, starty, endx, true, key, pos, identifier, w_x, w_y, true ); werase(w); wrefresh(w); delwin(w); refresh(); return ret; }
/* * Call string_input_win / ui_element_input::input_filter and filter the entries list interactively */ std::string uimenu::inputfilter() { std::string identifier = ""; // todo: uimenu.filter_identifier ? long key = 0; int spos = -1; mvwprintz(window, w_height - 1, 2, border_color, "< "); mvwprintz(window, w_height - 1, w_width - 3, border_color, " >"); /* //debatable merit std::string origfilter = filter; int origselected = selected; int origfselected = fselected; int origvshift = vshift; */ do { // filter=filter_input->query(filter, false); filter = string_input_win( window, filter, 256, 4, w_height - 1, w_width - 4, false, key, spos, identifier, 4, w_height - 1 ); // key = filter_input->keypress; if ( key != KEY_ESCAPE ) { if ( scrollby(0, key) == false ) { filterlist(); } show(); } } while(key != '\n' && key != KEY_ESCAPE); if ( key == KEY_ESCAPE ) { /* //perhaps as an option filter = origfilter; selected = origselected; fselected = origfselected; vshift = origvshift; */ filterlist(); } wattron(window, border_color); for( int i = 1; i < w_width - 1; i++ ) { mvwaddch(window, w_height-1, i, LINE_OXOX); } wattroff(window, border_color); return filter; }