Re: is [uiObject display] necessary?
Re: is [uiObject display] necessary?
- Subject: Re: is [uiObject display] necessary?
- From: "Erik M. Buck" <email@hidden>
- Date: Mon, 10 Dec 2001 19:39:04 -0600
- Organization: EMB & Assocites Inc.
What do we have to do to convince you that -setNeedsDisplay: is the method
best suited to updating the user interface ? Do we need to show you timing
and sequence diagrams or will it be enough that your applications are just
slower than the competitions ?
There is no mystery when views will be displayed. Any view marked with
setNeedsDisplay: will be displayed before the next user input (usually when
control is returned to the event loop). This is necessary so that the next
user input can be influenced by any changes in the gui. The primary
difference between calling -display and calling setNeedsDisplay: is that the
Application Kit can be much smarter about coalescing displays and minimizing
the number of changes to the current graphics context needed to display the
content of a window. The application kit can also optimize its communication
with the window server in a way that you can not since the connection to the
window server is private/concealed.
The only way for you to be as smart as the application kit is to
inappropriately couple interface components or implement a marking system
similar to the -setNeedsDisplay system.
There are reasons to call -display. One reason is because control will not
return to the event loop any time soon, but that is probably a design flaw
in its own right.
Here is an excerpt from my Stepwise article:
http://www.stepwise.com/Articles/Technical/DPSOptimized2.html
Don't display
Use the -setNeedsDisplay and -setNeedsDisplayInRect: methods rather
than -display or -displayInRect:. This will enable the ApplicationKit to
better queue drawing and minimize communication with the window server.
The classic example of this is an application with an inspector. A change in
the inspector may change the document and a change in the document may
change the inspector. [If the inspector is using notifications or the
responder chain in its implementation, it may not know about other interface
components and therefore can use its own display optimizations.] If you use
the -display method, it is not hard to get into a situation where one or
more views are asked to display multiple times to reflect one change. In
order to simplify the code and avoid that problem at the same time,
use -setNeedsDisplay and the built in autodisplay features liberally. No
matter how many times you call -setNeedsDisplay for a view, the view will
only be redrawn at most once per user event.
Another common occurrence is that a view (such as the matrix in a column of
a browser) is sent the display message and then its super view (The browser)
is sent a display message. Since the super view must draw its sub-views,
this results in one or more views being drawn redundantly.
Using -setNeedsDisplay avoids this problem also.