Skip to content
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

Plot: Legend improvements #410

Conversation

EmbersArc
Copy link
Contributor

Closes #409.

new_legend.mp4

This is based on the work in #363, so we should wait for that to be merged first. Sorry about the large PRs.

@EmbersArc EmbersArc marked this pull request as draft May 17, 2021 19:04
@EmbersArc EmbersArc marked this pull request as ready for review May 18, 2021 22:04
Copy link
Owner

@emilk

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice additions!

egui/src/widgets/plot/legend.rs Outdated Show resolved Hide resolved
egui/src/widgets/plot/legend.rs Outdated Show resolved Hide resolved
egui/src/widgets/plot/legend.rs Outdated Show resolved Hide resolved
egui/src/widgets/plot/legend.rs Outdated Show resolved Hide resolved
egui/src/widgets/plot/legend.rs Outdated Show resolved Hide resolved
egui/src/widgets/plot/legend.rs Outdated Show resolved Hide resolved
egui/src/widgets/plot/items.rs Outdated Show resolved Hide resolved
egui/src/widgets/plot/legend.rs Show resolved Hide resolved
@EmbersArc
Copy link
Contributor Author

Thanks for the review! I made the changes.

I also tried to give the legend a background, but couldn't find a way to do it without doing all the size calculation myself. Do you happen to know a way to do this?

@EmbersArc EmbersArc mentioned this pull request Jun 6, 2021
@EmbersArc EmbersArc requested a review from emilk June 7, 2021 18:50
Copy link
Owner

Thanks for the review! I made the changes.

I also tried to give the legend a background, but couldn't find a way to do it without doing all the size calculation myself. Do you happen to know a way to do this?

Sure, just add it to a Frame:

let frame = egui::Frame {};
frame.show(ui, |ui| { /* legend ui */ });

@EmbersArc
Copy link
Contributor Author

Sure, just add it to a Frame

I tried that and it looks great when the legend is on the top left:

Screenshot_20210607_213424

But it doesn't work for all the other cases:

Screenshot_20210607_213444
Screenshot_20210607_213500

Is there a way to work around this issue? Maybe something like choosing an anchor point for the frame?

Copy link
Owner

Sure, just add it to a Frame

I tried that and it looks great when the legend is on the top left:

Is there a way to work around this issue? Maybe something like choosing an anchor point for the frame?

I think this is a bug in Frame. Does this fix it:

diff --git a/egui/src/containers/frame.rs b/egui/src/containers/frame.rs
index 36b272c..6b41e31 100644
--- a/egui/src/containers/frame.rs
+++ b/egui/src/containers/frame.rs
@@ -175,10 +175,7 @@ impl Frame {
 
 impl Prepared {
     pub fn outer_rect(&self) -> Rect {
-        Rect::from_min_max(
-            self.outer_rect_bounds.min,
-            self.content_ui.min_rect().max + self.frame.margin,
-        )
+        self.content_ui.min_rect().expand2(self.frame.margin)
     }
 
     pub fn end(self, ui: &mut Ui) -> Response {

?

(that fix may introduce other problems, so please don't commit it)

Copy link
Owner

I think we should get this in even without the legend background

02db9ee into emilk:master Jun 7, 2021
@EmbersArc
Copy link
Contributor Author

That was it! Works in all corners now. I'll add that in the next PR then. Thanks!

image

@EmbersArc EmbersArc deleted the legend-improvements branch June 7, 2021 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Plot: Make legend more configurable
2 participants