iced_plot 0.4.0

A GPU-accelerated plotting widget for Iced.
Documentation
use std::sync::{Arc, RwLock};

/// Represents a shared axis link that can synchronize camera positions
/// across multiple plot widgets.
#[derive(Clone, Debug, Default)]
pub struct AxisLink {
    inner: Arc<RwLock<AxisLinkInner>>,
}

#[derive(Debug, Default)]
struct AxisLinkInner {
    /// The shared camera position
    position: f64,
    /// The shared camera half extent
    half_extent: f64,
    /// Version counter to detect changes
    version: u64,
}

impl AxisLink {
    /// Create a new axis link.
    pub fn new() -> Self {
        Default::default()
    }

    /// Get the current position and half extent
    pub(crate) fn get(&self) -> (f64, f64, u64) {
        let inner = self.inner.read().unwrap();
        (inner.position, inner.half_extent, inner.version)
    }

    /// Update the position and half extent, incrementing the version
    pub(crate) fn set(&self, position: f64, half_extent: f64) {
        let mut inner = self.inner.write().unwrap();
        inner.position = position;
        inner.half_extent = half_extent;
        inner.version = inner.version.wrapping_add(1);
    }

    /// Get the current version
    pub(crate) fn version(&self) -> u64 {
        self.inner.read().unwrap().version
    }
}