1 /* 2 * Copyright 2006, Ingo Weinhold <bonefish@cs.tu-berlin.de>. 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5 6 #include "OneElementLayouter.h" 7 8 #include <Size.h> 9 10 11 class OneElementLayouter::MyLayoutInfo : public LayoutInfo { 12 public: 13 float fSize; 14 15 MyLayoutInfo() 16 : fSize(0) 17 { 18 } 19 20 virtual float ElementLocation(int32 element) 21 { 22 return 0; 23 } 24 25 virtual float ElementSize(int32 element) 26 { 27 return fSize; 28 } 29 }; 30 31 32 // constructor 33 OneElementLayouter::OneElementLayouter() 34 : fMin(-1), 35 fMax(B_SIZE_UNLIMITED), 36 fPreferred(-1) 37 { 38 } 39 40 // destructor 41 OneElementLayouter::~OneElementLayouter() 42 { 43 } 44 45 // AddConstraints 46 void 47 OneElementLayouter::AddConstraints(int32 element, int32 length, 48 float min, float max, float preferred) 49 { 50 fMin = max_c(fMin, min); 51 fMax = min_c(fMax, max); 52 fMax = max_c(fMax, fMin); 53 fPreferred = max_c(fPreferred, preferred); 54 fPreferred = max_c(fPreferred, fMin); 55 fPreferred = min_c(fPreferred, fMax); 56 } 57 58 // SetWeight 59 void 60 OneElementLayouter::SetWeight(int32 element, float weight) 61 { 62 // not needed 63 } 64 65 // MinSize 66 float 67 OneElementLayouter::MinSize() 68 { 69 return fMin; 70 } 71 72 // MaxSize 73 float 74 OneElementLayouter::MaxSize() 75 { 76 return fMax; 77 } 78 79 // PreferredSize 80 float 81 OneElementLayouter::PreferredSize() 82 { 83 return fPreferred; 84 } 85 86 // CreateLayoutInfo 87 LayoutInfo* 88 OneElementLayouter::CreateLayoutInfo() 89 { 90 return new MyLayoutInfo; 91 } 92 93 // Layout 94 void 95 OneElementLayouter::Layout(LayoutInfo* layoutInfo, float size) 96 { 97 ((MyLayoutInfo*)layoutInfo)->fSize = max_c(size, fMin); 98 } 99 100 // CloneLayouter 101 Layouter* 102 OneElementLayouter::CloneLayouter() 103 { 104 OneElementLayouter* layouter = new OneElementLayouter; 105 layouter->fMin = fMin; 106 layouter->fMax = fMax; 107 layouter->fPreferred = fPreferred; 108 109 return layouter; 110 } 111