From WikiChip
Difference between revisions of "mirc/identifiers/$wrap"
< mirc‎ | identifiers

(Created page with "{{mirc title|$wrap Identifier}}'''$wrap''' returns the Nth line in text wrapped to the specified width in the specified font. This function is typically useful for picture wi...")
 
Line 2: Line 2:
  
 
This function is typically useful for picture window if you have to display text inside a specific rectangle and you have to wrap text.
 
This function is typically useful for picture window if you have to display text inside a specific rectangle and you have to wrap text.
 +
 +
Note that the pN option is enabled by default and that control codes are preserved accross wrapped lines
  
 
== Synopsis ==
 
== Synopsis ==
<pre>$wrap(text,font,size,width,word,N)</pre>
+
<pre>$wrap(text,font,size,width,bNiNpNtNwN,N)</pre>
  
 
== Parameters ==
 
== Parameters ==
Line 11: Line 13:
 
* '''size''' - The size of the font, you can specify a negative value to match the size of fonts in the font dialog
 
* '''size''' - The size of the font, you can specify a negative value to match the size of fonts in the font dialog
 
* '''width''' - The width at which the text should wrap
 
* '''width''' - The width at which the text should wrap
* '''word''' - Optional, if this value is 1, text is wrapped at whole words (default), otherwise use 0 so that it wrap at the maximum numbers of characters allowed
+
 
 +
Before, the 4th parameter was only a one true/false value parameter to enable word wrapping, it's now a set of options to go with $width and $height:
 +
 
 +
* '''bNiNpNtN''' - Optional, defines some options for the measurement, N can be 1 or 0 to enable or disable the option:
 +
** '''bN''' enables/disables bold
 +
** '''iN''' enables/disables italic
 +
** '''pN''' enables/disables control code (-bi not needed there)
 +
** '''tN''' enables/disables tab character
 +
** '''wN''' enables word wrapping
 
* '''N''' - The Nth line wrapped, use 0 to get the total number of wrapped line.
 
* '''N''' - The Nth line wrapped, use 0 to get the total number of wrapped line.
  

Revision as of 20:42, 22 January 2022

$wrap returns the Nth line in text wrapped to the specified width in the specified font.

This function is typically useful for picture window if you have to display text inside a specific rectangle and you have to wrap text.

Note that the pN option is enabled by default and that control codes are preserved accross wrapped lines

Synopsis

$wrap(text,font,size,width,bNiNpNtNwN,N)

Parameters

  • text - The text you want to know wrapping information about
  • font - The name of the font
  • size - The size of the font, you can specify a negative value to match the size of fonts in the font dialog
  • width - The width at which the text should wrap

Before, the 4th parameter was only a one true/false value parameter to enable word wrapping, it's now a set of options to go with $width and $height:

  • bNiNpNtN - Optional, defines some options for the measurement, N can be 1 or 0 to enable or disable the option:
    • bN enables/disables bold
    • iN enables/disables italic
    • pN enables/disables control code (-bi not needed there)
    • tN enables/disables tab character
    • wN enables word wrapping
  • N - The Nth line wrapped, use 0 to get the total number of wrapped line.

Properties

None

Example

Suppose you want to implement a chat inside a picture windows, your chat area starts a X,Y = 50,50 and your width and height is W,H=300,300 You width is then 300 and you'd start displaying text at 50 + some margin:

alias picwinchat {
  var %x 50,%y 50,%w 300,%h 300
  window -BfdpC @chat -1 -1 400 400
  ;make the window full white
  drawrect -fr @chat 16777215 0 0 0 400 400
  drawrect -r @chat 0 0 %x %y %w %h
  ;we substract 10 to the real width because we will use a 5 pixel margin on both left/right
  var %n $wrap($1-,verdana,10,$calc(%w - 10),1,0)
  ;the margin
  var %xstart %x + 5 ,%ystart %y + 5,%a 1
  while (%a <= %n) {
    drawtext -r @chat 0 verdana 10 %xstart %ystart $wrap($1-,verdana,10,$calc(%w - 10),1,%a)
    inc %a
    ;increase a constant value for y, this example isn't about $height after all!, but eventually you would be using $height with a margin too
    inc %ystart 20
  }
}

Now execute "/picwinchat test this is a very long text ok some more word please ok this is enough to illustrate the example i think maybe not"

Compatibility

Added: mIRC v5.8
Added on: 05 Sep 2000
Note: Unless otherwise stated, this was the date of original functionality.
Further enhancements may have been made in later versions.


See Also

$width $height