mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 05:40:03 -04:00
De-duplicate color_from_contrast
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
use std::{fmt::Debug, ops::RangeInclusive, sync::Arc};
|
use std::{fmt::Debug, ops::RangeInclusive, sync::Arc};
|
||||||
|
|
||||||
use epaint::{
|
use epaint::{
|
||||||
emath::{lerp, remap_clamp, round_to_decimals},
|
emath::{remap_clamp, round_to_decimals},
|
||||||
Color32, Pos2, Rect, Shape, Stroke, TextShape,
|
Pos2, Rect, Shape, Stroke, TextShape,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{Response, Sense, TextStyle, Ui, Widget, WidgetText};
|
use crate::{Response, Sense, TextStyle, Ui, Widget, WidgetText};
|
||||||
@@ -248,7 +248,7 @@ impl<const AXIS: usize> Widget for AxisWidget<AXIS> {
|
|||||||
0.0..=1.0,
|
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
|
let galley = ui
|
||||||
.painter()
|
.painter()
|
||||||
.layout_no_wrap(text, font_id.clone(), line_color);
|
.layout_no_wrap(text, font_id.clone(), line_color);
|
||||||
@@ -287,14 +287,3 @@ impl<const AXIS: usize> Widget for AxisWidget<AXIS> {
|
|||||||
response
|
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,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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<Shape>) -> Vec<Cursor> {
|
fn hover(&self, ui: &Ui, pointer: Pos2, shapes: &mut Vec<Shape>) -> Vec<Cursor> {
|
||||||
@@ -1885,3 +1874,14 @@ pub fn format_number(number: f64, num_decimals: usize) -> String {
|
|||||||
format!("{:.*}", num_decimals.at_least(1), number)
|
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,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user