PDA

View Full Version : Dynamic Creation (adding) of text to a view


javatis
10-13-2005, 04:12 PM
hi i would like to create dynamic text inside a view

for example i would like to add mixed text and graphics to my canvas content.

well for the images i thougt of using addSubview but in the LzText class there iss noc construct methode

uhm can someone help me in this case?

greetz

aboni
10-14-2005, 04:52 AM
See the file below, maybe help you.

All components can be instantiate passing parameters

1 - parent
2 - an object of attributes(e.g. {x:2, y:4, height:10})


Best regards!
Andrew

Shelby
10-14-2005, 05:46 AM
I recommend creating a new class.


<library>
<class name="imageWithText">
<attribute name="caption" type="text" value=""/>
<attribute name="image" type="text" value=""/>

<method name="loadImage" args="src" event="onimage">
setSource(src);
</method>

<method name="setLabel" args="txt" event="oncaption">
label.setText(txt);
</method>

<text name="label" resize="true"/>
</class>
</library>


Then you can instantiate it and pass it a caption, like so: new imageWithText(parent, {image:'assets/image.swf', txt:'caption text'})

Of course, you'll want to clean this up and treat the caption a specific way (fonts, positioning). At least, I think this is what you are asking. ;)

javatis
10-14-2005, 09:33 AM
thx for this answhere i found something into chapter 23 yesterday and plaed a litle bit arround with classes...

<canvas height="500" layout="y">
<class name="mytext">
<attribute name="text" type="html"/>
<attribute name="width"/>
<text text="${parent.text}"/>
</class>

<view id="outi" name="outi" width="350" height="400" bgcolor="0xbbbbbb">
<wrappinglayout axis="x" spacing="5"/>
</view>

<script>
hallo="blafghjfghjfghjfghjfghjfghjfghjfghjhhhhhhhhhhhhhhh hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhjjjjjjjjjjjjjjjjjjjj jjjjjjjjjjjjj"
halli="bo"
var a = new mytext(canvas.outi, {text:halli});
var b = new mytext(canvas.outi, {text:hallo});
var a = new mytext(canvas.outi, {text:hallo});
var a = new mytext(canvas.outi, {text:halli});
var a = new mytext(canvas.outi, {text:hallo});
var b = new mytext(canvas.outi, {text:hallo});
var a = new mytext(canvas.outi, {text:hallo});
var a = new mytext(canvas.outi, {text:halli});

</script>
</canvas>


and made something like that.. which works fine but has one big problem the textfields arent autsized them are all set to a size of 100...

anyway thx for ur class i will try thisone but i have a question...

what is one row of text is longer than the view is width???

ok i could set the text to multiline but tha it would look kind of funny...

i need this for a chat main window (eg graphic= smiley´s and text = html text...
has one of u any idea for those 2 problems i thought of makin a view for each row and only diplay 5 or 10 chars per textbox to limittate the length


greetz

Shelby
10-14-2005, 10:09 AM
From what I can tell, it sounds like you will need to write your own text handler. I would guess that you'll need scrolling support, so you will need a single view that grows veritcally as chat lines are added, which is placed inside a containing view with a scrollbar.

You can use the getTextWidth() function of the LzText class as a starting point.

If you were to use a single text field that was multiline and it's width was set to 100%, you could write your own line wrappers.

[code]
<view name="chatwindow">
<text name="chat_text" width="100%" multiline="true" resize="true">
<scrollbar/>
</view>
[code]

By the way, I have found that you need to allow about 15 pixels of space for the scrollbar when wrapping text, or the text will overlap the scrollbar. Therefore, you might use a constraint on the text width like this: width="${parent.width - 15}".

javatis
10-14-2005, 03:46 PM
uhm i think ur right.. but i had an idea... dident broughtit to work yet...

something like this...

<class name="mytext">
<attribute name="text" type="html"/>
<attribute name="width"/>
<text name="mynewtext" text=""/>
<script>
<![CDATA[
this.mynewtext.setResize(true)
var ala = 0;
while (this.mynewtext.getTextWidth() < this.parent.parent.width - this.mynewtext.x-10){
this.mynewtext.addText(parent.text.substring(ala,a la+1));
ala+=1;
}
]]>
</script>

</class>



to explain.. i pass the whole textstring to the textfield (class mytext) inside this class a textfield is creates and the text should be added char by char in a while loop as long as the textfeld is below 10 px from the widthrange of the parent parent view (thisone that is in the scrollable view and "grows" in y axis)

maybe than ( not thought of yet there must ba an overflow buffer that adds anntother textfield if the string is longer that the textfield could be... mabe a method build inside thatcalls a clas that backpoints to the mytext class and just handles the "overflow"...

uhm well i will go on trying tomorow:D

thx and greetz