REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 3-Aug-2010 Edit History  

REBOL 3 Functions: caret-to-offset


This function is provided to convert from a string character index position to an xy offset within the text of a face. This is used primarily for text editing or for text mapping operations such as for creating colored or hyperlinked text.

out: layout [
    bx: box 10x15 red
    tx: body 100x100
tx/text: {This is an example character string.}
xy: caret-to-offset tx at tx/text 14
bx/offset: tx/offset + xy
view out

The resulting offset xy was added to the face position tx/offset to find the correct position to locate the box bx.

In the above example the caret-to-offset function was used on a face that have not yet been shown. This makes pre-display processing, colored text, and hyperlinking possible using this function in combination with size-text.

The function can also be used after a face has been shown.

Remember that when making changes to the contents of strings that are longer than 200 characters, you must set the text face line-list to none to force the recomputation of all line breaks.

Editor note: Need example for setting text face line-list to none

See the offset-to-caret function for the reverse conversion.

  TOC < Back Next > - WIP Wiki Feedback Admin