Distributing elements

From TaskDepender
Jump to: navigation, search
(Design)
(Design)
 
Line 19: Line 19:
 
[[Image:Distribute.png]]
 
[[Image:Distribute.png]]
  
This gives the total space to occupy. Next the total space occupied by the elements must be calculated. This is done by determining the sum of the widths of all the selected elements as illustrated in the figure below:
+
This gives the total space to occupy. Next the total space occupied by the elements must be calculated. This is done by determining the sum of the widths of all the selected elements:
 +
 
 +
<math>W  = \displaystyle\sum_{i=1}^N w_i</math>
 +
 
 +
This is illustrated in the figure below:
  
 
[[Image:Distribute_step_2.png]]
 
[[Image:Distribute_step_2.png]]
Line 27: Line 31:
 
[[Image:Distribute_step_3.png]]
 
[[Image:Distribute_step_3.png]]
  
Assuming that the space between two adjacent elements is ''S'', then a certain element ''i'' must be positioned at:
+
Assuming that the space between two adjacent elements is ''S'', then the edge ''x<sub>i</sub>'' of certain element ''i'' must be positioned at:
  
 
<math>x_i = s_{i-1} + w_{i-1} + S</math>
 
<math>x_i = s_{i-1} + w_{i-1} + S</math>
  
 
with:
 
with:
 +
* <math>s_{1} = x_{min}</math>
 +
* <math>S  = \displaystyle\frac{x_{max}-x_{min}-W}{N-1}</math>
  
<math>S  = \frac{(x_{max}-x_{min})-\sum_i^N}{}</math>
+
This means that the position of the element is given by:
  
 +
<math>X_i =x_i + w_i/2</math>
 +
 +
Since the algorithm assumes the elements being ordered by position of the left edges, this additional step must be performed before running the described algorithm.
 +
 +
The same algorithm can be used for distributing the elements vertically, in which case the equations are:
 +
 +
<math>y_i = s_{i-1} + h_{i-1} + S</math>
 +
 +
with:
 +
* <math>s_{1} = y_{min}</math>
 +
* <math>S  = \displaystyle\frac{y_{max}-y_{min}-H}{N-1}</math>
 +
* <math>H  = \displaystyle\sum_{i=1}^N h_i</math>
  
The steps that need to be performed when the selected elements are to be horizontally distributed:
+
and the position of an element given by:
# Order the selected elements by position of the left edges.
+
# Set <tt>x_min</tt> to hold the left edge of the first element which is the leftmost edge.
+
# Set <tt>x_max</tt> to hold the right edge of the last element which is the rightmost edge.
+
# Set <tt>sum_width</tt> to hold the sum of the widths of all the elements.
+
# Set <tt>s=(x_max-x_min-sum_width)/(N-1)</tt>x_min</tt> to hold the space between two adjacent elements.
+
# Reposition all the elements except the first and the last element to their new position using the determined space.
+
  
<syntaxhighlight lang="cpp">
+
<math>Y_i =y_i + h_i/2</math>
;
+
</syntaxhighlight>
+
  
 
== Implementation ==
 
== Implementation ==

Latest revision as of 15:27, 14 November 2011