xref: /haiku/src/kits/interface/layouter/CollapsingLayouter.h (revision 002f37b0cca92e4cf72857c72ac95db5a8b09615)
1 /*
2  * Copyright 2011, Haiku, Inc.
3  * All rights reserved. Distributed under the terms of the MIT License.
4  */
5 #ifndef COLLAPSING_LAYOUTER_H
6 #define COLLAPSING_LAYOUTER_H
7 
8 #include "Layouter.h"
9 
10 
11 namespace BPrivate {
12 namespace Layout {
13 
14 
15 /* This layouter wraps either a Compound, Simple or OneElement layouter, and
16  * removes elements which have no constraints, or min/max constraints of
17  * B_SIZE_UNSET. The child layouter is given only the constraints for the
18  * remaining elements. When using the LayoutInfo of this layouter,
19  * collapsed (removed) elements are given no space on screen.
20  */
21 class CollapsingLayouter : public Layouter {
22 public:
23 								CollapsingLayouter(int32 elementCount,
24 									float spacing);
25 	virtual						~CollapsingLayouter();
26 
27 	virtual	void				AddConstraints(int32 element, int32 length,
28 									float min, float max, float preferred);
29 	virtual	void				SetWeight(int32 element, float weight);
30 
31 	virtual	float				MinSize();
32 	virtual	float				MaxSize();
33 	virtual	float				PreferredSize();
34 
35 	virtual	LayoutInfo*			CreateLayoutInfo();
36 
37 	virtual	void				Layout(LayoutInfo* layoutInfo, float size);
38 
39 	virtual	Layouter*			CloneLayouter();
40 
41 
42 private:
43 	class	ProxyLayoutInfo;
44 	struct	Constraint;
45 	struct	ElementInfo;
46 
47 			void				_ValidateLayouter();
48 			Layouter*			_CreateLayouter();
49 			void				_DoCollapse();
50 			void				_AddConstraints();
51 			void				_AddConstraints(int32 position,
52 									const Constraint* c);
53 			void				_SetWeights();
54 
55 			int32				fElementCount;
56 			ElementInfo*		fElements;
57 			int32				fValidElementCount;
58 			bool				fHaveMultiElementConstraints;
59 			float				fSpacing;
60 			Layouter*			fLayouter;
61 };
62 
63 } // namespace Layout
64 } // namespace BPrivate
65 
66 using BPrivate::Layout::CollapsingLayouter;
67 
68 #endif // COLLAPSING_LAYOUTER_H
69