Revision: 4776
          http://sourceforge.net/p/vexi/code/4776
Author:   clrg
Date:     2015-03-04 14:33:50 +0000 (Wed, 04 Mar 2015)
Log Message:
-----------
Change flow logic to use Resize trap

Modified Paths:
--------------
    branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/lib/layout/flow.t
    branches/vexi3/org.vexi-vexi.widgets/src_main/vexi/layout/flow.t

Modified: 
branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/lib/layout/flow.t
===================================================================
--- branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/lib/layout/flow.t    
2015-03-03 01:36:32 UTC (rev 4775)
+++ branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/lib/layout/flow.t    
2015-03-04 14:33:50 UTC (rev 4776)
@@ -1,223 +1,114 @@
-<!-- Copyright 2009 - see COPYING for details [LGPL] -->
+<!-- Copyright 2015 - see COPYING for details [LGPL] -->
 
-<vexi xmlns:ui="vexi://ui" xmlns:meta="vexi://meta" xmlns="org.vexi.lib.role">
-    <meta:doc>
-        <author>Charles Goodwin</author>
-        <notes>A box that flows children against its orient</notes>
-        <todo>
-            * support right to left
-            * optionally defer reflow
-            * more thorough documentation
-        </todo>
-    </meta:doc>
+<vexi xmlns:ui="vexi://ui"
+      xmlns:meta="vexi://meta"
+      xmlns="org.vexi.lib.role">
     
-    <polarizable />
-    <ui:box align="topleft" layout="layer">
+    <!--polarizable /-->
+    <ui:box layout="place" align="topleft">
         
-        thisbox.flow = true;
-        thisbox.hardwrap = 0;
-        
-        thisbox.v_ALIGN_NEAR = true;
-        thisbox.v_ALIGN_FAR = false;
-        
-        // assign static trap functions
-        thisbox.Children  ++= static.ChildrenWrite;
-        thisbox.align     ++= static.alignWrite;
-        thisbox.flow      ++= static.flowWrite;
-        thisbox.orient    ++= static.invokeReflow;
-        thisbox.hardwrap  ++= static.hardwrapWrite;
-        thisbox.reflow    ++= static.invokeReflow;
-        
-    </ui:box>
+        var _x;
+        var _y;
+        var _width;
+        var _height;
     
