-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Customize Plot label and cursor texts #1235
Conversation
egui/src/widgets/plot/mod.rs
Outdated
pub fn with_precision(precision: usize) -> Self { | ||
Self { | ||
function: Box::new(move |value| { | ||
format!("x: {:.p$}\ny: {:.p$}", value.x, value.y, p = precision) | ||
}), | ||
} | ||
} |
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.
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?
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.
Nice! Don't forget CHANGELOG.md
egui/src/widgets/plot/mod.rs
Outdated
emath::round_to_decimals(value.x, precision).to_string(), | ||
emath::round_to_decimals(value.y, precision).to_string(), |
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.
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 :)
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.
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
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.
Ah, no there it's different.
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.
Changed in f6b2915
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
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; |
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.
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."); |
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.
unintentional?
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.
Absolutely, good catch. Added the line again in 8cc5363.
Closes #1234
This was developed internally at embotech AG. We use egui extensively and would like to contribute changes that could benefit the open-source community.