Browse Source

Use Option instead of empty string for custom hover label name arg

pull/934/head
Ivgeni Segal 3 years ago
parent
commit
296caebb74
  1. 1
      egui/src/widgets/plot/items/mod.rs
  2. 6
      egui/src/widgets/plot/mod.rs

1
egui/src/widgets/plot/items/mod.rs

@ -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!(

6
egui/src/widgets/plot/mod.rs

@ -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>>;
// ----------------------------------------------------------------------------
@ -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()
@ -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 {

Loading…
Cancel
Save