-    /** generic trap to invoke reflow */
-    static.invokeReflow = function(v) {
-        cascade = v;
-        var t = trapee;
-        static.reflowBlock(t, t.dim, t.pos, t.flip(t.pos));
-    }
-    
-    /** synchronizes the block and it's contents with it's current size */
-    static.reflowBlock = function(b) {
-        // do not do anything with 0 sized flow parent
-        if (b.flow and b[b.dim] == 0 and b.hardwrap == 0) {
-            return;
-        }
+        var dirty;
+        var entered = false;
         
-        var dim = b.dim;
-        var pos = b.pos;
-        var f_dim = b.flip(dim);
-        var f_pos = b.flip(pos);
-        var contentdim = b.contentdim;
+        const reflowTrap = function(v) {
+            if (v != trapee[trapname]) {
+                cascade = v;
+                reflow();
+            }
+        };
         
-        var cur_dim = 0;   // dimension bounds imposed by placing children
-        var cur_pos = 0;   // current position to assign to children
-        var cur_f_pos = 0; // current flip(position) to assign to children
-        var cur_f_dim = 0; // current flip(dim) of line
-        var eol = false;   // end of line indicator
-        var sol = 0;       // index of child at start of line
-        var offset;        // used to store alignment offset
-        var i = 0;         // index reference
-        var c, prevtype;
-
-        // for efficiency, only fetch these once
-        var numchildren = b.numchildren;
-        var align_near = b.v_ALIGN_NEAR;
-        var offset_div = b.v_ALIGN_FAR ? 1 : 2;
-        var fontheight = b.fontheight;
-        var wrap_dim = b.hardwrap ? b.hardwrap : b[dim];
-        
-        // single line behaviour
-        if (!b.flow) {
-            for (var j=0; numchildren>j; j++) {
-                c = b[j];
-                c[pos] = cur_pos;
-                c[f_pos] = 0;
-                cur_pos += c[contentdim];
-                c[dim] = c[contentdim];
-                if (c[f_contentdim] > cur_f_dim) {
-                    cur_f_dim = c[f_contentdim];
-                }
+        const max = vexi.math.max;
+        const doReflow = function() {
+            if (entered) {
+                dirty = true;
+                return;
             }
-            if (!align_near) {
-                offset = (wrap_dim-cur_pos) / offset_div;
-                for (var j=0; numchildren>j; j++) {
-                    b[j][pos] += offset;
+            entered = true;
+            try {
+                if (!visible) {
+                    return;
+                } else {
+                    dirty = false;
                 }
+                
+                var rankSize = 0;
+                var offsetRank = 0;
+                var offset = 0;
+                for (var i, b in thisbox) {
+                    var offset0 = offset;
+                    var offsetRank1 = offsetRank; 
+                    var offset1 = offset+b[_width];
+                    if (offset1>thisbox[_width] and i!=0) {
+                        offsetRank1 += rankSize;
+                        offset0 = 0;
+                        offset1 = b[_width];
+                        rankSize = 0;
+                    }
+                    
+                    rankSize = max(rankSize, b[_height]);
+                    
+                    b[_x] = offset0;
+                    b[_y] = offsetRank1;
+//                  trace(i+" ("+b.x+","+b.y+") ("+b.width+","+b.height+")");
+                    offset = offset1;     
+                    offsetRank = offsetRank1;            
+                    
+                    b[_width]  ++= reflowTrap;
+                    b[_height] ++= reflowTrap;
+                }
+                thisbox[_height] = offsetRank + rankSize;
+//              // HACK 
+//              if (offsetRank==0 and offset==0) {
+//                  dirty = true;
+//              }
+            } finally {
+                entered = false;
             }
-            b[f_mindim] = cur_f_dim;
-            b[mindim] = cur_pos;
-            return;
+        };
+        
+        Resize ++= function(v) {
+            doReflow();
         }
         
-        // multiline lay out words
-        if (numchildren) do {
-            w = b[i];
-            // deal with whitespace
-            if (1>=w.chartype) {
-                if (w.linebreak) {
-                    w[pos] = cur_pos;
-                    w[f_pos] = cur_f_pos;
-                    eol = true;
-                } else if (cur_pos + w[contentdim] > wrap_dim) {
-                    w[dim] = 0;
-                } else {
-                    w[dim] = w[contentdim];
-                    w[pos] = cur_pos;
-                    w[f_pos] = cur_f_pos;
-                    cur_pos += w[contentdim];
-                }
-            // normal words
+        
+        
+        thisbox.orient ++= function(v){
+            cascade = v;
+            if ("horizontal"==v) {
+                _x = "x";
+                _y = "y";
+                _width = "width";
+                _height = "height";
             } else {
-                if (cur_pos + w[contentdim] > wrap_dim and cur_pos > 0) {
-                    eol = true;
-                    i--;
-                } else {
-                    w[dim] = w[contentdim];
-                    w[pos] = cur_pos;
-                    w[f_pos] = cur_f_pos;
-                    cur_pos += w[contentdim];
-                }
+                _x = "y";
+                _y = "x";
+                _height = "width";
+                _width = "height";
             }
-            // line height
-            if (!eol and w.minheight > cur_height) {
-                cur_height = w.minheight;
-            }
-            // move onto next word
-            i++;
-            // process completed lines
-            if (eol or i==numchildren) {
-                offset = align_near ? 0 : ((wrap_dim-cur_pos) / offset_div);
-                for (var j=sol; i>j; j++) {
-                    w = b[j];
-                    w[f_dim] = cur_height;
-                    w[pos] += offset;
-                }
-                if (cur_pos > cur_dim) {
-                    cur_dim = cur_pos;
-                }
-                cur_pos = 0;
-                cur_f_pos += cur_f_dim;
-                cur_f_dim = 0; // fontheight
-                eol = false;
-                sol = i;
-            }
-        } while (numchildren>i);
+        };
         
-        // set block height
-        b[f_dim] = cur_f_pos > 0 ? cur_f_pos : trapee[min_f_dim];
-        if (b.hardwrap) {
-            b[dim] = cur_dim;
-        }
-    }
-    
-    // trap functions ////////////////
-    
-    /** trap: update new children to identify themselves as the current word */
-    static.ChildrenWrite = function(v) {
-        // child added
-        if (v != null) {
-            v.Enter --= trapee.activeTrap;
-            v.Enter ++= trapee.activeTrap;
-        // child removed
-        } else {
-            var c = trapee[arguments.trapname];
-            c.Enter --= trapee.activeTrap;
-        }
-        // need to do this after removal for c to be valid
-        cascade = v;
-    }
-    
-    /** trap: set whether this is a flowing (multiline) text block or not 
(singleline) */
-    static.flowWrite = function(v)  {
-        cascade = v;
-        var t = trapee;
-        if (v) {
-            if (!trapee.hardwrap) {
-                t[t.dim] ++= static.invokeReflow;
+        orient = "horizontal";
+        
+        thisbox.width  ++= reflowTrap;
+        thisbox.height ++= reflowTrap;
+        
+        thisbox.Children ++= function(v) {
+            cascade = v;
+            if (v == null) {
+                const v0 = thisbox[trapname];
+                if (v0) {
+                       v0[_width]  --= reflowTrap;
+                       v0[_height] --= reflowTrap;
+                   }
             }
-            t[t.mindim] = 0;
-        } else {
-            t[t.dim] --= static.invokeReflow;
-        }
+            reflow();
+        };
         
-        t.reflow = true;
-    }
+    </ui:box>
     
-    /** trap to set the textual alignment of this block */
-    static.textalignWrite = function(v) {
-        cascade = v;
-        switch(v) {
-        case "left":
-            trapee.ALIGN_NEAR = true;
-            trapee.ALIGN_FAR = false;
-            break;
-            
-        case "center":
-            trapee.ALIGN_NEAR = false;
-            trapee.ALIGN_FAR = false;
-            break;
-            
-        case "right":
-            trapee.ALIGN_NEAR = false;
-            trapee.ALIGN_FAR = true;
-            break;
-        }
-    }
-    
-    /** reset block dimensions if wrapwidth is unset */
-    static.hardwrapWrite = function(v) {
-        cascade = v;
-        var t = trapee;
-        // if v==0 then v==false - 0 or null unsets
-        if (v) {
-            t[t.dim] --= static.invokeReflow;
-        } else {
-            t[t.mindim] = 0;
-            t[t.maxdim] = vexi.ui.maxdim;
-            t[t.dim] ++= static.invokeReflow;
-        }
-        t.reflow = true;
-    }
-    
 </vexi>

Modified: branches/vexi3/org.vexi-vexi.widgets/src_main/vexi/layout/flow.t
===================================================================
--- branches/vexi3/org.vexi-vexi.widgets/src_main/vexi/layout/flow.t    
2015-03-03 01:36:32 UTC (rev 4775)
+++ branches/vexi3/org.vexi-vexi.widgets/src_main/vexi/layout/flow.t    
2015-03-04 14:33:50 UTC (rev 4776)
@@ -1,128 +1,23 @@
-<!-- Copyright 2009 - see COPYING for details [LGPL] -->
+<!-- Copyright 2015 - see COPYING for details [LGPL] -->
 
 <vexi xmlns:ui="vexi://ui" 
-      xmlns:role="org.vexi.lib.role"
       xmlns:meta="vexi://meta"  
-      xmlns:lay="vexi.layout">
+      xmlns="org.vexi.lib.layout">
+
     <meta:doc>
-        <author>Charles Goodwin</author>
-        <author>Mike Goodwin</author>
         <name>Flow Layout</name>
         <desc>
         Lays out children filling first row/column (horizontal/vertical) 
before flowing onto the next row. 
         Essentially in the manner that wrapped text is layed out.
         </desc>
+        <usage>
+            <flow orient="horizontal">
+               <ui:box width="20" height="20" />
+               <ui:box width="10" height="10" />
+               etc
+            </flow>
+        </usage>
     </meta:doc>
     
-    <ui:box layout="place" align="topleft">
-        var _x;
-        var _y;
-        var _width;
-        var _height;
-        
-    
-    
-        var dirty;
-        const max = vexi.math.max;
-        var doReflow;
-        const reflowTrap = function(v) { 
-            cascade = v; 
-            doReflow(); 
-        };
-        
-        var entered = false;
-        doReflow = function(){
-//            trace(["doReflow", entered, visible, dirty]);
-            if(entered) {
-                dirty = true;
-                return;
-            }            
-            entered = true;
-            try{
-                   if(!visible){
-                       
-                       return;
-                   }else{
-                       dirty = false;
-                   }
-                    
-                   var rankSize = 0;
-                   var offsetRank = 0;
-                   var offset = 0;
-                   for(var i, b in thisbox){
-                       var offset0 = offset;
-                       var offsetRank1 = offsetRank; 
-                       var offset1 = offset+b[_width];
-                       if(offset1>thisbox[_width] and i!=0){
-                           offsetRank1 += rankSize;
-                           offset0 = 0;
-                           offset1 = b[_width];
-                           rankSize = 0;
-                       }
-                       
-                       rankSize = max(rankSize, b[_height]); 
-                       
-                       b[_x] = offset0;
-                       b[_y] = offsetRank1;
-//                     trace(i+" ("+b.x+","+b.y+") 
("+b.width+","+b.height+")");
-                       offset = offset1;     
-                       offsetRank = offsetRank1;            
-                       
-                       b[_width]  ++= reflowTrap;              
-                       b[_height] ++= reflowTrap;
-                   }
-                   thisbox[_height] = offsetRank + rankSize;
-//                 // HACK 
-//                 if(offsetRank==0 and offset==0){
-//                     dirty = true;
-//                 }
-            }finally{
-                entered = false;
-            }
-        };
-        
-        
-        
-        thisbox.orient ++= function(v){
-            cascade = v;
-            if("horizontal"==v){
-                _x = "x";
-                _y = "y";
-                _width = "width";
-                _height = "height";
-                
-                
-            }else{
-                _x = "y";
-                _y = "x";            
-                _height = "width";
-                _width = "height";
-            }
-        };
-        
-        thisbox.width  ++= reflowTrap;
-        thisbox.height ++= reflowTrap;
-    
-        
-        orient = "horizontal";
-        
-        
-        thisbox.visible ++= function(v) { 
-            cascade = v; 
-            if(v and dirty){
-                doReflow();             
-            }            
-        };
-                
-        thisbox.Children ++= function(v){
-            const v0 = thisbox[trapname];
-            if(v0){
-                v0.width  --= reflowTrap;
-                v0.height --= reflowTrap;
-            }
-            cascade = v;
-        };        
-        
-    </ui:box>
-    
+    <flow />
 </vexi>

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


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to