1 /* 2 * Copyright 2006, Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _TWO_DIMENSIONAL_LAYOUT_H 6 #define _TWO_DIMENSIONAL_LAYOUT_H 7 8 9 #include <Layout.h> 10 11 class BLayoutContext; 12 13 14 class BTwoDimensionalLayout : public BLayout { 15 public: 16 BTwoDimensionalLayout(); 17 virtual ~BTwoDimensionalLayout(); 18 19 void SetInsets(float left, float top, float right, 20 float bottom); 21 void GetInsets(float* left, float* top, float* right, 22 float* bottom) const; 23 24 void AlignLayoutWith(BTwoDimensionalLayout* other, 25 enum orientation orientation); 26 27 virtual BSize MinSize(); 28 virtual BSize MaxSize(); 29 virtual BSize PreferredSize(); 30 virtual BAlignment Alignment(); 31 32 virtual bool HasHeightForWidth(); 33 virtual void GetHeightForWidth(float width, float* min, 34 float* max, float* preferred); 35 36 virtual void InvalidateLayout(); 37 38 virtual void LayoutView(); 39 40 protected: 41 struct ColumnRowConstraints { 42 float weight; 43 float min; 44 float max; 45 }; 46 47 struct Dimensions { 48 int32 x; 49 int32 y; 50 int32 width; 51 int32 height; 52 }; 53 54 BSize AddInsets(BSize size); 55 void AddInsets(float* minHeight, float* maxHeight, 56 float* preferredHeight); 57 BSize SubtractInsets(BSize size); 58 59 virtual void PrepareItems(enum orientation orientation); 60 virtual bool HasMultiColumnItems(); 61 virtual bool HasMultiRowItems(); 62 63 virtual int32 InternalCountColumns() = 0; 64 virtual int32 InternalCountRows() = 0; 65 virtual void GetColumnRowConstraints( 66 enum orientation orientation, 67 int32 index, 68 ColumnRowConstraints* constraints) = 0; 69 virtual void GetItemDimensions(BLayoutItem* item, 70 Dimensions* dimensions) = 0; 71 72 private: 73 class CompoundLayouter; 74 class LocalLayouter; 75 class VerticalCompoundLayouter; 76 77 friend class LocalLayouter; 78 79 void _ValidateMinMax(); 80 BLayoutContext* _CurrentLayoutContext(); 81 82 protected: 83 float fLeftInset; 84 float fRightInset; 85 float fTopInset; 86 float fBottomInset; 87 float fHSpacing; 88 float fVSpacing; 89 90 private: 91 LocalLayouter* fLocalLayouter; 92 }; 93 94 #endif // _TWO_DIMENSIONAL_LAYOUT_H 95