#28 ✓resolved
Mic Pringle

drawRect is called twice ...

Reported by Mic Pringle | September 9th, 2008 @ 07:27 AM | in 0.5.1

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

Comments and changes to this ticket

  • Ross Boucher

    Ross Boucher September 10th, 2008 @ 07:18 AM

    • 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.

  • Francisco Tolmasky

    Francisco Tolmasky September 10th, 2008 @ 05:49 PM

    • State changed from “hold” to “resolved”

    (from [5618b628cf50f00959d3538d5dc7935723a2bb1c]) Modernized CPView drawing.

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

    [#31 state:resolved] [#28 state:resolved]

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

  • Francisco Tolmasky

    Francisco Tolmasky September 13th, 2008 @ 01:13 PM

    • Assigned user set to “Ross Boucher”
    • Milestone set to 0.5.1

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.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Cappuccino Web Framework, including AppKit, Foundation, and Objective-J.

Shared Ticket Bins

People watching this ticket

Referenced by

Pages