Revision: 4539
          http://sourceforge.net/p/vexi/code/4539
Author:   clrg
Date:     2013-08-23 11:13:11 +0000 (Fri, 23 Aug 2013)
Log Message:
-----------
Ratio layout - sizes children in proportion to their declared 'ratio'
e.g. where A.ratio=2 and B.ratio=1, A will be twice the size of B

Added Paths:
-----------
    branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/lib/layout/ratio.t
    branches/vexi3/org.vexi-vexi.widgets/src_main/vexi/layout/ratio.t
    branches/vexi3/org.vexi-vexi.widgets/src_test/test/layout/ratio.t

Added: branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/lib/layout/ratio.t
===================================================================
--- branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/lib/layout/ratio.t   
                        (rev 0)
+++ branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/lib/layout/ratio.t   
2013-08-23 11:13:11 UTC (rev 4539)
@@ -0,0 +1,47 @@
+<!-- Copyright 2013 - see COPYING for details [LGPL] -->
+
+<vexi xmlns:ui="vexi://ui" xmlns:role="org.vexi.lib.role">
+    <role:polarizable />
+    <ui:box>
+        
+        var totalRatio = 0;
+        const updateTotal = function(v) {
+            var oldRatio = trapee.ratio;
+            cascade = v==null?1:v;
+            totalRatio = totalRatio - oldRatio + trapee.ratio;
+            reflow();
+        }
+        
+        thisbox.Children ++= function(v) {
+            if (v) {
+                if (v.ratio==null)
+                    v.ratio = 1;
+                totalRatio += v.ratio;
+                v.ratio ++= updateTotal;
+            } else {
+                const box = thisbox[trapname];
+                totalRatio -= v.ratio;
+            }
+            cascade = v;
+        }
+        
+        thisbox.Resize ++= function(v) {
+            var factor = thisbox[dim] / totalRatio;
+            var remainder = 0;
+            var totalSize = 0;
+            for (var i,child in thisbox) {
+                if (child.display) {
+                    var rawSize = (child.ratio * factor) + remainder;
+                    var actSize = vexi.math.round(rawSize);
+                    remainder = rawSize - actSize;
+                    child[dim] = actSize;
+                    totalSize += actSize;
+                }
+            }
+            if (totalSize != thisbox[dim]) {
+                thisbox[numchildren-1][dim] += (thisbox[dim] - totalSize);
+            }
+        }
+        
+    </ui:box> 
+</vexi>

Added: branches/vexi3/org.vexi-vexi.widgets/src_main/vexi/layout/ratio.t
===================================================================
--- branches/vexi3/org.vexi-vexi.widgets/src_main/vexi/layout/ratio.t           
                (rev 0)
+++ branches/vexi3/org.vexi-vexi.widgets/src_main/vexi/layout/ratio.t   
2013-08-23 11:13:11 UTC (rev 4539)
@@ -0,0 +1,19 @@
+<!-- Copyright 2013 - see COPYING for details [LGPL] -->
+
+<vexi xmlns:ui="vexi://ui" xmlns:meta="vexi://meta" 
xmlns="org.vexi.lib.layout">
+    <meta:doc>
+        <author>Charles Goodwin</author>
+        <name>Grid</name>
+        <desc>Use for forming a packed grid of boxes</desc>
+        <usage>
+            <ratio>
+               <ui:box ratio="1" />
+               <ui:box ratio="2" />
+               <ui:box ratio="0.5" />
+               etc
+            </ratio>
+        </usage>
+    </meta:doc>
+    
+    <ratio />
+</vexi>
\ No newline at end of file

Added: branches/vexi3/org.vexi-vexi.widgets/src_test/test/layout/ratio.t
===================================================================
--- branches/vexi3/org.vexi-vexi.widgets/src_test/test/layout/ratio.t           
                (rev 0)
+++ branches/vexi3/org.vexi-vexi.widgets/src_test/test/layout/ratio.t   
2013-08-23 11:13:11 UTC (rev 4539)
@@ -0,0 +1,52 @@
+<vexi xmlns:meta="vexi://meta" xmlns:ui="vexi://ui" xmlns="vexi.layout">
+    <meta:doc>
+        <author>Charles Goodwin</author>
+    </meta:doc>
+    
+
+    
+   
+
+    
+    <ui:box>
+        var vunit = vexi..vexi.test.vunit;
+        
+        var newBox = function(n, r, f) {
+            var b = vexi.box;
+            b.fill = f;
+            b.name = n;
+            b.ratio = r;
+            return b;
+        };
+        
+        var assertWidth = function(w, b) {
+            vexi.log.info(b.name+".width: "+b.width);
+            vunit..assertEquals(w, b.width);
+        };
+        
+        
+        var b = vexi.box;
+        b.visible ++= function() { return true; };
+        .ratio(b);
+        b[0] = newBox("A",1,"red");
+        b[1] = newBox("B",2,"blue");
+        b[2] = newBox("C",0.5,"green");
+        b[3] = newBox("D",1.5,"yellow");
+        b.width = 100;
+        b.fill = "white";
+        
+        var f = vexi.box;
+        f.layout="place";
+        f[0] = b;
+        vexi.ui.frame = f;
+        f.Press1 ++= function(v) {
+            cascade = v;
+            b.discover();
+            assertWidth(20, b[0]);
+            assertWidth(40, b[1]);
+            assertWidth(10, b[2]);
+            assertWidth(30, b[3]);
+        }
+        
+    </ui:box>
+</vexi>
\ No newline at end of file

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Introducing Performance Central, a new site from SourceForge and 
AppDynamics. Performance Central is your source for news, insights, 
analysis and resources for efficient Application Performance Management. 
Visit us today!
http://pubads.g.doubleclick.net/gampad/clk?id=48897511&iu=/4140/ostg.clktrk
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to