1 /* 2 * Copyright 2006-2007, Ingo Weinhold <bonefish@cs.tu-berlin.de>. 3 * All rights reserved. Distributed under the terms of the MIT License. 4 * 5 * Layouter implementation that can handle simple layout constraints 6 * (restricting one element) only. It is 7 */ 8 #ifndef SIMPLE_LAYOUTER_H 9 #define SIMPLE_LAYOUTER_H 10 11 #include "Layouter.h" 12 13 14 class BList; 15 16 namespace BPrivate { 17 namespace Layout { 18 19 class SimpleLayouter : public Layouter { 20 public: 21 SimpleLayouter(int32 elementCount, 22 float spacing); 23 virtual ~SimpleLayouter(); 24 25 virtual void AddConstraints(int32 element, int32 length, 26 float min, float max, float preferred); 27 virtual void SetWeight(int32 element, float weight); 28 29 virtual float MinSize(); 30 virtual float MaxSize(); 31 virtual float PreferredSize(); 32 33 virtual LayoutInfo* CreateLayoutInfo(); 34 35 virtual void Layout(LayoutInfo* layoutInfo, float size); 36 37 virtual Layouter* CloneLayouter(); 38 39 static void DistributeSize(int32 size, float weights[], 40 int32 sizes[], int32 count); 41 42 private: 43 static long _CalculateSumWeight(BList& elementInfos); 44 45 void _ValidateMinMax(); 46 void _LayoutMax(); 47 void _LayoutStandard(); 48 49 private: 50 class ElementLayoutInfo; 51 class ElementInfo; 52 class MyLayoutInfo; 53 54 int32 fElementCount; 55 int32 fSpacing; 56 ElementInfo* fElements; 57 58 int32 fMin; 59 int32 fMax; 60 int32 fPreferred; 61 62 bool fMinMaxValid; 63 64 MyLayoutInfo* fLayoutInfo; 65 }; 66 67 } // namespace Layout 68 } // namespace BPrivate 69 70 using BPrivate::Layout::SimpleLayouter; 71 72 #endif // SIMPLE_LAYOUTER_H 73