REBOL Document

Offset-to-caret - Function Summary


Summary:

Returns the offset in the face's text corresponding to the offset pair.

Usage:

offset-to-caret face offset

Arguments:

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

offset - The XY offset relative to the face. (must be: pair)

Description:

This function is provided to convert from an X-Y offset within a text face to a character index within a string. It is mainly used for text editing and text mapping operations such as for colored or hyperlinked text.

Here is an interesting example. When you click your mouse on the upper text face, the string from that position forward will be shown in the lower text face.


    view layout [
        body 80x50 "This is an example string."
            feel [
                engage: func [face act event] [
                    if act = 'down [
                        bx/text: copy offset-to-caret
                            face event/offset
                        show bx
                    ]
                ]
            ]
        bx: body 80x50 white black
    ]

When the top face is clicked, the event/offset contains the X-Y offset that is converted to a string index position with offset-to-caret. The string from that point forward is copied and displayed in the lower text box (bx).

Note that the string does not have to be displayed for this function to work. Also 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.

Related:

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


<Back | Index | Next>

Copyright 2004 REBOL Technologies