Skip to content

Commit

Permalink
Use Option instead of empty string for custom hover label name arg
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivgeni Segal committed Dec 11, 2021
1 parent ea959d1 commit 296caeb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions egui/src/widgets/plot/items/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,7 @@ pub(super) fn rulers_at_value(
let x_decimals = ((-scale[0].abs().log10()).ceil().at_least(0.0) as usize).at_most(6);
let y_decimals = ((-scale[1].abs().log10()).ceil().at_least(0.0) as usize).at_most(6);
if let Some(custom_label) = custom_label_func {
let name = (!name.is_empty()).then(|| name);
custom_label(name, &value)
} else if plot.show_x && plot.show_y {
format!(
Expand Down
6 changes: 3 additions & 3 deletions egui/src/widgets/plot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mod items;
mod legend;
mod transform;

type CustomLabelFunc = dyn Fn(&str, &Value) -> String;
type CustomLabelFunc = dyn Fn(Option<&str>, &Value) -> String;
type CustomLabelFuncRef = Option<Box<CustomLabelFunc>>;

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -199,7 +199,7 @@ impl Plot {
/// let line = Line::new(Values::from_values_iter(sin));
/// Plot::new("my_plot").view_aspect(2.0)
/// .custom_label_func(|name, value| {
/// if !name.is_empty() {
/// if let Some(name) = name {
/// format!("{}: {:.*}%", name, 1, value.y).to_string()
/// } else {
/// "".to_string()
Expand All @@ -208,7 +208,7 @@ impl Plot {
/// .show(ui, |plot_ui| plot_ui.line(line));
/// # });
/// ```
pub fn custom_label_func<F: 'static + Fn(&str, &Value) -> String>(
pub fn custom_label_func<F: 'static + Fn(Option<&str>, &Value) -> String>(
mut self,
custom_lebel_func: F,
) -> Self {
Expand Down

0 comments on commit 296caeb

Please sign in to comment.