Is there anyway to highlight some text with different color by using new textField.
I tried some weird methods like combining more than one textfiled together but can not be successfull so much. (Except some minor cases)
The problem with combining more than one textfield is i can not find the correct place (x,y) coordinate where the textField finished.
In addition when allignment takes part this logic totaly fails. Maybe some idea to point me out?
Previously with textwrap i coded something like this. But now we have builtin working like a charm Textfield with alignment i am trying to achieve some similar logic.
Quote starts from old textwrap class: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.Quote Finished:Fullcode with old textwrap:
http://giderosmobile.com/forum/discussion/1580/textwrap-addition/p1My simple code just to demonstrate my idea with Textfield:
local textLines = {
"this is a blue text",
"here comes the green text",
"This is a reddish one"
}
local textField = TextField.new(nil, "")
local textField2 = TextField.new(nil, "")
--1st textfield
textField:setPosition(100, 100)
textField:setTextColor(0x88bbdd)
stage:addChild(textField)
textField:setText(textLines[1])
a=textField:getWidth()
b=textField:getWidth()
--2nd textfield
textField2:setPosition(100+a, 100)
textField2:setTextColor(0x119900)
textField2:setText(textLines[2]) -- set new text
stage:addChild(textField2) |
Comments
- Create a RenderTarget.
- Create a single TextField to use as a brush.
- Split your text string into separate words.
- Store all words in a table with their x, y, color, etc.
- Set the brush text, color, position and draw it to the RenderTarget (for every word).
- Create a Bitmap using the RenderTarget as its Texture.
- Display the Bitmap on stage.
Then it's a simple matter to change the color of any word..
- Get the x, y position of the word.
- Clear that area of the RenderTarget.
- Set the brush text, color, and position.
- Draw the brush to the RenderTarget.
Is that helpful? I'll try to make an example in the morning :bz
Likes: talis
Likes: antix, talis
https://deluxepixel.com
So as you can see there is an area of text that wraps automatically to a user specified width. The height will be auto generated so no need to bother with that. Text can change color word by word and you can align the text left. right, or center. You can also make new lines. Pretty much that's what it does
In this example the TextBox is created with the text you see then every occurrence of the word "is" is recolored to magenta, and finally the first occurrence of the word "the" is recolored Cyan.
CONTROL CODES
#align# - the next word will be used to align the text ("left", "right", "center")
#color# - the next word will be used as the new brush color (0x000000 format)
#n# - will force a new line
Note that EVERYTHING must be separated by SPACES and in the expected format/order or the TextBox class will crash. Error checking could be built in but I leave that to you
FUNCTIONS
TextBox:new(options)
options (optional) is a table containing things like text, x, y, color, etc.
TextBox:SetText(text)
text - the new text to be rendered. This will force the TextBox to redraw its self.
TextBox:SetFont(font)
font - the new font to be used. This will force the TextBox to redraw its self.
TextBox:recolor(text, color, all)
text - the word that will be recolored.
color - the new color for the word.
all - if true, all occurrences of the word in the TextBox will be recolored.
Anyway, it was fun creating this this morning and I hope somebody finds some use for it :bz
OH, this has only been tested with the default font in Gideros, your mileage may vary
Likes: talis
It seems it can have so much use in business applications, especially content applications.
Something like "This is a \e[color=#f00]red\e[color=] text".
What do you think ?
Likes: keszegh, Atavismus, talis, pie, antix, hassan
Likes: talis
Likes: keszegh, pie, talis, antix, MoKaLux
Likes: antix
"What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
“The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
No need to further increase the weight of libraries
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
I think that Gideros should not pursue "Unity", but should take its own niche-mini 2d games, with a small size.
Likes: antix
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
Likes: SinisterSoft
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
Nowadays size is less and less an issue (and don't get me wrong, I am totally in favour of small sized binaries, my job being to develop for small sized/low power platforms like MCU's).
I think gideros have more strengths:
- instant debug over wifi is unvaluable
- fast learning curve/easy to get started
- easy export
- ...
Likes: SinisterSoft
-yes, for me, the advantage is a small size
when I started using Gideros:
-he was not free
-exports were difficult
*If I need 3d - I will use Unity
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
Also, if all goes according to plan, there will be a features or two in 2018.3 (mid March) that should bring a lot more people to Gideros.
Likes: oleg, Apollo14
https://deluxepixel.com
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Likes: Atavismus, SinisterSoft
https://deluxepixel.com
Likes: oleg, antix
https://deluxepixel.com
I'll do whatever I can to provide information about Gideros in our local RU-communities, to possibly attract more developers.
"What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
“The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
When we talk of Unreal Engine and Unity and Gideros we are really not comparing apples to apples. Both Unreal Engine and Unity are primarily 3D engines with some 2D component mashed in because users wanted it.
Gideros is better compared to Corona and Love2d which are primarily 2D engines.
Unity and Unreal Engines are considered more "serious" by fanatical people that like C based systems with all those squiggles, strict variable typing and so many semicolons
Likes: MoKaLux
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
Fragmenter - animated loop machine and IKONOMIKON - the memory game