Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

drawRect is called twice ...

#28

When you create custom views and override drawRect it is called twice. You can replicate this by running the following code and then inspecting the DOM to see 2 canvas elements rather than one, or just add an alert ...


@implementation DMView : CPView
{
}
- (id)initWithFrame:(CPRect)aFrame
{
    self = [super initWithFrame:aFrame];
    if (self){
		[self setNeedsDisplay:true];
	}
	return self;
}

- (void)drawRect:(CPRect)aRect
{
	var _canvas = document.createElement("canvas");
	self._DOMElement.appendChild(_canvas);
}
@end

Reported by Mic Pringle · September 9th, 2008 @ 07:27 AM

State: resolved
Milestone: 0.5.1
Assigned to: Ross Boucher Ross Boucher

Activity

  1. Ross Boucher
    Ross Boucher
    • State changed from new to hold

    drawRect may be called multiple times. In fact, as anything in the UI changes that Cappuccino determines may affect the contents of whatever view you're drawRect method is defined, it will call it.

    The idea of drawRect is that it should always draw exactly what your UI should look like. In other words, it's a replace solution, not an additive one. Beyond the obvious fact that you shouldn't be appending to the DOM yourself, you definitely should NOT be doing it inside drawRect. If anything, this is the method you'd want to actually paint onto the canvas with.

    The other thing about drawRect is that you don't need to create your own canvas, its done automatically for you. I believe there may be a bug with this currently that Francisco is working on a fix for.

    September 10th, 2008 @ 07:18 AM

  2. Francisco Tolmasky
    Francisco Tolmasky
    • State changed from hold to resolved

    (from [5618b628cf50f00959d3538d5dc7935723a2bb1c]) Modernized CPView drawing.

    Fix for http://cappuccino.lighthouseapp..... Fix for http://cappuccino.lighthouseapp....>

    [#31 Make CPView use run loop drawing state:resolved] [#28 drawRect is called twice ... state:resolved]

    Reviewed by Tom. http://github.com/280north/cappu...

    September 10th, 2008 @ 05:49 PM

  3. Francisco Tolmasky
    Francisco Tolmasky
    • Assigned user set to Ross Boucher
    • Milestone set to 0.5.1

    September 13th, 2008 @ 01:13 PM

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.