REBOL Document

Caret-to-offset - Function Summary


Summary:

Returns the offset position relative to the face of the character position.

Usage:

caret-to-offset face offset

Arguments:

face - The face containing the text. (must be: object)

offset - The offset in the text. (must be: any-string)

Description:

This function is provided to convert from a string character index position to an X-Y 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

Note that 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, but it 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.

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

This function can also work on faces that have never been shown. This makes pre-display processing, colored text, and hyperlinking possible using this function in combination with SIZE-TEXT.


<Back | Index | Next>

Copyright 2004 REBOL Technologies