Your Universal Remote Control Center
RemoteCentral.com
Philips Pronto Professional Forum - View Post
Previous section Next section Up level
Up level
The following page was printed from RemoteCentral.com:

Login:
Pass:
 
 

Topic:
Wrap text in a text box
This thread has 3 replies. Displaying all posts.
Post 1 made on Monday September 2, 2024 at 08:49
mattmarsden
Junior Member
Joined:
Posts:
January 2021
28
Is there any way to to wrap text in a text box? I'm trying to import the movie plot in to a text box but just get one long line. Thanks!
Post 2 made on Monday September 2, 2024 at 16:38
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
13,059
Not without a lot of trial and error.

Here's something simple I've had for years.



//********************************************************************************
// JavaScript String Extensions
//********************************************************************************
// String extensions for wordwrap + trimming
//String.wordWrap(maxLength: Integer, [breakWith: String = "\n"], [cutWords: Boolean = false]): String
//Returns an string with the extra characters/words "broken".
//maxLengthmaximum amount of characters per line
//breakWithstring that will be added whenever it's needed to break the line
//cutWordsif true, the words will be cut, so the line will have exactly "maxLength" characters, otherwise the words won't be cut
//
String.prototype.wordWrap = function(m, b, c)
{
var i, j, s, r = this.split("\n");
if(m > 0)
{
for(i in r)
{
for(s = r[i], r[i] = ""; s.length > m; j = c ? m : (j = s.substr(0, m).match(/\S*$/)).input.length - j[0].length || m,r[i] += s.substr(0, j) + ((s = s.substr(j)).length ? b : ""));
r[i] += s;
}
}
return r.join("\n");
};

String.prototype.wordWrapIntoArray = function(m, b, c)
{
var i, j, s, r = this.split("\n");
if(m > 0)
{
for(i in r)
{
for(s = r[i], r[i] = ""; s.length > m; j = c ? m : (j = s.substr(0, m).match(/\S*$/)).input.length - j[0].length || m,r[i] += s.substr(0, j) + ((s = s.substr(j)).length ? b : ""));
r[i] += s;
}
}
return r;
};

String.prototype.trim = function()
{
return this.replace(/^\s+|\s+$/g,"");
};

String.prototype.ltrim = function()
{
return this.replace(/^\s+/,"");
};

String.prototype.rtrim = function()
{
return this.replace(/\s+$/,"");
};
//********************************************************************************
// JavaScript String Extensions
//********************************************************************************


Hope this will get you started. To really do this right, you need to examine the textWidth/textHeight required and adjust text accordingly which is much more complex than what I posted above.
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 3 made on Monday September 2, 2024 at 17:18
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
13,059
I have an XCF file that I can send you that has some algorithms I was playing with for a weather module but the code currently does not honor word boundaries for a single word that requires a width that is more than the widget width.

For example: "Thunderstorm With Light Rain"
when split to a widget of width 130 and height 258 with X and Y centered

Becomes:
"Thundersto"
"rm With"
"Light Rain"

So, if you size the widget to a minimum width of the longest word you expect to process, you should be good. You really only run into issues if you have a very narrow widget.

Email me at the address on my RC Profile and I will send you the XCF.

This is a work in progress and results are not guaranteed but the code was my first attempt at using the widget::getLabelSize(text) function available in ProntoScript.
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 4 made on Wednesday September 4, 2024 at 17:50
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
13,059
I knew I'd visited this topic before. A forum search of wrap text brought this to light.

[Link: remotecentral.com]
Lyndel McGee
Philips Pronto Addict/Beta Tester


Jump to


Protected Feature Before you can reply to a message...
You must first register for a Remote Central user account - it's fast and free! Or, if you already have an account, please login now.

Please read the following: Unsolicited commercial advertisements are absolutely not permitted on this forum. Other private buy & sell messages should be posted to our Marketplace. For information on how to advertise your service or product click here. Remote Central reserves the right to remove or modify any post that is deemed inappropriate.

Hosting Services by ipHouse