Or alternatively, no constraints and only simple handlers, something like:

<handler name="oninit"><![CDATA[
   this.setAttribute('selectable', classroot.selectable);
]]></handler>

<handler name="ontext" method="_setCalcX" />
<handler name="onwidth" method="_setCalcX" />

<method name="_setCalcX"><![CDATA[
   if (classroot.textalign == "center") {
       var x = ((this.width /2) - (this.getTextWidth() /2));
       if (x < 0) x = 0;
       this.setAttribute("x", x);
   } else if (classroot.textalign == "right") {
       var x = ((this.width) - (this.getTextWidth() + 10));
       if (x < 0) x = 0;
       this.setAttribute("x", x);
   } else {
       this.setAttribute("x", 0);
   }
]]></method>

The other way to do this is to give _calcX a dependency method. See for instance LzDataElementTrait#getFirstChild. Clearly whatever you do there will have to be updated to the new dependencies-method scheme (when we figure out what that is!). There needs to be a general, user- extensible way to write a method that computes the dependencies for another method for the case where the compiler's simple analysis is insufficient.

On 2008-03-19, at 23:57 EDT, Henry Minsky wrote:
>/ I wanted to get rid of the deprecated "applyConstraint" call in
/>/ gridtext, which looks like
/>/
/>/ -                    var f = function() {
/>/ - this.setAttribute("x", />/ this._calcX());
/>/ -                            }
/>/ -                    var d = [this, "width"];
/>/ -                    this.applyConstraint("x", f, d);
/>/
/>/ so I replaced it with the LZX constraint on "x"
/>/
/>/
/>/ +                  x="${ this._calcX() + this.width * 0}"
/>/
/>/
/>/ which  should be equivalent; it has a dependency on "width", but
/>/ multiplies it by zero, and calls the _calcX() method
/>/ which is what the original applyConstraint was doing.  So this should
/>/ do the same thing as the original call to applyConstraint, right?
/>/
/>/
/>/
/>/ Index: gridtext.lzx
/>/ ===================================================================
/>/ --- gridtext.lzx (revision 8323)
/>/ +++ gridtext.lzx (working copy)
/>/ @@ -66,6 +66,7 @@
/>/             <text visible="${!parent.editing}" width="${parent.width}"
/>/                   resize="false"
/>/                   y="${ parent.height /2 - this.height/2}"
/>/ +                  x="${ this._calcX() + this.width*0}"
/>/                   fgcolor="${ parent.immediateparent.selected ?
/>/                                     classroot._textselectedcolor:
/>/ />/ (parent.immediateparent.highlighted ?
/>/ @@ -76,11 +77,6 @@
/>/                 <handler name="oninit">
/>/                 <![CDATA[
/>/ this.setAttribute('selectable', />/ classroot.selectable);
/>/ -                    var f = function() {
/>/ - this.setAttribute("x", />/ this._calcX());
/>/ -                            }
/>/ -                    var d = [this, "width"];
/>/ -                    this.applyConstraint("x", f, d);
/>/                 ]]>
/>/                 </handler>
/>/
/>/
/>/
/>/ -- />/ Henry Minsky
/>/ Software Architect
/>/ hminsky at laszlosystems.com 
<http://www.openlaszlo.org/mailman/listinfo/laszlo-dev>
/

Reply via email to