Advertisement
Guest User

Untitled

a guest
Apr 16th, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.33 KB | None | 0 0
  1. #include <nana/gui/wvl.hpp>
  2. #include <nana/gui/place.hpp>
  3. #include <nana/gui/widgets/button.hpp>
  4. #include <nana/gui/widgets/textbox.hpp>
  5.  
  6. int main()
  7. {
  8.     using namespace nana::gui;
  9.  
  10.     //Define widgets
  11.     form fm;
  12.     textbox usr(fm), pswd(fm);
  13.     button login(fm), cancel(fm);
  14.  
  15.     usr.tip_string(STR("User:")).multi_lines(false);
  16.     pswd.tip_string(STR("Password:")).multi_lines(false).mask('*');
  17.  
  18.     login.caption(STR("Login"));
  19.     cancel.caption(STR("Cancel"));
  20.  
  21.     usr.make_event<nana::gui::events::key_char>([&usr,&pswd](const nana::gui::eventinfo& info)
  22.                                                             {
  23.                                                                 if(info.keyboard.key == '\t')
  24.                                                                 {
  25.                                                                     nana::gui::eventinfo event;
  26.                                                                     event.identifier = nana::gui::events::key_char::identifier;
  27.                                                                     event.keyboard.key = nana::gui::keyboard::backspace;
  28.  
  29.                                                                     nana::gui::API::raise_event<nana::gui::events::key_char>(usr,event);
  30.                                                                     nana::gui::API::focus_window(pswd);
  31.                                                                 }
  32.                                                             });
  33.  
  34.     pswd.make_event<nana::gui::events::key_char>([&usr,&pswd](const nana::gui::eventinfo& info)
  35.                                                              {
  36.                                                                  if(info.keyboard.key == '\t')
  37.                                                                  {
  38.                                                                      nana::gui::eventinfo event;
  39.                                                                      event.identifier = nana::gui::events::key_char::identifier;
  40.                                                                      event.keyboard.key = nana::gui::keyboard::backspace;
  41.  
  42.                                                                      nana::gui::API::raise_event<nana::gui::events::key_char>(pswd,event);
  43.                                                                      nana::gui::API::focus_window(usr);
  44.                                                                  }
  45.                                                              });
  46.  
  47.     //Define a place for the form.
  48.     place plc(fm);
  49.  
  50.     //Divide the form into fields
  51.     plc.div("<><weight=80% vertical<><weight=70% vertical<vertical textboxs><weight=25 buttons>><>><>");
  52.  
  53.     //Insert widgets
  54.  
  55.     //The field textboxs is vertical, it automatically adjusts the widgets' top
  56.     //and height. The usr and pswd are single-line textboxs, and we should specify
  57.     //them with a fixed height.
  58.     plc.field("textboxs")<<plc.fixed(usr, 25)<<10<<plc.fixed(pswd, 25);
  59.  
  60.     plc.field("buttons")<<login<<10<<cancel;
  61.  
  62.     //Finially, the widgets should be collocated.
  63.     //Do not miss this line, otherwise the widgets are not collocated
  64.     //until the form is resized.
  65.     plc.collocate();
  66.  
  67.     fm.show();
  68.     exec();
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement