1 /* 2 * Copyright 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 complex constraints. 6 */ 7 #ifndef COMPLEX_LAYOUTER_H 8 #define COMPLEX_LAYOUTER_H 9 10 #include <List.h> 11 12 #include "Layouter.h" 13 14 15 namespace BPrivate { 16 namespace Layout { 17 18 class LayoutOptimizer; 19 20 class ComplexLayouter : public Layouter { 21 public: 22 ComplexLayouter(int32 elementCount, 23 float spacing); 24 virtual ~ComplexLayouter(); 25 26 virtual status_t InitCheck() const; 27 28 virtual void AddConstraints(int32 element, int32 length, 29 float min, float max, float preferred); 30 virtual void SetWeight(int32 element, float weight); 31 32 virtual float MinSize(); 33 virtual float MaxSize(); 34 virtual float PreferredSize(); 35 36 virtual LayoutInfo* CreateLayoutInfo(); 37 38 virtual void Layout(LayoutInfo* layoutInfo, float size); 39 40 virtual Layouter* CloneLayouter(); 41 42 private: 43 class MyLayoutInfo; 44 struct Constraint; 45 struct SumItem; 46 struct SumItemBackup; 47 48 bool _Layout(int32 size, SumItem* sums, 49 int32* sizes); 50 bool _AddOptimizerConstraints(); 51 bool _SatisfiesConstraints(int32* sizes) const; 52 bool _SatisfiesConstraintsSums(int32* sums) const; 53 54 void _ValidateLayout(); 55 void _ApplyMaxConstraint( 56 Constraint* currentConstraint, int32 index); 57 void _PropagateChanges(SumItem* sums, int32 toIndex, 58 Constraint* lastMaxConstraint); 59 void _PropagateChangesBack(SumItem* sums, 60 int32 changedIndex, 61 Constraint* lastMaxConstraint); 62 63 void _BackupValues(int32 maxIndex); 64 void _RestoreValues(int32 maxIndex); 65 66 private: 67 int32 fElementCount; 68 int32 fSpacing; 69 Constraint** fConstraints; 70 float* fWeights; 71 SumItem* fSums; 72 SumItemBackup* fSumBackups; 73 LayoutOptimizer* fOptimizer; 74 float fMin; 75 float fMax; 76 int32 fUnlimited; 77 bool fMinMaxValid; 78 bool fOptimizerConstraintsAdded; 79 }; 80 81 } // namespace Layout 82 } // namespace BPrivate 83 84 using BPrivate::Layout::ComplexLayouter; 85 86 87 #endif // COMPLEX_LAYOUTER_H 88