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

Customize Plot label and cursor texts #1235

Merged
merged 9 commits into from Feb 15, 2022
Merged

Conversation

s-nie
Copy link
Contributor

@s-nie s-nie commented Feb 9, 2022

Closes #1234

image

This was developed internally at embotech AG. We use egui extensively and would like to contribute changes that could benefit the open-source community.

Comment on lines 41 to 47
pub fn with_precision(precision: usize) -> Self {
Self {
function: Box::new(move |value| {
format!("x: {:.p$}\ny: {:.p$}", value.x, value.y, p = precision)
}),
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here (and in other places) it would be great to have a function to format with a fixed number of significant digits. Does egui happen to already have this functionality somewhere?

Copy link
Owner

@emilk emilk left a comment

Choose a reason for hiding this comment

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

Nice! Don't forget CHANGELOG.md

Comment on lines 47 to 48
emath::round_to_decimals(value.x, precision).to_string(),
emath::round_to_decimals(value.y, precision).to_string(),
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
emath::round_to_decimals(value.x, precision).to_string(),
emath::round_to_decimals(value.y, precision).to_string(),
format!("{:.*}", decimal_places, value.x),
format!("{:.*}", decimal_places, value.y),

Look at emath::round_to_decimals and you see why the old code was weird :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haha I see, then we should also replace it down here right?

https://github.com/emilk/egui/blob/master/egui/src/widgets/plot/mod.rs#L952

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, no there it's different.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed in f6b2915

egui/src/widgets/plot/mod.rs Outdated Show resolved Hide resolved
egui/src/widgets/plot/mod.rs Outdated Show resolved Hide resolved
s-nie and others added 4 commits February 10, 2022 15:49
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
@s-nie s-nie requested a review from emilk February 10, 2022 15:12
type AxisFormatterFn = dyn Fn(f64) -> String;
type LabelFormatterFn = dyn Fn(&str, &Value) -> String;
type LabelFormatter = Option<Box<LabelFormatterFn>>;
type AxisFormatterFn = dyn Fn(f64, &RangeInclusive<f64>) -> String;
Copy link
Owner

Choose a reason for hiding this comment

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

In a future PR we could change these to return WidgetText instead, allowing users to color the output.

@@ -753,7 +762,6 @@ impl super::View for PlotDemo {
egui::reset_button(ui, self);
ui.collapsing("Instructions", |ui| {
ui.label("Pan by dragging, or scroll (+ shift = horizontal).");
ui.label("Box zooming: Right click to zoom in and zoom out using a selection.");
Copy link
Owner

Choose a reason for hiding this comment

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

unintentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Absolutely, good catch. Added the line again in 8cc5363.

@s-nie s-nie requested a review from emilk February 14, 2022 08:49
@emilk emilk changed the title Show pointer coordinates and improve formatters Customize Plot label and cursor texts Feb 15, 2022
@emilk emilk merged commit 8f8eb5d into emilk:master Feb 15, 2022
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: Show pointer coordinates and pass axis range to label functions
2 participants