mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 13:20:05 -04:00
Make egui_plot::PlotItem a public trait (#3943)
This commit is contained in:
@@ -23,7 +23,7 @@ mod values;
|
||||
const DEFAULT_FILL_ALPHA: f32 = 0.05;
|
||||
|
||||
/// Container to pass-through several parameters related to plot visualization
|
||||
pub(super) struct PlotConfig<'a> {
|
||||
pub struct PlotConfig<'a> {
|
||||
pub ui: &'a Ui,
|
||||
pub transform: &'a PlotTransform,
|
||||
pub show_x: bool,
|
||||
@@ -31,8 +31,8 @@ pub(super) struct PlotConfig<'a> {
|
||||
}
|
||||
|
||||
/// Trait shared by things that can be drawn in the plot.
|
||||
pub(super) trait PlotItem {
|
||||
fn shapes(&self, ui: &mut Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>);
|
||||
pub trait PlotItem {
|
||||
fn shapes(&self, ui: &Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>);
|
||||
|
||||
/// For plot-items which are generated based on x values (plotting functions).
|
||||
fn initialize(&mut self, x_range: RangeInclusive<f64>);
|
||||
@@ -194,7 +194,7 @@ impl HLine {
|
||||
}
|
||||
|
||||
impl PlotItem for HLine {
|
||||
fn shapes(&self, ui: &mut Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
|
||||
fn shapes(&self, ui: &Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
|
||||
let Self {
|
||||
y,
|
||||
stroke,
|
||||
@@ -329,7 +329,7 @@ impl VLine {
|
||||
}
|
||||
|
||||
impl PlotItem for VLine {
|
||||
fn shapes(&self, ui: &mut Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
|
||||
fn shapes(&self, ui: &Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
|
||||
let Self {
|
||||
x,
|
||||
stroke,
|
||||
@@ -479,7 +479,7 @@ fn y_intersection(p1: &Pos2, p2: &Pos2, y: f32) -> Option<f32> {
|
||||
}
|
||||
|
||||
impl PlotItem for Line {
|
||||
fn shapes(&self, _ui: &mut Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
|
||||
fn shapes(&self, _ui: &Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
|
||||
let Self {
|
||||
series,
|
||||
stroke,
|
||||
@@ -653,7 +653,7 @@ impl Polygon {
|
||||
}
|
||||
|
||||
impl PlotItem for Polygon {
|
||||
fn shapes(&self, _ui: &mut Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
|
||||
fn shapes(&self, _ui: &Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
|
||||
let Self {
|
||||
series,
|
||||
stroke,
|
||||
@@ -778,7 +778,7 @@ impl Text {
|
||||
}
|
||||
|
||||
impl PlotItem for Text {
|
||||
fn shapes(&self, ui: &mut Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
|
||||
fn shapes(&self, ui: &Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
|
||||
let color = if self.color == Color32::TRANSPARENT {
|
||||
ui.style().visuals.text_color()
|
||||
} else {
|
||||
@@ -910,7 +910,7 @@ impl Points {
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the maximum extent of the marker around its position.
|
||||
/// Set the maximum extent of the marker around its position, in ui points.
|
||||
#[inline]
|
||||
pub fn radius(mut self, radius: impl Into<f32>) -> Self {
|
||||
self.radius = radius.into();
|
||||
@@ -939,7 +939,7 @@ impl Points {
|
||||
}
|
||||
|
||||
impl PlotItem for Points {
|
||||
fn shapes(&self, _ui: &mut Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
|
||||
fn shapes(&self, _ui: &Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
|
||||
let sqrt_3 = 3_f32.sqrt();
|
||||
let frac_sqrt_3_2 = 3_f32.sqrt() / 2.0;
|
||||
let frac_1_sqrt_2 = 1.0 / 2_f32.sqrt();
|
||||
@@ -1167,7 +1167,7 @@ impl Arrows {
|
||||
}
|
||||
|
||||
impl PlotItem for Arrows {
|
||||
fn shapes(&self, _ui: &mut Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
|
||||
fn shapes(&self, _ui: &Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
|
||||
use crate::emath::*;
|
||||
let Self {
|
||||
origins,
|
||||
@@ -1331,7 +1331,7 @@ impl PlotImage {
|
||||
}
|
||||
|
||||
impl PlotItem for PlotImage {
|
||||
fn shapes(&self, ui: &mut Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
|
||||
fn shapes(&self, ui: &Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
|
||||
let Self {
|
||||
position,
|
||||
rotation,
|
||||
@@ -1565,7 +1565,7 @@ impl BarChart {
|
||||
}
|
||||
|
||||
impl PlotItem for BarChart {
|
||||
fn shapes(&self, _ui: &mut Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
|
||||
fn shapes(&self, _ui: &Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
|
||||
for b in &self.bars {
|
||||
b.add_shapes(transform, self.highlight, shapes);
|
||||
}
|
||||
@@ -1726,7 +1726,7 @@ impl BoxPlot {
|
||||
}
|
||||
|
||||
impl PlotItem for BoxPlot {
|
||||
fn shapes(&self, _ui: &mut Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
|
||||
fn shapes(&self, _ui: &Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
|
||||
for b in &self.boxes {
|
||||
b.add_shapes(transform, self.highlight, shapes);
|
||||
}
|
||||
|
||||
@@ -357,7 +357,7 @@ impl MarkerShape {
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/// Query the points of the plot, for geometric relations like closest checks
|
||||
pub(crate) enum PlotGeometry<'a> {
|
||||
pub enum PlotGeometry<'a> {
|
||||
/// No geometry based on single elements (examples: text, image, horizontal/vertical line)
|
||||
None,
|
||||
|
||||
@@ -425,7 +425,7 @@ impl ExplicitGenerator {
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/// Result of [`super::PlotItem::find_closest()`] search, identifies an element inside the item for immediate use
|
||||
pub(crate) struct ClosestElem {
|
||||
pub struct ClosestElem {
|
||||
/// Position of hovered-over value (or bar/box-plot/...) in PlotItem
|
||||
pub index: usize,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user