-
Notifications
You must be signed in to change notification settings - Fork 128
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
Layers that modify transforms #676
Comments
The main difficulty here is that currently transforms are just inserted as-is, and this would require a second book-keeping layer of transform stacks, which would only be used for this API. Would you consider creating your own version of this for external use. e.g. pub struct TransformedScene {
scene: &mut Scene,
transform: Affine
}
impl TransformedScene {
pub fn fill(...){self.scene.fill(..., self.transform.then(transform))}
} |
I suppose that would work, but I'm exposing the scene to client code in a GUI framework, so it would be much cleaner to have it built-in rather than creating a wrapper. The two situations where it would be useful for me are 1) Scaling an entire scene to transparently account for HiDPI, and 2) Transforming the contents of UI nodes to the origin, so client code doesn't have to account for their final laid-out position while painting. I imagine these two use cases are pretty useful for other GUI frameworks as well, so I would argue that it's worth an extra stack of transforms. Again, I'm happy to implement it! |
At least in the second case, wouldn't you want the ability for scenes to be retained for a widget if it didn't need to be repainted? But if you think it being handled in your paint equivalent is needed, the way to do that would is to have it handled externally. I don't see how it's any less clean to use a wrapper struct - the external API you expose would stay the same. Maybe I'm misunderstanding though. Do you have parts of our extant example code which could be written more clearly using this capability? |
If a widget wants to cache its drawing commands, there's no reason it can't store a The majority of my frame time is spent building the scene, which is why this added bit of flexibility is so important to me. I would much prefer to re-export the actual I really don't think this would be a significant departure from the API as it stands. Right now, the docs for |
From my perspective this is much less clean, as it is adding extra-bookkeeping for every operation on a I'm not likely to approve your proposed design, but I'm not going to block it either. Edit: Edited to reduce snarkiness |
+1 to Daniel’s comments. In addition to the extra bookkeeping, this request makes the assumption that a layer and transform group are the same which is not universally true. The color font spec, for example, does not merge these concepts and implementing that with this proposed change would be exceedingly painful. For this reason and others, I’m strongly opposed to making this change. However, we’ve had several people ask for some form of state tracking API and it would be reasonable to add such a thing to vello. This could mimic the original piet RenderContext or the web Canvas. The semantics should be well defined and considerations should be made for conversion to/from the current scene type. If you’re interested in working on this, I’d recommend opening a new issue or starting a zulip thread for design discussion before submitting a PR. |
Ok, so you're saying that one way forward would be to create an alternate API for constructing an How would either of you feel about exposing a Sorry if at any point I came across as snarky, that wasn't my intention! I really appreciate the work you're doing. :) |
Currently,
push_layer()
doesn't modify the transforms of drawing operations in that layer, but there are a couple places in my project where that would be useful. I couldappend()
the fragment that I'd like to transform, but that involves a copy and it may be very large, so I'd rather avoid that if possible.I think there's two obvious options to change the API to allow this. Either, add an
Option<Transform>
parameter topush_layer()
that gets applied to everything within that layer, or add a separate function called something likepush_transform_layer()
that only effects transforms. In the second case it might make sense to renamepush_layer()
topush_clip_layer()
, but then you'd have two different types of layers to pop, which could be confusing and error prone.If this is something the project is willing to include, I'm happy to implement whatever API gets settled on! The scene encoding doesn't seem too hard to work with... (knock on wood)
The text was updated successfully, but these errors were encountered: