[REBOL] Re: drawing images on text face after displayed = "highlighting text"
From: anton::wilddsl::net::au at: 1-Oct-2008 18:17
Hi Alan,
The problem is, VID only provides one highlight-start and
highlight-end, and one caret, shared amongst all faces.
('Highlights' are separate from the concept of 'selection',
but VID calls the current text selection a 'highlight').
Therefore, you need to patch VID and the focus system so that it
does highlighting *optionally*, not automatically, and write a
custom text style which chooses not to exercise that option. :)
I expect each of your custom text faces should allow multiple
highlights, so create a 'highlights' facet block, and store
each pair of highlight-start/highlight-end in there.
To implement it, you need to maintain several 'highlight faces',
one for each highlight in the highlights facet.
(These highlight faces are like your red box.)
The highlight faces go into the PANE block of your custom
text style face.
See example code at bottom.
Your "Paint" button uses an interesting technique to
draw
the same box multiple times at multiple locations.
I don't recommend this technique, because you never know
when the next redraw will clear it.
You should better implement multiple boxes in your custom
text style's pane block.
There are more problems to solve, like accurately finding the
position of some text in all cases (ie. doing a better job than
CARET-TO-OFFSET does) and maybe opting out of the automatic
system caret placement on focus.
I've solved some of these problems already.
I have several modular VID patches, which allows customised
AREA and FIELD style replacements to draw their own
highlight and caret.
It should be relatively easy (for me, anyway!) to add multiple
highlighting to these styles.
http://anton.wildit.net.au/rebol/patch/caret-to-offset-patch.r
http://anton.wildit.net.au/rebol/patch/focus-system-patch.r
http://anton.wildit.net.au/rebol/patch/ctx-text-caret-highlight-patch.r
do http://anton.wildit.net.au/rebol/gui/demo-area.r
do http://anton.wildit.net.au/rebol/gui/demo-field.r
do http://anton.wildit.net.au/rebol/gui/demo-edit-panel.r
do http://anton.wildit.net.au/rebol/gui/demo-edit-panels.r
... so the answer to your question is: "yes".
Regards,
Anton.
Alan Macleod wrote:
> Is there a way to append an image object (a box for example) to a face that
> has already been displayed. I'm looking to get simple highlight
> functionality in an app in which a string is scanned for in a series of text
> faces.
>
> I've been able to highlight the search word in each face but if I click in
> any of the text faces the face looses the highlight effect sort of like
> loosing focus on normal highlighting.
> I would like the highlight to remain until no longer needed
> -Alan Macleod
rebol []
stylize/master [
my-text: text with [
highlights: [] ; custom facet
init: [
pane: copy []
]
add-highlight: func [start end][
append append highlights start end
refresh-highlights
show self
]
highlight-box: make-face/spec 'box [
size: 50x18
effect: [merge multiply yellow] ; translucent
]
refresh-highlights: has [n][
n: 0
foreach [start end] highlights [
n: n + 1
if n > length? pane [
append pane make highlight-box []
]
pane/:n/offset: 30x22 * (n - 1)
; (use CARET-TO-OFFSET here etc.)
]
clear skip pane n ; remove old highlights
]
feel: make feel [
redraw: func [face action position][
;face/refresh-highlights
]
]
]
]
view layout [
my-text: my-text 400x300 {Hello how are you going^/Just wonderful
thankyou.}
btn "Add highlight" [my-text/add-highlight 10 20]
]