Skip navigation.
 
mlRe: Dynamic color changes in a text view
FROM : Mike Ferris
DATE : Tue Dec 31 19:44:47 2002

Is there more than one color?

If there's only a single color, just set a new
NSForegroundColorAttribute over the whole range of text.

But if you're doing something like syntax coloring and there's multiple
ranges with different colors and you need to change one of those
colors, then what you're describing is probably the wqay to go.  PB
does something very similar.  It uses a custom syntax coloring
attribute to mark sections that are comments or numbers or strings or
whatever, and when the user changes the preference for one of the
elements it scans through, finding ranges that are that element using
the custom attribute and resetting the NSForegroundColorAttribute for
the ranges that it needs to change.

Because this can be arbitrarily expensive depending on how much text
you've got and how many discreet ranges, you may want to consider not
doing it immediately.  If you can't do the real change immediately you
could still put some sample text near the color change UI and reflect
changes immediately there (where you have control over how expensive it
would be) and do the change throughout the user's real text only after
the user has decided on a color.

You cannot just change the color object that all the ranges use since
NSColors are immutable...

Mike

Begin forwarded message:

> From: Daryn <<email_removed>>
> Date: Tue Dec 31, 2002  10:11:51 AM US/Pacific
> To: <email_removed>
> Subject: Dynamic color changes in a text view
>
> I have a text view that contains text with various configurable
> colors.  Using a continous color well, I'd like the existing text to
> change color.
>
> My thoughts about how to implement this would involve adding my own
> attributes (ie. "MyRedColor", "MyGreenColor", etc) to the text storage
> in order to use attribute:atIndex:effectiveRange: to iterate over the
> storage and update the color.
>
> Is there a simpler method to achieve this result?  For example, is it
> possible to conceptually change a single color object that all the
> colored ranges use?
>
> Daryn
> _______________________________________________
> cocoa-dev mailing list | <email_removed>
> Help/Unsubscribe/Archives:
> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
> Do not post admin requests to the list. They will be ignored.

_______________________________________________
cocoa-dev mailing list | <email_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

Related mailsAuthorDate
mlDynamic color changes in a text view Daryn Dec 31, 19:11
mlRe: Dynamic color changes in a text view Greg Titus Dec 31, 19:29
mlRe: Dynamic color changes in a text view Mike Ferris Dec 31, 19:44
mlRe: Dynamic color changes in a text view Mike Ferris Dec 31, 19:46
mlRe: Dynamic color changes in a text view Daryn Dec 31, 20:17
mlRe: Dynamic color changes in a text view Daryn Dec 31, 21:39
mlRe: Dynamic color changes in a text view Greg Titus Dec 31, 21:52
mlRe: Dynamic color changes in a text view Mike Ferris Jan 2, 17:14