-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reset function for Canvas2D #5618
Comments
Why is it that the correct way to clear the canvas should not just clear the backing store but also reset the path, but definitively should not clear style? The linked proposal asserts this without justifying or explaining. |
The draft talks about the "transformation stack" but I think intends to refer to the A good example of why this is bad is:
|
@othermaciej. That's a fair point, the documents don't explain this well. We want a command to clear the canvas buffer (independent of the current state) and do the minimum number of operations needed to keep that sane and consistent. It seemed that reseting path/clip/transform was a part of this, but not fillStyle/globalAlpha/etc... The path was a borderline case, but we the "draw a path after a clear" would be least surprising like that. |
@smfr, I don't understand the "shared use of a canvas" argument. Why is your example any different from:
Any subcomponent can do this right now. Except it's surrounded in this mysterious "assign to itself" (that, btw, is marked - correctly so - as "bad code" on all JS linters and TypeScript). And is completely magical side-effect of assignment. We have a situation right now where Context2D can be in a state that it can't clear itself without being destroyed:
|
I don't particularly care what is the set of operations we keep. From my perspective, we should do the minimum set of operations that makes clearing the whole buffer sane. We could even consider a |
If you want to reset buffer and (most of?) the state, a (no-op) resize will
do that for you too, IIRC. It's not great ergonomics (asking for A to get
seemingly unrelated B), but if we added a reset() and defined resize's
reset in terms of it, that's an improvement to me.
A function clear() { pushPath; clearRect(0,0,c.width,c.height); popPath;}
is a slight ease of use improvement, but doesn't feel major to me.
…On Tue, Jun 9, 2020, 9:55 AM Fernando Serboncini ***@***.***> wrote:
I don't particularly care what is the set of operations we keep. From my
perspective, we should do the minimum set of operations that makes clearing
the whole buffer sane. We could even consider a clear() that only clears
the buffer, and/or a reset() that is clear + reset the whole state.
—
You are receiving this because you are on a team that was mentioned.
Reply to this email directly, view it on GitHub
<#5618 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AALHJDNKTGTIUPE6XKOP2NTRVZSONANCNFSM4NYVOK2A>
.
|
Naively, I'd expect a |
So it seems that we agree on a And the arguments against a
Would there be space for a |
If you clear the stack you have to also reset the state tracked by the stack (https://html.spec.whatwg.org/multipage/canvas.html#the-canvas-state). It would be specified as "unwinding the stack as if |
What about state set before the first call to |
Regarding the clipping areas, we certainly miss an absolute Now, I can see potential use cases for a |
Provide a
clear()
function that resets the state of the Canvas.Working proposal: https://github.com/fserb/canvas2D/blob/master/spec/clear.md
(cc @whatwg/canvas )
The text was updated successfully, but these errors were encountered: