Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
TextWrap Addition - Gideros Forum

TextWrap Addition

talistalis Guru
edited August 2012 in Code snippets
I am using @ar2rsawseen textwrap class. It is really a good solution. Also there is one more Textwrap2 by @atilim which is optimized for vey vey long texts. But i am using ar2rsawseen's cause it also supports formats like justify etc.

I had something in mind like this when i started:
@" in the beginning of the lines. And the code will recognize them and format my line according to correspending parameters.
Example inside txt file:
This is a test line.
@This is a test line.

@ line will be green color. But the first line will be black as default.

What i done:
1-To function TextWrap:setText(text) i added some lines of code like this:
 
@ characters
local line = TextField.new(self.font, part)  
print(atchar)  --check only
@ signs inside our text
print(i)
line:setTextColor(0xfff450)  --set the wanted color for the <a href="/profile/2">@2</a> line
else
line:setTextColor(self.textColor)  --else default
end
2-For the ones doesn't want to format the txt file i wrote another function which you can give spesific lines that you want to change colors. So for example if you will give begin=1 and ending=3, 1,2,3 lines will be differnet color in your program.
function TextWrap:setTextColorRow(begin,endind,color)
	self.textColor = color
	for i = begin, endind do
		local sprite = self:getChildAt(i)
		sprite:setTextColor(color)
	end
 
end
So here is an example project.
When i will finish all the class i will post it here again. I posted before finishing because maybe someone else have some other ideas about it and we can work all together.
zip
zip
TextWrap_New.zip
4K
+1 -1 (+3 / -0 ) Share on Facebook

Comments

  • @talis hey nice one.
    I had an idea in mind to combine @atilims performance with mine alignment settings and create new TextWrap, so any additions like this are also welcome, when I'll finally get to this. ;)

    Likes: talis

    +1 -1 (+1 / -0 ) Share on Facebook
  • talistalis Guru
    edited August 2012
    @ar2rsawseen looking forward for the new class. Before i started to implement this one i tried to combine @atilims version with yours actually, but it seems ahead of my current skills right now unfortunately. But my learning curve is increasing with easing.cubic :D

    Till that time i will contribute with my ideas and additions i guess.

    I am planning to publish the altered version within this week.

  • Just wondering : how hard would it be to support Markown formatting with this class?
    twitter@TheWindApps Artful applications : The Wind Forest. #art #japan #apps
  • talistalis Guru
    edited August 2012
    @ in the beginning of some line. Tt can not change the whole row's color hence it can be split-ted by the code to a whole new line.
    Maybe we should somehow take the desired row in some special code brackets like.
    some text here
    or just more simple


    @ special character)

    Any idea about it:D
  • talistalis Guru
    edited August 2012
    Ok here is my work so far.
    1-I switched to @atilim 's version of Textwrap2 class and added alignment,linespacing,letterspacing,defaultcolor change and special coloring of rows properties.
    Here is the example of the init function
    TextWrap2:new(text, areaWidth, areaHeight,lineSpacing,letterSpacing,align,font,mainColor,color1)
    Parameter Descriptions
    text = text to show on screen
    areaWidth = textarea width on screen
    areaHeight = textarea height on screen
    lineSpacing = text's line spacing
    letterSpacing = text's letter spacing
    align = Supporting "left","right" or "center" by default it is "left" alligned.
    font =ttf font to be used
    mainColor = text's main color by default black
    color1@" signs will be omitted from the text.

    @ar2rsawseen maybe you can help me with my problems.
    Problems:
    @ sign to some long row when the code is splitting the row my color is returning to default color again.

    I am attaching my whole project for all forum usage hope it will be usefull to someone.




    Likes: gorkem

    zip
    zip
    Textwrap2_New.zip
    55K
    +1 -1 (+1 / -0 ) Share on Facebook
  • @Talis - some very useful code, thanks for sharing. :)
    WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
    #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
  • @ar2rsawseen looking forward to hear your ideas and improvements:D
    @techdojo you are welcome.
    Additions i want to implement soon:
    1-It is a simple one but i thought that why this class is not returning the number of lines it is holding.
    So i wanna a wrote a function inside returning number of lines.
    Possible usage of it:
    According to number of lines you want to switch auto scrolling or not.

    2-Another idea is to implement event listeners inside the class and control their behavior with boolean parameteres like autoscroll=ture,false or scrollable=true,false
    autoscroll= the text is sliding by itself from the screen without user interaction.
    scroll=the text can slide with onmove event.

  • Just curious about the subject anyone done some improvement to textwrap or anyone wrote some totally new class for it? It will be really appreciated if shared .
    Thanks
  • I needed a change of font instead of color, so in some places in the class I replaced "color1" with "font1", and replaced setTextColor with setFont. Works well.

    It would be swell if there was a TextWrap-like class that could handle new lines (\n etc) as well as different formats (ie change of font or color) inside a line. :-)
  • n1cken1cke Maintainer
    Can I ask you why do you need such advanced text formatting for a game? It is much easier to make screenshot of Word/OpenOffice document and paste it as bitmap into Gideros.
  • piepie Member
    If you have many dialogues in your game this can be useful: think about the hundreds of Nintendo titles where keywords like names, places and items are highlighted when they're spoken :)
    It could also be used to make non-games apps
  • n1cken1cke Maintainer
    Yes, text highlighting is useful and TextArea already supports it since it has ability to select text while editing. TextArea also supports per line text coloring.. But colored characters with different fonts inside same line... It is more like HTML thing and more suited for business apps I think. It is possible to add font changing and coloring for each word (between spaces) to TextArea though.

    Likes: pie

    +1 -1 (+1 / -0 ) Share on Facebook
  • Suppose I needed a good looking formatted text partly containing strings generated from elsewehere?

    Also, this could save memory, instead of loading a huge bitmap (>2000px in height), right? On the other hand, if we're talking a few bitmaps, I guess the memory add-on shouldn't be a big issue? /:)
  • n1cken1cke Maintainer
    > this could save memory
    No, you can only save some disc space because texts should be rendered into texture too. Also cached font for texts consumes big amount of memory.

    Likes: saeys

    +1 -1 (+1 / -0 ) Share on Facebook
Sign In or Register to comment.