diff --git a/crates/egui/src/widgets/plot/axis.rs b/crates/egui/src/widgets/plot/axis.rs index 7b2a18aef..4e877a144 100644 --- a/crates/egui/src/widgets/plot/axis.rs +++ b/crates/egui/src/widgets/plot/axis.rs @@ -1,8 +1,8 @@ use std::{fmt::Debug, ops::RangeInclusive, sync::Arc}; use epaint::{ - emath::{lerp, remap_clamp, round_to_decimals}, - Color32, Pos2, Rect, Shape, Stroke, TextShape, + emath::{remap_clamp, round_to_decimals}, + Pos2, Rect, Shape, Stroke, TextShape, }; use crate::{Response, Sense, TextStyle, Ui, Widget, WidgetText}; @@ -248,7 +248,7 @@ impl Widget for AxisWidget { 0.0..=1.0, ); - let line_color = color_from_contrast(ui, line_weight); + let line_color = super::color_from_contrast(ui, line_weight); let galley = ui .painter() .layout_no_wrap(text, font_id.clone(), line_color); @@ -287,14 +287,3 @@ impl Widget for AxisWidget { response } } - -fn color_from_contrast(ui: &Ui, contrast: f32) -> Color32 { - let bg = ui.visuals().extreme_bg_color; - let fg = ui.visuals().widgets.open.fg_stroke.color; - let mix = 0.5 * contrast.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, - lerp((bg.b() as f32)..=(fg.b() as f32), mix) as u8, - ) -} diff --git a/crates/egui/src/widgets/plot/mod.rs b/crates/egui/src/widgets/plot/mod.rs index 72f7abd62..d9575e68c 100644 --- a/crates/egui/src/widgets/plot/mod.rs +++ b/crates/egui/src/widgets/plot/mod.rs @@ -1770,17 +1770,6 @@ impl PreparedPlot { )); } } - - fn color_from_contrast(ui: &Ui, contrast: f32) -> Color32 { - let bg = ui.visuals().extreme_bg_color; - let fg = ui.visuals().widgets.open.fg_stroke.color; - let mix = 0.5 * contrast.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, - lerp((bg.b() as f32)..=(fg.b() as f32), mix) as u8, - ) - } } fn hover(&self, ui: &Ui, pointer: Pos2, shapes: &mut Vec) -> Vec { @@ -1885,3 +1874,14 @@ pub fn format_number(number: f64, num_decimals: usize) -> String { format!("{:.*}", num_decimals.at_least(1), number) } } + +pub fn color_from_contrast(ui: &Ui, contrast: f32) -> Color32 { + let bg = ui.visuals().extreme_bg_color; + let fg = ui.visuals().widgets.open.fg_stroke.color; + let mix = 0.5 * contrast.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, + lerp((bg.b() as f32)..=(fg.b() as f32), mix) as u8, + ) +}