1 #include "view_promt.h" 7 int li = text_offset_y;
9 for(std::string line : str_split(message + input,
"\n"))
11 mvwprintw(win, ++li, text_offset_x,
"%s", line.c_str());
12 ci = line.length() + text_offset_x;
15 button_offset_x = (width - label_cancel.length() - sep.length() - label_confirm.length()) / 2;
16 button_offset_y = height - text_offset_y;
20 wattron(win, A_REVERSE);
21 mvwprintw(win, button_offset_y, button_offset_x,
"%s", label_cancel.c_str());
22 wattroff(win, A_REVERSE);
23 mvwprintw(win, button_offset_y, button_offset_x + label_cancel.length(),
"%s", sep.c_str());
24 mvwprintw(win, button_offset_y, button_offset_x + label_cancel.length() + sep.length(),
"%s", label_confirm.c_str());
28 mvwprintw(win, button_offset_y, button_offset_x,
"%s", label_cancel.c_str());
29 mvwprintw(win, button_offset_y, button_offset_x + label_cancel.length(),
"%s", sep.c_str());
30 wattron(win, A_REVERSE);
31 mvwprintw(win, button_offset_y, button_offset_x + label_cancel.length() + sep.length(),
"%s", label_confirm.c_str());
32 wattroff(win, A_REVERSE);
37 void ViewPromt::setMessage(std::string message)
39 this->message = message;
42 void ViewPromt::setConfirm(std::string name, std::function<
void(
int)> call)
48 void ViewPromt::setCancel(std::string name,
bool cancelable)
51 this->cancelable = cancelable;
54 std::string ViewPromt::getInput()
59 std::function<void(
int)> ViewPromt::keypress(
int& key)
61 std::function<void(
int)> ret =
nullptr;
71 selection = (selection + 1 ) % 2;
78 if(getmouse(&event) == OK &&
event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED))
80 size_t column_start = start_x + button_offset_x;
81 size_t row_start = start_y + button_offset_y;
82 size_t mouse_x =
event.x, mouse_y =
event.y;
83 if(mouse_y == row_start)
85 if(cancelable && mouse_x >= column_start && mouse_x < column_start + label_cancel.length())
87 if(selection == 0 || event.bstate & BUTTON1_DOUBLE_CLICKED)
91 if(mouse_x >= column_start + label_cancel.length() + sep.length() && mouse_x < column_start + label_cancel.length() + sep.length() + label_confirm.length())
93 if(selection == 1 || event.bstate & BUTTON1_DOUBLE_CLICKED)
115 if(key >=
' ' && key <=
'~')