-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add layer transforms, interaction in layer #3906
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool stuff!
7b3d1f7
to
ac2ae96
Compare
@emilk Thank you for all the detailed comments and advice! I've taken some time and (hopefully) addressed all of them, could you take another look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking much better!
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
I added a few doctests, switched the transform order as you suggested, and completed the small refactoring tasks. I think all the tests should be passing as well. Let me know if there's any other changes you'd like me to make. (I'm not sure if you meant for me to add doctests or a test module, I went with doctests for now) |
@emilk Could you take a look at the updates when you have a chance? I'd love to get this merged (and avoid merge conflicts 😛 ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some docstrings to fix! Good job :)
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
The text clip bug is quite annoying. It would also be good if the demo/example has a description in the UI (e.g. a label at the top, that isn't zoomed/panned) |
The two other biggest annoyances I've seen are that remain are the internal Video.mp4It would also be nice if there was an example of painting a shape onto the transforming layer, since painting onto the top level |
@MeGaGiGaGon Is this the behaviour you're referring to where the inner windows should have their transformation match the outer demo window? Screen.Recording.2024-02-16.at.15.58.24.movUnfortunately, I'm also not sure of a good solution to ensuring that the inner windows stay atop the demo window but not other demo windows. |
@Tweoss Yep, that's it :) Edit: On further though, it is possible to re-order
This all means that, even though it is hacky, all that is needed is to get the |
Regarding the text disappearing, I've finally discovered that it is the initial text boxes' bounding box that goes beyond the clip rectangle, causing the whole text to disappear. I'll try to transform that bounding box as well. Tada! Screen.Recording.2024-02-16.at.22.12.25.mov |
Yay! It's probably better to have the smiley be on it's own un-interactable area, since otherwise odd things happen with the widget it's painted on It would also be nice to have an example painting that also moves with a draggable area I did even more thinking, and sadly my idea wouldn't work. Getting the pub struct PanZoom {
transform: TSTransform,
drag_value: f32,
window_layer_id: Option<egui::LayerId>,
}
// ...
// inside impl super::Demo for PanZoom inside fn show
self.window_layer_id = window.show(ctx, |ui| self.ui(ui)).and_then(|x| Some(x.response.layer_id));
// ...
// inside fn ui
if self.window_layer_id.is_none() {
return;
} However the issue is still the ui.ctx().memory(|mem| mem.areas().top_layer_id(egui::Order::Middle)) This is sadly not powerful enough, since the only tool for manipulating the ui.ctx().move_to_top(layer_id) Which also affects the top most Something else I just noticed is that things start glitching out if you zoom in far enough. I'd suspect this is due to floating point imprecision, so meh. Video.mp4I also also just noticed that while the translation is saved on close and open, the scale isn't |
If people want to make their own window ordering, I think that could be separate and that the demo doesn't necessarily need to demonstrate that. I should note that, though, some widgets may still need their mouse input coordinates to be reverse transformed, like in the panels and area widgets. |
What I'm mostly thinking about is if this were to be separated into it's own container/widget struct. I imagine most people making a Also on more thinking, one of these days there should also be a PR for making |
This seems to be working quite well now. The layering issue is difficult, and I think should be fixed in a separate PR. Potential solutions include:
In any case, I suggest we merge this now. |
Oops - unfortunately this broke the drag-and-drop preview code. I'll see if I can fix it. |
Thank you @emilk for taking the time to review and add changes! Also, thank you @MeGaGiGaGon for the suggestions and noticing those bugs. |
2024-06-13.23-12-49.mp4 |
⚠️ Removes `Context::translate_layer`, replacing it with a sticky `set_transform_layer` Adds the capability to scale layers. Allows interaction with scaled and transformed widgets inside transformed layers. I've also added a demo of how to have zooming and panning in a window (see the video below). This probably closes emilk#1811. Having a panning and zooming container would just be creating a new `Area` with a new id, and applying zooming and panning with `ctx.transform_layer`. I've run the github workflow scripts in my repository, so hopefully the formatting and `cargo cranky` is satisfied. I'm not sure if all call sites where transforms would be relevant have been handled. This might also be missing are transforming clipping rects, but I'm not sure where / how to accomplish that. In the demo, the clipping rect is transformed to match, which seems to work. https://github.com/emilk/egui/assets/70821802/77e7e743-cdfe-402f-86e3-7744b3ee7b0f --------- Co-authored-by: tweoss <fchua@puffer5.stanford.edu> Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
Context::translate_layer
, replacing it with a stickyset_transform_layer
Adds the capability to scale layers.
Allows interaction with scaled and transformed widgets inside transformed layers.
I've also added a demo of how to have zooming and panning in a window (see the video below).
This probably closes #1811. Having a panning and zooming container would just be creating a new
Area
with a new id, and applying zooming and panning withctx.transform_layer
.I've run the github workflow scripts in my repository, so hopefully the formatting and
cargo cranky
is satisfied.I'm not sure if all call sites where transforms would be relevant have been handled. This might also be missing are transforming clipping rects, but I'm not sure where / how to accomplish that. In the demo, the clipping rect is transformed to match, which seems to work.
Screen.Recording.2024-01-28.at.18.29.39.mov