Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved plot interaction methods #892

Merged
merged 6 commits into from
Nov 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ NOTE: [`epaint`](epaint/CHANGELOG.md), [`eframe`](eframe/CHANGELOG.md), [`egui_w
* You can now read and write the cursor of a `TextEdit` ([#848](https://github.com/emilk/egui/pull/848)).
* Most widgets containing text (`Label`, `Button` etc) now supports rich text ([#855](https://github.com/emilk/egui/pull/855)).
* When using a custom font you can now specify a font index ([#873](https://github.com/emilk/egui/pull/873)).
* You can now read the plot coordinates of the mouse when building a `Plot` ([#766](https://github.com/emilk/egui/pull/766)).
* You can now query information about the plot (e.g. get the mouse position in plot coordinates, or the plot
bounds) while adding items. `Plot` ([#766](https://github.com/emilk/egui/pull/766) and
[#892](https://github.com/emilk/egui/pull/892)).
* Add vertical sliders with `Slider::new(…).vertical()` ([#875](https://github.com/emilk/egui/pull/875)).
* Add `Button::image_and_text` ([#832](https://github.com/emilk/egui/pull/832)).

Expand All @@ -36,7 +38,7 @@ NOTE: [`epaint`](epaint/CHANGELOG.md), [`eframe`](eframe/CHANGELOG.md), [`egui_w
* [5225225](https://github.com/5225225): ([#849](https://github.com/emilk/egui/pull/849)).
* [B-Reif](https://github.com/B-Reif) ([#875](https://github.com/emilk/egui/pull/875)).
* [d10sfan](https://github.com/d10sfan) ([#832](https://github.com/emilk/egui/pull/832)).
* [EmbersArc](https://github.com/EmbersArc): ([#766](https://github.com/emilk/egui/pull/766)).
* [EmbersArc](https://github.com/EmbersArc): ([#766](https://github.com/emilk/egui/pull/766), [#892](https://github.com/emilk/egui/pull/892)).
* [mankinskin](https://github.com/mankinskin) ([#543](https://github.com/emilk/egui/pull/543)).
* [sumibi-yakitori](https://github.com/sumibi-yakitori) ([#830](https://github.com/emilk/egui/pull/830)).
* [t18b219k](https://github.com/t18b219k): ([#868](https://github.com/emilk/egui/pull/868), [#888](https://github.com/emilk/egui/pull/888)).
Expand Down
32 changes: 16 additions & 16 deletions egui/src/widgets/plot/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::ops::{Bound, RangeBounds, RangeInclusive};

use epaint::Mesh;

use super::transform::{Bounds, ScreenTransform};
use super::transform::{PlotBounds, ScreenTransform};
use crate::*;

const DEFAULT_FILL_ALPHA: f32 = 0.05;
Expand Down Expand Up @@ -233,8 +233,8 @@ impl PlotItem for HLine {
None
}

fn get_bounds(&self) -> Bounds {
let mut bounds = Bounds::NOTHING;
fn get_bounds(&self) -> PlotBounds {
let mut bounds = PlotBounds::NOTHING;
bounds.min[1] = self.y;
bounds.max[1] = self.y;
bounds
Expand Down Expand Up @@ -343,8 +343,8 @@ impl PlotItem for VLine {
None
}

fn get_bounds(&self) -> Bounds {
let mut bounds = Bounds::NOTHING;
fn get_bounds(&self) -> PlotBounds {
let mut bounds = PlotBounds::NOTHING;
bounds.min[0] = self.x;
bounds.max[0] = self.x;
bounds
Expand All @@ -360,7 +360,7 @@ pub(super) trait PlotItem {
fn highlight(&mut self);
fn highlighted(&self) -> bool;
fn values(&self) -> Option<&Values>;
fn get_bounds(&self) -> Bounds;
fn get_bounds(&self) -> PlotBounds;
}

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -503,8 +503,8 @@ impl Values {
(start < end).then(|| start..=end)
}

pub(super) fn get_bounds(&self) -> Bounds {
let mut bounds = Bounds::NOTHING;
pub(super) fn get_bounds(&self) -> PlotBounds {
let mut bounds = PlotBounds::NOTHING;
self.values
.iter()
.for_each(|value| bounds.extend_with(value));
Expand Down Expand Up @@ -710,7 +710,7 @@ impl PlotItem for Line {
Some(&self.series)
}

fn get_bounds(&self) -> Bounds {
fn get_bounds(&self) -> PlotBounds {
self.series.get_bounds()
}
}
Expand Down Expand Up @@ -840,7 +840,7 @@ impl PlotItem for Polygon {
Some(&self.series)
}

fn get_bounds(&self) -> Bounds {
fn get_bounds(&self) -> PlotBounds {
self.series.get_bounds()
}
}
Expand Down Expand Up @@ -953,8 +953,8 @@ impl PlotItem for Text {
None
}

fn get_bounds(&self) -> Bounds {
let mut bounds = Bounds::NOTHING;
fn get_bounds(&self) -> PlotBounds {
let mut bounds = PlotBounds::NOTHING;
bounds.extend_with(&self.position);
bounds
}
Expand Down Expand Up @@ -1186,7 +1186,7 @@ impl PlotItem for Points {
Some(&self.series)
}

fn get_bounds(&self) -> Bounds {
fn get_bounds(&self) -> PlotBounds {
self.series.get_bounds()
}
}
Expand Down Expand Up @@ -1301,7 +1301,7 @@ impl PlotItem for Arrows {
Some(&self.origins)
}

fn get_bounds(&self) -> Bounds {
fn get_bounds(&self) -> PlotBounds {
self.origins.get_bounds()
}
}
Expand Down Expand Up @@ -1431,8 +1431,8 @@ impl PlotItem for PlotImage {
None
}

fn get_bounds(&self) -> Bounds {
let mut bounds = Bounds::NOTHING;
fn get_bounds(&self) -> PlotBounds {
let mut bounds = PlotBounds::NOTHING;
let left_top = Value::new(
self.position.x as f32 - self.size.x / 2.0,
self.position.y as f32 - self.size.y / 2.0,
Expand Down
Loading