Revision: 3023
          http://vexi.svn.sourceforge.net/vexi/?rev=3023&view=rev
Author:   clrg
Date:     2008-08-04 01:22:18 +0000 (Mon, 04 Aug 2008)

Log Message:
-----------
Clean up of lib.text.block code

Modified Paths:
--------------
    trunk/widgets/org.vexi.widgets/src/org/vexi/lib/text/block.t

Modified: trunk/widgets/org.vexi.widgets/src/org/vexi/lib/text/block.t
===================================================================
--- trunk/widgets/org.vexi.widgets/src/org/vexi/lib/text/block.t        
2008-08-03 23:20:16 UTC (rev 3022)
+++ trunk/widgets/org.vexi.widgets/src/org/vexi/lib/text/block.t        
2008-08-04 01:22:18 UTC (rev 3023)
@@ -12,10 +12,8 @@
         </todo>
     </meta:doc>
     
-    <ui:box redirect=":$content">
-        <ui:box id="content" layout="place" />
+    <ui:box layout="layer">
         
-        thisbox.content = $content;
         thisbox.fontheight = vexi.ui.font.height(font, fontsize, "dy");
         thisbox.minheight = fontheight;
         thisbox.multiline = false;
@@ -27,11 +25,10 @@
         thisbox.ALIGN_RIGHT = false;
         
         /** reflows words and works out block height using pure JS layout */
-        thisbox.reflow = function() { static.reflowBlock($content, thisbox); }
+        thisbox.reflow = function() { static.reflowBlock(thisbox); }
         
         /** reusable function for updating mWord notifier */
-        $content.activeTrap = function(v) { cascade = v; mWord = trapee; }
-        $content.reflow = static.reflowBlock;
+        thisbox.activeTrap = function(v) { cascade = v; mWord = trapee; }
         
         // assign static trap functions
         thisbox.font      ++= static.fontWrite;
@@ -45,7 +42,7 @@
         thisbox.text      ++= static.textRead;
         thisbox.text      ++= static.textWrite;
         thisbox.wrapwidth ++= static.wrapwidthWrite;
-        $content.Children ++= static.ChildrenWrite;
+        thisbox.Children ++= static.ChildrenWrite;
                 
     </ui:box>
     
@@ -76,31 +73,31 @@
     }
     
     /** generic trap to invoke reflow */
-    static.invokeReflow = function(v) { cascade = v; trapee.reflow(); }
+    static.invokeReflow = function(v) { cascade = v; 
static.reflowBlock(trapee); }
     
     /** synchronizes the block and it's contents with it's current size */
