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 struct Arrows {
|
||||||
pub(super) origins: PlotPoints,
|
pub(super) origins: PlotPoints,
|
||||||
pub(super) tips: PlotPoints,
|
pub(super) tips: PlotPoints,
|
||||||
|
pub(super) tip_length: Option<f32>,
|
||||||
pub(super) color: Color32,
|
pub(super) color: Color32,
|
||||||
pub(super) name: String,
|
pub(super) name: String,
|
||||||
pub(super) highlight: bool,
|
pub(super) highlight: bool,
|
||||||
|
|
@ -1007,6 +1008,7 @@ impl Arrows {
|
||||||
Self {
|
Self {
|
||||||
origins: origins.into(),
|
origins: origins.into(),
|
||||||
tips: tips.into(),
|
tips: tips.into(),
|
||||||
|
tip_length: None,
|
||||||
color: Color32::TRANSPARENT,
|
color: Color32::TRANSPARENT,
|
||||||
name: Default::default(),
|
name: Default::default(),
|
||||||
highlight: false,
|
highlight: false,
|
||||||
|
|
@ -1019,6 +1021,12 @@ impl Arrows {
|
||||||
self
|
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.
|
/// Set the arrows' color.
|
||||||
pub fn color(mut self, color: impl Into<Color32>) -> Self {
|
pub fn color(mut self, color: impl Into<Color32>) -> Self {
|
||||||
self.color = color.into();
|
self.color = color.into();
|
||||||
|
|
@ -1044,6 +1052,7 @@ impl PlotItem for Arrows {
|
||||||
let Self {
|
let Self {
|
||||||
origins,
|
origins,
|
||||||
tips,
|
tips,
|
||||||
|
tip_length,
|
||||||
color,
|
color,
|
||||||
highlight,
|
highlight,
|
||||||
..
|
..
|
||||||
|
|
@ -1062,7 +1071,11 @@ impl PlotItem for Arrows {
|
||||||
.for_each(|(origin, tip)| {
|
.for_each(|(origin, tip)| {
|
||||||
let vector = tip - origin;
|
let vector = tip - origin;
|
||||||
let rot = Rot2::from_angle(std::f32::consts::TAU / 10.0);
|
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 tip = origin + vector;
|
||||||
let dir = vector.normalized();
|
let dir = vector.normalized();
|
||||||
shapes.push(Shape::line_segment([origin, tip], stroke));
|
shapes.push(Shape::line_segment([origin, tip], stroke));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue