mirror of
https://github.com/emilk/egui.git
synced 2026-06-26 22:53:14 -04:00
Use Option instead of empty string for custom hover label name arg
This commit is contained in:
@@ -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!(
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user