[Laszlo-user] multiline text - bug or mistake?

Benjamin Shine ben at laszlosystems.com
Sun Mar 19 23:51:54 EST 2006


There is probably a simple workaround -- set multiline to true once,  
leave it that way, just change the height -- but I looked into this  
and got interested in a potential bug. It seems like there is  
something not updating correctly. The case below shows that changing  
the value of the multiline attribute at runtime does not cause the  
text to wrap.

I noticed a few small potential problems in your test case:
	<attribute name="multi" type = "number" value="0" />
No need to say type="number". The type of an attribute is an  
expression if not otherwise specified.

>      	<attribute name="text" type = "text" />
For this, you want type="string", not type="text".

> this.multiline = true;
It is always a better idea to say this.setAttribute("multiline",  
true) rather than setting the attribute directly. That way, you give  
the runtime a chance to updated constraints and dependencies.

<method event = "oninit">
The order in which attributes get their values during instance  
initialization can be tricky. In this case, I'd be wary of the order  
in which tester.text.text gets set vis a vis tester.text.


.......my test file...
<canvas proxied="false" debug = "true">

      <class name="tester" width="100" height="100" bgcolor="0xFF8888">
      	<attribute name="text" type="string" />
      	<text name="t" text="${parent.text}" width="${parent.width}"
      	  multiline="true"
      	  height="${parent.height}" bgcolor="0x8888FF" >
		</text>
	</class>

      <class name="othertester" width="100" height="100"  
bgcolor="0xFF8888">
      	<attribute name="text" type="string" />
      	<text name="t" text="${parent.text}" width="${parent.width}"
      	  multiline="false"
      	  height="${parent.height}" bgcolor="0x8888FF" >
		</text>
	</class>

	<tester id="gTest" text="Here is some text that should wrap over  
several lines" />

     <othertester id="gOther" x="200" text="I am the othertester. Yes  
I am. Yeah, yeah." />

     <button y="90" text="multiline">
         <method event="onclick">
             gTest.setAttribute('multiline', true);
             gTest.setAttribute('text', 'I should wrap. Yes I should.');
         </method>
     </button>

     <button y="120" text="no multiline">
         <method event="onclick">
             gTest.setAttribute('multiline', false);
             // THE PROBLEM: this does wrap.
             gTest.setAttribute('text', 'This should not wrap. I hope  
it does not wrap.');
         </method>
     </button>

     <button x="200" y="90" text="multiline">
         <method event="onclick">
             // THE PROBLEM: this should wrap, but it doesn't.
             gOther.setAttribute('multiline', true);
             gOther.setAttribute('text', 'I should wrap. Yes I  
should.');
         </method>
     </button>

     <button x="200" y="120" text="no multiline">
         <method event="onclick">
             gOther.setAttribute('multiline', false);
             gOther.setAttribute('text', 'This should not wrap. I  
hope it does not wrap.');
         </method>
     </button>



</canvas>


On Mar 19, 2006, at 2:38 PM, graphis1 at mac.com wrote:

> I'm having problems scripting a text element within a class to become
> multiline - at present it only works when I specify both the width
> and the height. Here's a simple test case:
>
> <canvas proxied="false" debug = "true">
>      <class name="tester">
>      	<attribute name="multi" type = "number" value="0" />
>      	<attribute name="text" type = "text" />
>      	<text name = "t" resize = "true" text = "${parent.text}" >
> 			<method event = "oninit"><![CDATA[
> 				if (parent.multi>0){
> 					this.multiline = true;
> 					this.setWidth(parent.multi);
> 					//this.setHeight(parent.multi);
> 					Debug.write("Multiline is " + this.multiline);
> 					Debug.write("Width is " + this.width);
> 					Debug.write("Height is " + this.height);
> 					}
> 				]]>
> 			</method>
> 		</text>
> 	</class>
>
> 	<tester multi = "50" >Here's some text that should wrap over several
> lines</tester>
>
> </canvas>
>
> I've tried various combinations in place of "this.multiline = true",
> including "this.setAttribute('multiline', true) but can't get a
> result unless I uncomment the setHeight line, which isn't ideal. (I
> understand this forces the multiline attribute to true). Can anyone
> see how I could get it working using only width and multiline?
>
> (Laszlo version 3.2cr2 - SOLO)
>
> Many thanks
>
> Nick
>
> _______________________________________________
> Laszlo-user mailing list
> Laszlo-user at openlaszlo.org
> http://www.openlaszlo.org/mailman/listinfo/laszlo-user

benjamin shine
software engineer
ben at laszlosystems.com





More information about the Laszlo-user mailing list