PDA

View Full Version : setting attributes


mallesh
11-26-2003, 03:25 AM
Hi Antun,

How do i set the values of the attributes in another part of the program when some event occur?

for example, i want to change the font,font size and alignment of the text in the inputtext when i clicking on the button .i couldn't find the methods setFont,setFontSize etc..

here is some code example.
<inputtext id="textcolor" resize="true" x="10" y="35" width="250" height="60" bgcolor="white" fontsize="15" font="helv" multiline="true">
<method event="onkeydown">
//var messege=textcolor.getText();
Debug.write("text from input box"+messege);
texton.setText(textcolor.getText());

</method>
</inputtext>

<view x="10" y="160" resource="Images/plus.png" clickable="true" >
<method event="onclick">
this.setAttribute("fontsize" +fontsize);
</method>
</view>

Thanks
Mallesh

antun
11-26-2003, 08:09 AM
Your approach is correct but you can't change the fontsize of an inputtext field at runtime.

You can change the font text and size of a regular (non-editable) text field at run time by setting the text with HTML tags:


<method event="onclick">
<![CDATA[
mytextfield.setText("<font size=\"20\">Hello</font>");
]]>
</method>


-Antun

mallesh
11-27-2003, 05:27 AM
Hi Antun,

Regarding to my previous question, is there any alternate solution for same?.I mean is it possible to use any other text fields instead of inputtext (like widowtext,simpleinputtext etc..)?

In html and jsp, we can change the fontsize,font and alignment dynamically (by clicking on the button).

here is the code in html
<html>
<body>
<div id="text" style="font-size:8pt"> Some text here! </div>
<input type="button" value="A+" onClick="upSize()">
<input type="button" value="A-" onClick="downSize()">
<script type="text/javascript">
var max = 24;
var min = 8;
function upSize()
{

size = parseInt(document.getElementById("text").style.fontSize)
if (size <= max) { size = size + 2 }
document.getElementById("text").style.fontSize = size + "pt"}

function downSize()
{
size = parseInt(document.getElementById("text").style.fontSize)
if (size <= min) { size = size - 2 }
document.getElementById("text").style.fontSize = size + "pt"}
</script>
</body>
</html>

I included the above code (with some alteration )but i did not got the result.

Becouse i need to change the font, fontsize and alignment of the text (entered into the inputtext)when ever i select different font, fontsize and alignment.


Thanks
Mallesh

antun
12-01-2003, 08:40 AM
Regarding to my previous question, is there any alternate solution for same?.I mean is it possible to use any other text fields instead of inputtext (like widowtext,simpleinputtext etc..)?


No, not really - all the other components use inputtext at their core. For example, windowtext is essentially an inputtext field with a 3D-look border around it.

Depending on your needs, it may be possible to instantiate a new inputtext view with different fontsize and fontstyle attributes when needed, and set the text of that field at runtime. See here for more on how to instantiate a view at runtime:

http://www.laszlosystems.com/developers/community/forums/showthread.php?s=&threadid=102&highlight=instantiating

Another thing you might want to consider is having a regular text field that mirrors what the user typed into an inputtext field, and manipulate the text in that text field.

-Antun

mallesh
01-06-2004, 05:44 AM
Hi Antun,]

Regarding to my previous question on setting the fontstyle,fontsize etc.. ,is LPS2.0 server support these feature?.I mean can i change the above attribute dynamically with in the application?
Becouse in my application we have to support large variaty of fonts , fontstyle and fontsize. It wlould be tedious to hard coding the above properties.


Thanks
Mallesh

antun
01-06-2004, 10:55 AM
No, unfortunately you can't set the fontsize of an inputtext at run-time in 2.0. However there is a workaround that will get you the desired effect:

Delete the <inputtext> node using deleteNode(), then create a new inputtext at run-time from script, and copy over the old inputtext field's details:


<canvas debug="true">
<font src="helmetr.ttf" name="helv"/>

<inputtext name="bar" y="10" font="helv"
fontsize="10">Laszlo Rocks!</inputtext>

<button y="50">Increment Font Size
<method event="onclick">
var fontSizeIncrement = 4;
var origSize = bar.fontsize;
var origText = bar.getText();
var ypos = bar.y;
bar.deleteNode();
new LzInputText( canvas, { name: "bar",
font: "helv",
fontsize: origSize+fontSizeIncrement,
y: ypos,
width: 300,
text: origText
} );
</method>
</button>


<!-- These fields are just for the compiler to use -->
<inputtext y="100" font="helv" fontsize="14" visible="false" />
<inputtext y="130" font="helv" fontsize="18" visible="false" />
<inputtext y="155" font="helv" fontsize="22" visible="false" />
<inputtext y="155" font="helv" fontsize="26" visible="false" />
</canvas>


There's a little catch though: You can't create a new inputtext from script unless you have instantiated one with the same properties from a tag. That's what the invisible text fields are for above. See, if you keep incrementing the size of the field, and get beyond 26 (which is the largest declared), then it will break.

2.0 makes this possible, because calling deleteNode() no longer causes a memory leak.

-Antun

thipperudra
03-24-2004, 04:36 AM
Hi Antun,

I want to set attributes like align,valign and fontstyle of text dynamically.Is it lps-2.1 supports.

-Rudresh

antun
03-24-2004, 08:57 AM
Align and valign can only be set on the text or inputtext view itself, not the text within it. If you have the resize attribute set to true then the size of the text view will shrink and expand as needed and you can set the align attribute of that, relative to its parent.

-Antun