Re: Dynamic color changes in a text view
Re: Dynamic color changes in a text view
- Subject: Re: Dynamic color changes in a text view
- From: Mike Ferris <email@hidden>
- Date: Tue, 31 Dec 2002 10:44:47 -0800
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@hidden>
Date: Tue Dec 31, 2002 10:11:51 AM US/Pacific
To: email@hidden
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@hidden
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@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.