1 /* 2 * Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz 3 * Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz 4 * Copyright 2010, Clemens Zeidler <haiku@clemens-zeidler.de> 5 * Distributed under the terms of the MIT License. 6 */ 7 8 9 #include <Application.h> 10 #include <Button.h> 11 #include <MenuField.h> 12 #include <PopUpMenu.h> 13 #include <RadioButton.h> 14 #include <SpaceLayoutItem.h> 15 #include <StatusBar.h> 16 #include <StringView.h> 17 #include <TextView.h> 18 #include <Window.h> 19 20 #include "ALMLayout.h" 21 #include "ALMLayoutBuilder.h" 22 23 24 using namespace LinearProgramming; 25 26 27 class ViewsWindow : public BWindow { 28 public: 29 ViewsWindow(BRect frame) 30 : 31 BWindow(frame, "ALM Views", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE) 32 { 33 BButton* button1 = new BButton("BButton"); 34 BRadioButton* radioButton = new BRadioButton("BRadioButton", NULL); 35 BButton* button3 = new BButton("3"); 36 BButton* button4 = new BButton("4"); 37 button4->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, 38 B_ALIGN_VERTICAL_CENTER)); 39 BButton* button5 = new BButton("5"); 40 BButton* button6 = new BButton("6"); 41 BTextView* textView1 = new BTextView("textView1"); 42 textView1->SetText("BTextView"); 43 BStatusBar* statusBar = new BStatusBar("BStatusBar", "label", 44 "trailing label"); 45 statusBar->Update(50); 46 47 BMenu* menu = new BMenu("Menu 1"); 48 BMenuField* menu1 = new BMenuField("MenuField 1", menu); 49 menu->AddItem(new BPopUpMenu("Menu 1")); 50 BStringView* stringView1 = new BStringView("string 1", "string 1"); 51 52 menu = new BMenu("Menu 2 + long text"); 53 BMenuField* menu2 = new BMenuField("MenuField 2", menu); 54 menu->AddItem(new BPopUpMenu("Menu 2")); 55 BStringView* stringView2 = new BStringView("string 2", "string 2"); 56 57 BALM::BALMLayout* layout = new BALMLayout(10, 10); 58 BALM::BALMLayoutBuilder(this, layout) 59 .SetInsets(10) 60 .Add(button1, layout->Left(), layout->Top()) 61 .StartingAt(button1) 62 .AddToRight(radioButton) 63 .AddToRight(BSpaceLayoutItem::CreateGlue()) 64 .AddToRight(button3) 65 .StartingAt(radioButton) 66 .AddBelow(textView1, NULL, NULL, layout->RightOf(button3)) 67 .AddBelow(button4) 68 .AddToRight(button5, layout->Right()) 69 .AddBelow(button6) 70 .AddBelow(menu1, layout->AddYTab(), layout->Left(), 71 layout->AddXTab()) 72 .AddToRight(stringView1) 73 .AddToRight(BSpaceLayoutItem::CreateGlue(), layout->Right()) 74 .AddBelow(statusBar, NULL, layout->Left(), layout->Right()); 75 76 // start over so that layout->RightOf() can return accurate results 77 BALM::BALMLayoutBuilder(layout) 78 .StartingAt(statusBar) 79 .AddBelow(menu2, layout->Bottom(), layout->Left(), 80 layout->RightOf(menu1)) 81 .AddToRight(stringView2) 82 .AddToRight(BSpaceLayoutItem::CreateGlue(), layout->Right()); 83 84 layout->Solver()->AddConstraint(2, layout->TopOf(menu1), -1, 85 layout->Bottom(), OperatorType(kEQ), 0); 86 87 // test size limits 88 BSize min = layout->MinSize(); 89 BSize max = layout->MaxSize(); 90 SetSizeLimits(min.Width(), max.Width(), min.Height(), max.Height()); 91 } 92 93 }; 94 95 96 class Views : public BApplication { 97 public: 98 Views() 99 : 100 BApplication("application/x-vnd.haiku.Views") 101 { 102 BRect frameRect; 103 frameRect.Set(100, 100, 300, 300); 104 ViewsWindow* window = new ViewsWindow(frameRect); 105 window->Show(); 106 } 107 }; 108 109 110 int 111 main() 112 { 113 Views app; 114 app.Run(); 115 return 0; 116 } 117 118