xref: /haiku/src/tests/libs/alm/ComplexButtons.cpp (revision 579f1dbca962a2a03df54f69fdc6e9423f91f20e)
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 		// test size limits
70 		BSize min = fLayout->MinSize();
71 		BSize max = fLayout->MaxSize();
72 		SetSizeLimits(min.Width(), max.Width(), min.Height(), max.Height());
73 	}
74 
75 private:
76 	BALMLayout* fLayout;
77 
78 };
79 
80 
81 int
82 main()
83 {
84 	BApplication app("application/x-vnd.haiku.ComplexButtons");
85 
86 	BRect frameRect;
87 	frameRect.Set(100, 100, 600, 300);
88 	ComplexButtonsWindow* window = new ComplexButtonsWindow(frameRect);
89 	window->Show();
90 
91 	app.Run();
92 	return 0;
93 }
94