diff --git a/crates/egui/src/widgets/plot/axis.rs b/crates/egui/src/widgets/plot/axis.rs index 4e877a144..54f93b31c 100644 --- a/crates/egui/src/widgets/plot/axis.rs +++ b/crates/egui/src/widgets/plot/axis.rs @@ -242,13 +242,13 @@ impl Widget for AxisWidget { if spacing_in_points <= MIN_TEXT_SPACING { continue; } - let line_weight = remap_clamp( + let line_strength = remap_clamp( spacing_in_points, MIN_TEXT_SPACING..=FULL_CONTRAST_SPACING, 0.0..=1.0, ); - let line_color = super::color_from_contrast(ui, line_weight); + let line_color = super::color_from_strength(ui, line_strength); let galley = ui .painter() .layout_no_wrap(text, font_id.clone(), line_color); diff --git a/crates/egui/src/widgets/plot/mod.rs b/crates/egui/src/widgets/plot/mod.rs index d9575e68c..382b3ee6d 100644 --- a/crates/egui/src/widgets/plot/mod.rs +++ b/crates/egui/src/widgets/plot/mod.rs @@ -1741,7 +1741,7 @@ impl PreparedPlot { 0.0..=1.0, ); - let line_color = color_from_contrast(ui, line_strength); + let line_color = color_from_strength(ui, line_strength); let mut p0 = pos_in_gui; let mut p1 = pos_in_gui; @@ -1875,10 +1875,11 @@ pub fn format_number(number: f64, num_decimals: usize) -> String { } } -pub fn color_from_contrast(ui: &Ui, contrast: f32) -> Color32 { +/// Determine a color from a 0-1 strength value. +pub fn color_from_strength(ui: &Ui, strength: f32) -> Color32 { let bg = ui.visuals().extreme_bg_color; let fg = ui.visuals().widgets.open.fg_stroke.color; - let mix = 0.5 * contrast.sqrt(); + let mix = 0.5 * strength.sqrt(); Color32::from_rgb( lerp((bg.r() as f32)..=(fg.r() as f32), mix) as u8, lerp((bg.g() as f32)..=(fg.g() as f32), mix) as u8,