1+ #include " ../gui.hpp"
2+
3+
4+ std::pair<bool , std::string> GUI::input_box (nana::window owner, std::string caption, std::string prompt)
5+ {
6+ using widgets::theme;
7+ using namespace nana ;
8+ std::pair<bool , std::string> ret;
9+
10+ themed_form fm {nullptr , owner, {}, appear::decorate{}};
11+ fm.center (400 , 165 );
12+ fm.caption (caption);
13+ fm.snap (conf.cbsnap );
14+
15+ fm.div (R"( vert margin=20
16+ <l_prompt weight=30> <weight=15>
17+ <weight=25 <tb>> <weight=20>
18+ <<><btn_ok weight=90> <weight=20> <btn_cancel weight=90> <>>
19+ )" );
20+
21+ ::widgets::Label l_prompt {fm, prompt};
22+ l_prompt.text_align (align::center, align_v::center);
23+
24+ ::widgets::Textbox tb {fm};
25+ tb.multi_lines (false );
26+ tb.padding (0 , 5 , 0 , 5 );
27+ tb.events ().key_press ([&](const arg_keyboard &arg)
28+ {
29+ if (arg.key == keyboard::enter)
30+ {
31+ ret = {true , tb.caption ()};
32+ fm.close ();
33+ }
34+ });
35+
36+ ::widgets::Button btn_ok {fm, " OK" }, btn_cancel {fm, " Cancel" };
37+ btn_ok.events ().click ([&] { ret = {true , tb.caption ()}; fm.close (); });
38+ btn_cancel.events ().click ([&] { ret = {false , " " }; fm.close (); });
39+
40+ fm[" l_prompt" ] << l_prompt;
41+ fm[" tb" ] << tb;
42+ fm[" btn_ok" ] << btn_ok;
43+ fm[" btn_cancel" ] << btn_cancel;
44+
45+ fm.theme_callback ([&](bool dark)
46+ {
47+ fm.bgcolor (theme::fmbg.blend (dark ? colors::white : colors::grey, .04 ));
48+ fm.refresh_widgets ();
49+ return false ;
50+ });
51+
52+ if (conf.cbtheme == 2 )
53+ fm.system_theme (true );
54+ else fm.dark_theme (conf.cbtheme == 0 );
55+
56+ tb.focus ();
57+ fm.collocate ();
58+ fm.activate ();
59+ fm.show ();
60+ fm.modality ();
61+ return ret;
62+ }
0 commit comments