-    static.reflowBlock = function(b, p) {
-        if (p.multiline and p.width == 0 and p.wrapwidth == 0) return;
+    static.reflowBlock = function(b) {
+        if (b.multiline and b.width == 0 and b.wrapwidth == 0) return;
         
         var cur_x = 0;                  // current x to assign to words
         var cur_y = 0;                  // current y to assign to words
-        var cur_height = p.fontheight;  // current height of line
+        var cur_height = b.fontheight;  // current height of line
         var eol = false;                // end of line indicator
         var sol = 0;                    // index of word at start of line
         var offset;                     // used to store alignment offset
         var i = 0;                      // index reference
 
         // for efficiency, only fetch these once
-        var b_numchildren = b.numchildren;
-        var p_align_left = p.ALIGN_LEFT;
-        var p_right_mark = p.ALIGN_RIGHT ? 1 : 2;
-        var p_fontheight = p.fontheight;
-        var p_width = p.wrapwidth ? p.wrapwidth : p.width;
-        var b_width = 0;
+        var numchildren = b.numchildren;
+        var align_left = b.ALIGN_LEFT;
+        var right_mark = b.ALIGN_RIGHT ? 1 : 2;
+        var fontheight = b.fontheight;
+        var wrapwidth = b.wrapwidth ? b.wrapwidth : b.width;
+        var width = 0;
         
         // single line behaviour
-        if (!p.multiline) {
-            for (var j=0; b_numchildren>j; j++) {
+        if (!b.multiline) {
+            for (var j=0; numchildren>j; j++) {
                 b[j].x = cur_x;
                 b[j].y = 0;
                 cur_x += b[j].prefwidth;
@@ -108,25 +105,25 @@
                 if (b[j].minheight > cur_height) cur_height = b[j].minheight;
                 b[j].maxheight = vexi.ui.maxdim;
             }
-            if (!p_align_left) {
-                offset = (p_width-cur_x) / p_right_mark;
-                for (var j=0; b_numchildren>j; j++) b[j].x += offset;
+            if (!align_left) {
+                offset = (wrapwidth-cur_x) / right_mark;
+                for (var j=0; numchildren>j; j++) b[j].x += offset;
             }
-            p.height = cur_height;
-            p.minwidth = cur_x;
-            p.sync = true;
+            b.height = cur_height;
+            b.minwidth = cur_x;
+            b.sync = true;
             return;
         }
         
         // multiline lay out words
-        if (b_numchildren) do {
+        if (numchildren) do {
             // deal with whitespace
             if (b[i].whitespace) {
                 if (b[i].linebreak) {
                     b[i].x = cur_x;
                     b[i].y = cur_y;
                     eol = true;
-                } else if (cur_x + b[i].prefwidth > p_width) {
+                } else if (cur_x + b[i].prefwidth > wrapwidth) {
                     b[i].width = 0;
                 } else {
                     b[i].width = b[i].prefwidth;
@@ -136,7 +133,7 @@
                 }
             // normal words
             } else {
-                if (cur_x + b[i].prefwidth > p_width and cur_x > 0) {
+                if (cur_x + b[i].prefwidth > wrapwidth and cur_x > 0) {
                     eol = true;
                     i--;
                 } else {
@@ -152,26 +149,26 @@
             // move onto next word
             i++;
             // process completed lines
-            if (eol or i==b_numchildren) {
-                offset = p_align_left ? 0 : ((p_width-cur_x) / p_right_mark);
+            if (eol or i==numchildren) {
+                offset = align_left ? 0 : ((wrapwidth-cur_x) / right_mark);
                 for (var j=sol; i>j; j++) {
                     b[j].height = cur_height;
                     b[j].x += offset;
                 }
-                if (cur_x > b_width) b_width = cur_x;
+                if (cur_x > width) width = cur_x;
                 cur_x = 0;
                 cur_y += cur_height;
-                cur_height = p_fontheight;
+                cur_height = fontheight;
                 eol = false;
                 sol = i;
             }
-        } while (b_numchildren>i);
+        } while (numchildren>i);
         
         // set block height
-        p.height = cur_y > 0 ? cur_y : p_fontheight;
-        if (p.wrapwidth) p.width = b_width;
+        b.height = cur_y > 0 ? cur_y : fontheight;
+        if (b.wrapwidth) b.width = width;
         // fire sync trap added in lib.text.edit
-        p.sync = true;
+        b.sync = true;
     }
     
     // trap functions ////////////////
@@ -251,11 +248,9 @@
     
     /** make text v the textual content of this block */
     static.textWrite = function(v) {
-        // prevent the core from rendering text directly
-        cascade = null;
-        var c = trapee.content;
+        var t = trapee;
         // delete any existing text
-        for (var w=c[0]; w!=null; w=c[0]) c[0] = null;
+        while (t[0]) t[0] = null;
         
         var l = v.length;
         // check for empty string
@@ -263,7 +258,7 @@
         
         // create new text based on v
         var str = v.charAt(0);
-        var nextword = trapee.getword;
+        var nextword = t.getword;
         var chartype = (str == ' ');
         nextword.whitespace = chartype;
         for (var i=1; l>i; i++) {
@@ -271,23 +266,24 @@
             // change between words
             if (chartype != nextword.whitespace) {
                 // assign this word
-                c[c.numchildren] = nextword;
+                t[t.numchildren] = nextword;
                 nextword.text = str;
                 // move onto next word
-                nextword = trapee.getword;
+                nextword = t.getword;
                 nextword.whitespace = chartype;
                 str = v.charAt(i);
-            }
             // accrue word text
-            else str = str + v.charAt(i);
+            } else str = str + v.charAt(i);
         }
         // assign last word
         if (str != "") {
-            c[c.numchildren] = nextword;
+            t[t.numchildren] = nextword;
             nextword.text = str;
         }
         // flow text
-        trapee.reflow();
+        t.reflow();
+        // prevent the core from rendering text directly
+        return;
     }
     
     /** read trap for getting new words relevant to a block */


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

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to