mirror of
https://github.com/emilk/egui.git
synced 2026-06-27 23:13:13 -04:00
<!-- Please read the "Making a PR" section of [`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md) before opening a Pull Request! * Keep your PR:s small and focused. * The PR title is what ends up in the changelog, so make it descriptive! * If applicable, add a screenshot or gif. * If it is a non-trivial addition, consider adding a demo for it to `egui_demo_lib`, or a new example. * Do NOT open PR:s from your `master` branch, as that makes it hard for maintainers to add commits to your PR. * Remember to run `cargo fmt` and `cargo clippy`. * Open the PR as a draft until you have self-reviewed it and run `./scripts/check.sh`. * When you have addressed a PR comment, mark it as resolved. Please be patient! I will review your PR, but my time is limited! --> Related to #3482 Not sure what the "best practice" is, to me it seems like one should import from "the original location" if possible, but now it should at least be possible to not re-export ahash without any breakage in the egui code base (but possibly in projects using egui, so one should probably deprecate it if one would like to go that path). It also seems like epaint re-exports ahash.
82 lines
2.2 KiB
Rust
82 lines
2.2 KiB
Rust
use std::collections::BTreeMap;
|
|
|
|
use egui::{Context, Id, Pos2, Vec2b};
|
|
|
|
use crate::{PlotBounds, PlotTransform};
|
|
|
|
/// Information about the plot that has to persist between frames.
|
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
|
#[derive(Clone)]
|
|
pub struct PlotMemory {
|
|
/// Indicates if the plot uses automatic bounds.
|
|
///
|
|
/// This is set to `false` whenever the user modifies
|
|
/// the bounds, for example by moving or zooming.
|
|
pub auto_bounds: Vec2b,
|
|
|
|
/// Display string of the hovered legend item if any.
|
|
pub hovered_legend_item: Option<String>,
|
|
|
|
/// Which items _not_ to show?
|
|
pub hidden_items: ahash::HashSet<String>,
|
|
|
|
/// The transform from last frame.
|
|
pub(crate) transform: PlotTransform,
|
|
|
|
/// Allows to remember the first click position when performing a boxed zoom
|
|
pub(crate) last_click_pos_for_zoom: Option<Pos2>,
|
|
|
|
/// The thickness of each of the axes the previous frame.
|
|
///
|
|
/// This is used in the next frame to make the axes thicker
|
|
/// in order to fit the labels, if necessary.
|
|
pub(crate) x_axis_thickness: BTreeMap<usize, f32>,
|
|
pub(crate) y_axis_thickness: BTreeMap<usize, f32>,
|
|
}
|
|
|
|
impl PlotMemory {
|
|
#[inline]
|
|
pub fn transform(&self) -> PlotTransform {
|
|
self.transform
|
|
}
|
|
|
|
#[inline]
|
|
pub fn set_transform(&mut self, t: PlotTransform) {
|
|
self.transform = t;
|
|
}
|
|
|
|
/// Plot-space bounds.
|
|
#[inline]
|
|
pub fn bounds(&self) -> &PlotBounds {
|
|
self.transform.bounds()
|
|
}
|
|
|
|
/// Plot-space bounds.
|
|
#[inline]
|
|
pub fn set_bounds(&mut self, bounds: PlotBounds) {
|
|
self.transform.set_bounds(bounds);
|
|
}
|
|
}
|
|
|
|
#[cfg(feature = "serde")]
|
|
impl PlotMemory {
|
|
pub fn load(ctx: &Context, id: Id) -> Option<Self> {
|
|
ctx.data_mut(|d| d.get_persisted(id))
|
|
}
|
|
|
|
pub fn store(self, ctx: &Context, id: Id) {
|
|
ctx.data_mut(|d| d.insert_persisted(id, self));
|
|
}
|
|
}
|
|
|
|
#[cfg(not(feature = "serde"))]
|
|
impl PlotMemory {
|
|
pub fn load(ctx: &Context, id: Id) -> Option<Self> {
|
|
ctx.data_mut(|d| d.get_temp(id))
|
|
}
|
|
|
|
pub fn store(self, ctx: &Context, id: Id) {
|
|
ctx.data_mut(|d| d.insert_temp(id, self));
|
|
}
|
|
}
|