egui: Plot Arrows add method to specify tip_size (#3138)
Normally the tip_size will be dependent on the arrow length. This patch adds a new method to explicitly set the arrow tip size.
This commit is contained in:
parent
e82ec74c5c
commit
cbdf748a3b
|
|
@ -997,6 +997,7 @@ impl PlotItem for Points {
|
|||
pub struct Arrows {
|
||||
pub(super) origins: PlotPoints,
|
||||
pub(super) tips: PlotPoints,
|
||||
pub(super) tip_length: Option<f32>,
|
||||
pub(super) color: Color32,
|
||||
pub(super) name: String,
|
||||
pub(super) highlight: bool,
|
||||
|
|
@ -1007,6 +1008,7 @@ impl Arrows {
|
|||
Self {
|
||||
origins: origins.into(),
|
||||
tips: tips.into(),
|
||||
tip_length: None,
|
||||
color: Color32::TRANSPARENT,
|
||||
name: Default::default(),
|
||||
highlight: false,
|
||||
|
|
@ -1019,6 +1021,12 @@ impl Arrows {
|
|||
self
|
||||
}
|
||||
|
||||
/// Set the length of the arrow tips
|
||||
pub fn tip_length(mut self, tip_length: f32) -> Self {
|
||||
self.tip_length = Some(tip_length);
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the arrows' color.
|
||||
pub fn color(mut self, color: impl Into<Color32>) -> Self {
|
||||
self.color = color.into();
|
||||
|
|
@ -1044,6 +1052,7 @@ impl PlotItem for Arrows {
|
|||
let Self {
|
||||
origins,
|
||||
tips,
|
||||
tip_length,
|
||||
color,
|
||||
highlight,
|
||||
..
|
||||
|
|
@ -1062,7 +1071,11 @@ impl PlotItem for Arrows {
|
|||
.for_each(|(origin, tip)| {
|
||||
let vector = tip - origin;
|
||||
let rot = Rot2::from_angle(std::f32::consts::TAU / 10.0);
|
||||
let tip_length = vector.length() / 4.0;
|
||||
let tip_length = if let Some(tip_length) = tip_length {
|
||||
*tip_length
|
||||
} else {
|
||||
vector.length() / 4.0
|
||||
};
|
||||
let tip = origin + vector;
|
||||
let dir = vector.normalized();
|
||||
shapes.push(Shape::line_segment([origin, tip], stroke));
|
||||
|
|
|
|||
Loading…
Reference in New Issue