Text Width

Discussion and feedback on Construct 2

Post » Sat Dec 17, 2011 7:48 pm

How to determine the size in pixels of a text in a particular font?
And an "auto size" properties on the Text object would be nice!
Be nice with others and with yourself!
My musics: https://soundcloud.com/vinians
My C2 Forum:
http://nmbr.forumeiros.com/
My Site:
http://www.dicasebytes.com.br
B
22
S
5
G
6
Posts: 167
Reputation: 4,949

Post » Sun Dec 18, 2011 12:10 am

Yep, that would be nice.
And also, being able to change the size, the color, etc... of a text through Actions.
I don't think we can right now...
B
12
S
2
G
5
Posts: 73
Reputation: 3,570

Post » Sun Dec 18, 2011 7:26 pm

[QUOTE=guicole] Yep, that would be nice.
And also, being able to change the size, the color, etc... of a text through Actions.
I don't think we can right now...[/QUOTE]

Oh darn. I was planning on doing this. =\
B
47
S
10
G
6
Posts: 455
Reputation: 8,331

Post » Sun Dec 18, 2011 9:18 pm

Use the expression len(text.text) (in case of a text object named text).
This system expression will return the number of characters contained in the passed string.

From there try to multiply it by your font's size +/- X (for the space between the characters).

For formatting of text, check out jessejoh's HTML elements plugin that allow to use HTML formatting on your text.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
278
S
104
G
86
Posts: 7,313
Reputation: 84,296

Post » Sun Dec 18, 2011 9:23 pm

[QUOTE=Kyatric] Use the expression len(text.text) (in case of a text object named text).
This system expression will return the number of characters contained in the passed string.

From there try to multiply it by your font's size +/- X (for the space between the characters).[/QUOTE]
I do that but its only works with fixed size fonts like "courier new".

About use of others plugins I dont like so much because its not guaranteed to be compatible with future versions of C2, so I am asking that this feature is placed in the next release of C2.
Be nice with others and with yourself!
My musics: https://soundcloud.com/vinians
My C2 Forum:
http://nmbr.forumeiros.com/
My Site:
http://www.dicasebytes.com.br
B
22
S
5
G
6
Posts: 167
Reputation: 4,949

Post » Mon Dec 19, 2011 9:05 am

@Vinians : somebody can code a quick plugin using a DOM property from IE that has been implemented on other browser : offsetWidth.
The way to use it is :
[quote]
var offsetWidth = element.offsetWidth;
[/quote]
So if you have your text inside a <span>, for example, that has no border nor any frills, you can retrieve the width in pixels of your string as displayed on screen. I don't know if Ashley has the time to implement that C2's Text object, but perhaps another plugin developer can attack that problem.
If nobody has done that yet in a week or two, I can make it myself, but not before ;).
B
33
S
9
G
6
Posts: 709
Reputation: 6,704

Post » Mon Dec 19, 2011 9:14 am

Canvas has a measureText() method.Mipey2011-12-19 09:14:58
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,170

Post » Mon Dec 19, 2011 11:45 am

Friends, do not expect everyone to use the C2 can leave creating plugins. When we ask something like this is to be incorporated into the System C2 or object into another object in the standard distribution of the program. This program (C2) is designed to be simple. For most the creators are busy that we have the right to make requests even though they may not be met, that is how the program gets better and better.
Thanks to all.
Be nice with others and with yourself!
My musics: https://soundcloud.com/vinians
My C2 Forum:
http://nmbr.forumeiros.com/
My Site:
http://www.dicasebytes.com.br
B
22
S
5
G
6
Posts: 167
Reputation: 4,949

Post » Mon Dec 19, 2011 4:47 pm

Added text measurement to the todo list.
Scirra Founder
B
386
S
229
G
87
Posts: 24,201
Reputation: 191,530


Return to Construct 2 General

Who is online

Users browsing this forum: Tokinsom and 3 guests