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