Login | Register
My pages Projects Community openCollabNet

algierlib
Wiki: HowTo/LayoutCalculator

Edit this page | HowTo | Links to this page | Page information | Attachments | Refresh page

 

How-to layout a Calculator

The code example works only with version 0.6.0 and later.

   1 #include <algier/window.hpp>
   2 #include <algier/button.hpp>
   3 #include <algier/layout.hpp>
   4 #include <algier/field.hpp>
   5 
   6 int main()
   7 {
   8         using namespace algier;
   9 
  10         window_ptr win(dialog::create(L"Calculator"));
  11 
  12         panel_ptr calc_top(panel::create());
  13         field_ptr tf(textfield::create(15));
  14         win->attach(calc_top);
  15         calc_top->attach(tf);
  16         calc_top->relayout(flow_layout::create());
  17 
  18         panel_ptr calc_center(panel::create());
  19         win->attach(calc_center);
  20         calc_center->attach(action_button::create(L"7"));
  21         calc_center->attach(action_button::create(L"8"));
  22         calc_center->attach(action_button::create(L"9"));
  23         calc_center->attach(action_button::create(L"/"));
  24         calc_center->attach(action_button::create(L"4"));
  25         calc_center->attach(action_button::create(L"5"));
  26         calc_center->attach(action_button::create(L"6"));
  27         calc_center->attach(action_button::create(L"*"));
  28         calc_center->attach(action_button::create(L"1"));
  29         calc_center->attach(action_button::create(L"2"));
  30         calc_center->attach(action_button::create(L"3"));
  31         calc_center->attach(action_button::create(L"-"));
  32         calc_center->attach(action_button::create(L"0"));
  33         calc_center->attach(action_button::create(L"."));
  34         calc_center->attach(action_button::create(L"="));
  35         calc_center->attach(action_button::create(L"+"));
  36 
  37         std::tr1::array<algier::form_spec, 16> specs = { 
  38                 stretch,  stretch, stretch, stretch,
  39                 stretch,  stretch, stretch, stretch,
  40                 stretch,  stretch, stretch, stretch,
  41                 stretch,  stretch, stretch, stretch
  42         };
  43 
  44         layout_ptr form(make_form_layout(4, specs.begin(), specs.end()));
  45         calc_center->relayout(form);
  46 
  47         border_layout_ptr frame_layout(new border_layout());
  48         frame_layout->place(calc_center, center);
  49         frame_layout->place(calc_top, top);
  50         win->relayout(frame_layout);
  51         win->size(dimension_t(170,180));
  52 
  53         win->show();
  54 
  55         join();
  56 }

HowTo/LayoutCalculator (last edited 2011-03-08 22:56:59 -0700 by ?amin)