xref: /haiku/src/tests/libs/alm/ComplexButtons.cpp (revision 2bf5ded1ed0a650fd1a36799f660624a7068dbc9)
1 /*
2  * Copyright 2010, Clemens Zeidler <haiku@clemens-zeidler.de>
3  * Distributed under the terms of the MIT License.
4  */
5 
6 #include <stdio.h>
7 
8 #include <Application.h>
9 #include <Button.h>
10 #include <List.h>
11 #include <Window.h>
12 
13 // include this for ALM
14 #include "ALMLayout.h"
15 #include "ALMLayoutBuilder.h"
16 
17 
18 class ComplexButtonsWindow : public BWindow {
19 public:
20 	ComplexButtonsWindow(BRect frame)
21 		:
22 		BWindow(frame, "ALM Complex Buttons", B_TITLED_WINDOW,
23 			B_QUIT_ON_WINDOW_CLOSE)
24 	{
25 		BButton* button1 = new BButton("A");
26 		BButton* button2 = new BButton("B");
27 		BButton* button3 = new BButton("GHIJ");
28 
29 		BButton* button4 = new BButton("abcdefghijklmnop");
30 		BButton* button5 = new BButton("Foo");
31 
32 		const int32 kOffset = 80;
33 
34 		button1->SetExplicitAlignment(BAlignment(B_ALIGN_USE_FULL_WIDTH,
35 			B_ALIGN_USE_FULL_HEIGHT));
36 		button1->SetExplicitMaxSize(BSize(500, 500));
37 		button1->SetExplicitPreferredSize(BSize(10 + kOffset, B_SIZE_UNSET));
38 
39 		button2->SetExplicitAlignment(BAlignment(B_ALIGN_USE_FULL_WIDTH,
40 			B_ALIGN_USE_FULL_HEIGHT));
41 		button2->SetExplicitMaxSize(BSize(500, 500));
42 		button2->SetExplicitPreferredSize(BSize(10 + kOffset, B_SIZE_UNSET));
43 
44 		button3->SetExplicitAlignment(BAlignment(B_ALIGN_USE_FULL_WIDTH,
45 			B_ALIGN_USE_FULL_HEIGHT));
46 		button3->SetExplicitMaxSize(BSize(500, 500));
47 		button3->SetExplicitPreferredSize(BSize(40 + kOffset, B_SIZE_UNSET));
48 
49 		button4->SetExplicitAlignment(BAlignment(B_ALIGN_USE_FULL_WIDTH,
50 			B_ALIGN_USE_FULL_HEIGHT));
51 		button4->SetExplicitMaxSize(BSize(500, 500));
52 		button4->SetExplicitPreferredSize(BSize(160 + kOffset, B_SIZE_UNSET));
53 
54 		button5->SetExplicitAlignment(BAlignment(B_ALIGN_USE_FULL_WIDTH,
55 			B_ALIGN_USE_FULL_HEIGHT));
56 		button5->SetExplicitMaxSize(BSize(500, 500));
57 		button5->SetExplicitPreferredSize(BSize(30 + kOffset, B_SIZE_UNSET));
58 
59 		BALMLayout* fLayout = new BALMLayout(10, 10);
60 		BALM::BALMLayoutBuilder(this, fLayout)
61 			.Add(button1, fLayout->Left(), fLayout->Top())
62 			.StartingAt(button1)
63 				.AddToRight(button2)
64 				.AddToRight(button3, fLayout->Right())
65 			.AddBelow(button4, fLayout->Bottom(), fLayout->Left(),
66 				fLayout->AddXTab())
67 			.AddToRight(button5, fLayout->Right());
68 
69 		/*
70 		// create a new BALMLayout and use  it for this window
71 		fLayout = new BALMLayout();
72 		SetLayout(fLayout);
73 
74 		fLayout->AddView(button1, fLayout->Left(), fLayout->Top(), NULL,
75 			NULL);
76 		fLayout->AddViewToRight(button2);
77 		fLayout->AddViewToRight(button3, fLayout->Right());
78 		fLayout->AddView(button4, fLayout->Left(), fLayout->BottomOf(button1),
79 			NULL, fLayout->Bottom());
80 		fLayout->AddViewToRight(button5, fLayout->Right());
81 		*/
82 
83 		// test size limits
84 		BSize min = fLayout->MinSize();
85 		BSize max = fLayout->MaxSize();
86 		SetSizeLimits(min.Width(), max.Width(), min.Height(), max.Height());
87 	}
88 
89 private:
90 	BALMLayout* fLayout;
91 
92 };
93 
94 
95 int
96 main()
97 {
98 	BApplication app("application/x-vnd.haiku.ComplexButtons");
99 
100 	BRect frameRect;
101 	frameRect.Set(100, 100, 600, 300);
102 	ComplexButtonsWindow* window = new ComplexButtonsWindow(frameRect);
103 	window->Show();
104 
105 	app.Run();
106 	return 0;
107 }
108