170e20761SClemens Zeidler /* 270e20761SClemens Zeidler * Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz 370e20761SClemens Zeidler * Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz 470e20761SClemens Zeidler * Copyright 2010, Clemens Zeidler <haiku@clemens-zeidler.de> 570e20761SClemens Zeidler * Distributed under the terms of the MIT License. 670e20761SClemens Zeidler */ 770e20761SClemens Zeidler 870e20761SClemens Zeidler 970e20761SClemens Zeidler #include <Application.h> 1070e20761SClemens Zeidler #include <Button.h> 1170e20761SClemens Zeidler #include <MenuField.h> 1270e20761SClemens Zeidler #include <PopUpMenu.h> 1370e20761SClemens Zeidler #include <RadioButton.h> 1470e20761SClemens Zeidler #include <SpaceLayoutItem.h> 1570e20761SClemens Zeidler #include <StatusBar.h> 1670e20761SClemens Zeidler #include <StringView.h> 1770e20761SClemens Zeidler #include <TextView.h> 1870e20761SClemens Zeidler #include <Window.h> 1970e20761SClemens Zeidler 2070e20761SClemens Zeidler #include "ALMLayout.h" 212bf5ded1SAlex Wilson #include "ALMLayoutBuilder.h" 2270e20761SClemens Zeidler 2370e20761SClemens Zeidler 24b1f9962bSClemens Zeidler using namespace LinearProgramming; 25b1f9962bSClemens Zeidler 26b1f9962bSClemens Zeidler 2770e20761SClemens Zeidler class ViewsWindow : public BWindow { 2870e20761SClemens Zeidler public: 2970e20761SClemens Zeidler ViewsWindow(BRect frame) 3070e20761SClemens Zeidler : 3137344020SClemens Zeidler BWindow(frame, "ALM Views", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE) 3270e20761SClemens Zeidler { 3370e20761SClemens Zeidler BButton* button1 = new BButton("BButton"); 3470e20761SClemens Zeidler BRadioButton* radioButton = new BRadioButton("BRadioButton", NULL); 3570e20761SClemens Zeidler BButton* button3 = new BButton("3"); 3670e20761SClemens Zeidler BButton* button4 = new BButton("4"); 3770e20761SClemens Zeidler button4->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, 3870e20761SClemens Zeidler B_ALIGN_VERTICAL_CENTER)); 3970e20761SClemens Zeidler BButton* button5 = new BButton("5"); 4070e20761SClemens Zeidler BButton* button6 = new BButton("6"); 4170e20761SClemens Zeidler BTextView* textView1 = new BTextView("textView1"); 4270e20761SClemens Zeidler textView1->SetText("BTextView"); 4370e20761SClemens Zeidler BStatusBar* statusBar = new BStatusBar("BStatusBar", "label", 4470e20761SClemens Zeidler "trailing label"); 4570e20761SClemens Zeidler statusBar->Update(50); 4670e20761SClemens Zeidler 4770e20761SClemens Zeidler BMenu* menu = new BMenu("Menu 1"); 4870e20761SClemens Zeidler BMenuField* menu1 = new BMenuField("MenuField 1", menu); 4970e20761SClemens Zeidler menu->AddItem(new BPopUpMenu("Menu 1")); 5070e20761SClemens Zeidler BStringView* stringView1 = new BStringView("string 1", "string 1"); 5170e20761SClemens Zeidler 5270e20761SClemens Zeidler menu = new BMenu("Menu 2 + long text"); 5370e20761SClemens Zeidler BMenuField* menu2 = new BMenuField("MenuField 2", menu); 5470e20761SClemens Zeidler menu->AddItem(new BPopUpMenu("Menu 2")); 5570e20761SClemens Zeidler BStringView* stringView2 = new BStringView("string 2", "string 2"); 5670e20761SClemens Zeidler 572bf5ded1SAlex Wilson BALM::BALMLayout* layout = new BALMLayout(10, 10); 582bf5ded1SAlex Wilson BALM::BALMLayoutBuilder(this, layout) 592bf5ded1SAlex Wilson .SetInsets(10) 602bf5ded1SAlex Wilson .Add(button1, layout->Left(), layout->Top()) 612bf5ded1SAlex Wilson .StartingAt(button1) 622bf5ded1SAlex Wilson .AddToRight(radioButton) 632bf5ded1SAlex Wilson .AddToRight(BSpaceLayoutItem::CreateGlue()) 642bf5ded1SAlex Wilson .AddToRight(button3) 652bf5ded1SAlex Wilson .StartingAt(radioButton) 662bf5ded1SAlex Wilson .AddBelow(textView1, NULL, NULL, layout->RightOf(button3)) 672bf5ded1SAlex Wilson .AddBelow(button4) 682bf5ded1SAlex Wilson .AddToRight(button5, layout->Right()) 692bf5ded1SAlex Wilson .AddBelow(button6) 702bf5ded1SAlex Wilson .AddBelow(menu1, layout->AddYTab(), layout->Left(), 712bf5ded1SAlex Wilson layout->AddXTab()) 722bf5ded1SAlex Wilson .AddToRight(stringView1) 732bf5ded1SAlex Wilson .AddToRight(BSpaceLayoutItem::CreateGlue(), layout->Right()) 74*6457a651SAlex Wilson .AddBelow(statusBar, NULL, layout->Left(), layout->Right()); 75*6457a651SAlex Wilson 76*6457a651SAlex Wilson // start over so that layout->RightOf() can return accurate results 77*6457a651SAlex Wilson BALM::BALMLayoutBuilder(layout) 782bf5ded1SAlex Wilson .StartingAt(statusBar) 792bf5ded1SAlex Wilson .AddBelow(menu2, layout->Bottom(), layout->Left(), 802bf5ded1SAlex Wilson layout->RightOf(menu1)) 812bf5ded1SAlex Wilson .AddToRight(stringView2) 822bf5ded1SAlex Wilson .AddToRight(BSpaceLayoutItem::CreateGlue(), layout->Right()); 832bf5ded1SAlex Wilson 8470e20761SClemens Zeidler layout->Solver()->AddConstraint(2, layout->TopOf(menu1), -1, 85b1f9962bSClemens Zeidler layout->Bottom(), OperatorType(kEQ), 0); 8670e20761SClemens Zeidler 8770e20761SClemens Zeidler // test size limits 8870e20761SClemens Zeidler BSize min = layout->MinSize(); 8970e20761SClemens Zeidler BSize max = layout->MaxSize(); 9070e20761SClemens Zeidler SetSizeLimits(min.Width(), max.Width(), min.Height(), max.Height()); 9170e20761SClemens Zeidler } 9270e20761SClemens Zeidler 9370e20761SClemens Zeidler }; 9470e20761SClemens Zeidler 9570e20761SClemens Zeidler 9670e20761SClemens Zeidler class Views : public BApplication { 9770e20761SClemens Zeidler public: 9870e20761SClemens Zeidler Views() 9970e20761SClemens Zeidler : 10070e20761SClemens Zeidler BApplication("application/x-vnd.haiku.Views") 10170e20761SClemens Zeidler { 10270e20761SClemens Zeidler BRect frameRect; 10370e20761SClemens Zeidler frameRect.Set(100, 100, 300, 300); 10470e20761SClemens Zeidler ViewsWindow* window = new ViewsWindow(frameRect); 10570e20761SClemens Zeidler window->Show(); 10670e20761SClemens Zeidler } 10770e20761SClemens Zeidler }; 10870e20761SClemens Zeidler 10970e20761SClemens Zeidler 11070e20761SClemens Zeidler int 11170e20761SClemens Zeidler main() 11270e20761SClemens Zeidler { 11370e20761SClemens Zeidler Views app; 11470e20761SClemens Zeidler app.Run(); 11570e20761SClemens Zeidler return 0; 11670e20761SClemens Zeidler } 11770e20761SClemens Zeidler 118