How do I set textarea height to total height of text

Get help using Construct 2

Post » Sun Jul 06, 2014 8:08 pm

Hi,

Could anyone help me with setting up the height of textarea to total height amount of text within it?

Thx
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
92
S
30
G
22
Posts: 1,987
Reputation: 20,178

Post » Mon Jul 07, 2014 3:42 am

so you basically want to "wrap" your text? Meaning make it so it doesn't cut off or not display text if it is too long for the height you gave it in the editor?

Never tried it before but here's an idea:

Account for which font and how many "W"s (or your font's widest letter) would fit in the given width; check how many characters are in your text string (making sure to check for newlines) then just do the math... Also you need to figure how much height to add with each newline.

if 50 is your letter width max and you have 150 characters (including spaces) you add (3 * lineheight) to your TextBox's height.
B
100
S
33
G
16
Posts: 1,204
Reputation: 16,865

Post » Mon Jul 07, 2014 3:37 pm

Will try :) What about enter's? Thanks!
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
92
S
30
G
22
Posts: 1,987
Reputation: 20,178

Post » Tue Jul 08, 2014 12:32 am

yes, that's what I meant about "newlines" or "carriage returns". You need to count them as a full line by themselves.

I'm not that great at string parsing in C2 but maybe the best way would be to replace all the "newline"s or "enters" with spaces (or any character for that matter) just so you can count all the characters to make the correct amount of lines.

so let's say your TextBox's line height is 7 (pixels) and your line width is 20 (characters)...

Code: Select all
Set TextBox1 Text to ("This is my text." & newline & newline & "And this is a new paragraph.")
Call Function AutoTextHeight("This is my text." & newline & newline & "And this is a new paragraph.")

and in the Function do this:

Code: Select all
Function AutoTextHeight-------------
replace(Function.Param(0),newline,"XXXXXXXXXXXXXXXXXXXX")  //this will replace all your "enters" with Xs

Set TextBox1 Height to (len(Function.Param(0) / 20) * 7 // divide by the linewidth and multiply by lineheight


you would need to pass the UID of the Text Object to "pick" it.. or you don't even need it in a function. Just make sure to set the Text with the "enters" then make a copy of the string to replaces the "enters" for counting only. You don't want the actual Xs in your text.
B
100
S
33
G
16
Posts: 1,204
Reputation: 16,865

Post » Tue Jul 08, 2014 1:26 am

I'm having problems with my suggestion.. now I'm not sure of the best way to do it.

The first problem is my method requires monospacing (a font like courier). The second problem is for some reason C2 won't recognize "newline" as a carriage return (enter) in the replace() function. The ascii character is 0x13 or 'CR' but I don't know how to reference that in C2...

also it seems the text object resize during runtime doesn't wrap the text...

There must be a better way to do this..

here is the capx I was working with...
You do not have the required permissions to view the files attached to this post.
B
100
S
33
G
16
Posts: 1,204
Reputation: 16,865

Post » Wed Jul 30, 2014 9:56 pm

@jobel hey, I didn't get notification about your replies. Will look in the capx soon.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
92
S
30
G
22
Posts: 1,987
Reputation: 20,178

Post » Thu Jul 31, 2014 2:05 am

jobel wrote:stuff

Image


not sure if this is better or not, but this is how i did it
B
6
S
1
Posts: 51
Reputation: 502

Post » Thu Jul 31, 2014 4:04 pm

@megatronx yeah sorry I don't have a solution.. was hoping someone else could pitch in.. maybe @trultz has the answer?
B
100
S
33
G
16
Posts: 1,204
Reputation: 16,865


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 32 guests