1: <?php
2: /**
3: * ManiaLib - Lightweight PHP framework for Manialinks
4: *
5: * @see http://code.google.com/p/manialib/
6: * @copyright Copyright (c) 2009-2011 NADEO (http://www.nadeo.com)
7: * @license http://www.gnu.org/licenses/lgpl.html LGPL License 3
8: * @version $Revision: 732 $:
9: * @author $Author: maximeraoust $:
10: * @date $Date: 2012-07-09 16:55:18 +0200 (lun., 09 juil. 2012) $:
11: */
12:
13: namespace ManiaLib\Gui\Layouts;
14:
15: /**
16: * Abstract class used for building layouts
17: */
18: abstract class AbstractLayout extends \ManiaLib\Gui\Component
19: {
20:
21: public $xIndex = 0;
22: public $yIndex = 0;
23: public $zIndex = 0;
24: protected $marginWidth;
25: protected $marginHeight;
26: protected $borderWidth;
27: protected $borderHeight;
28:
29: /**
30: * Default constructor is used to set the size of the layout, just like
31: * \ManiaLib\Gui\Element
32: * @param float Layout's width
33: * @param float Layout's height
34: */
35: function __construct($sizeX = 20, $sizeY = 20)
36: {
37: $this->sizeX = $sizeX;
38: $this->sizeY = $sizeY;
39: }
40:
41: /**
42: * Sets the horizontal margin between two elements of the layout
43: * @param float
44: */
45: function setMarginWidth($marginWidth)
46: {
47: $this->marginWidth = $marginWidth;
48: }
49:
50: /**
51: * Sets the vertical margin between two elements of the layout
52: * @param float
53: */
54: function setMarginHeight($marginHeight)
55: {
56: $this->marginHeight = $marginHeight;
57: }
58:
59: /**
60: * Sets the margin between two elements of the layout
61: * @param Horizontal margin
62: * @param Vertical margin
63: */
64: function setMargin($marginWidth = 0, $marginHeight = 0)
65: {
66: $this->marginWidth = $marginWidth;
67: $this->marginHeight = $marginHeight;
68: }
69:
70: /**
71: * Returns the horizontal margin between two elements of the layout
72: * @return float
73: */
74: function getMarginWidth()
75: {
76: return $this->marginWidth;
77: }
78:
79: /**
80: * Returns the vertical margin between two elements of the layout
81: * @return float
82: */
83: function getMarginHeight()
84: {
85: return $this->marginHeight;
86: }
87:
88: /**
89: * Sets the width between the layout outer border and its content
90: * @param float
91: */
92: function setBorderWidth($borderWidth)
93: {
94: $this->borderWidth = $borderWidth;
95: $this->xIndex = $borderWidth;
96: }
97:
98: /**
99: * Sets the height between the layout outer border and its content
100: * @param float
101: */
102: function setBorderHeight($borderHeight)
103: {
104: $this->borderHeight = $borderHeight;
105: $this->yIndex = - $borderHeight;
106: }
107:
108: /**
109: * Sets the gap between the layout outer border and its content
110: * @param Border width
111: * @param Border height
112: */
113: function setBorder($borderWidth = 0, $borderHeight = 0)
114: {
115: $this->borderWidth = $borderWidth;
116: $this->xIndex = $borderWidth;
117: $this->borderHeight = $borderHeight;
118: $this->yIndex = - $borderHeight;
119: }
120:
121: /**
122: * Returns the width between the layout outer border and its content
123: * @return float
124: */
125: function getBorderWidth()
126: {
127: return $this->borderWidth;
128: }
129:
130: /**
131: * Returns the height between the layout outer border and its content
132: * @return float
133: */
134: function getBorderHeight()
135: {
136: return $this->borderHeight;
137: }
138:
139: final function updateComponent(\ManiaLib\Gui\Component $item)
140: {
141: $item->incPosX($this->xIndex);
142: $item->incPosY($this->yIndex);
143: $item->incPosZ($this->zIndex);
144: }
145:
146: /**
147: * Override this method to perform an action before rendering an item.
148: * Typical use: look for overflow
149: */
150: function preFilter(\ManiaLib\Gui\Component $item)
151: {
152:
153: }
154:
155: /**
156: * Override this method to perform an action after rendering an an item.
157: * Typical use: update x,y,z indexes for the next item
158: */
159: function postFilter(\ManiaLib\Gui\Component $item)
160: {
161:
162: }
163:
164: }
165:
166: ?>