#[derive(Debug, Clone, PartialEq)]
pub enum Shape {
Ellipse(Ellipse),
Points(Points),
Text(Text),
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(
feature = "pyo3",
pyo3::pyclass(eq, get_all, set_all, from_py_object, module = "xdot_rs.shapes")
)]
pub struct Ellipse {
pub filled: bool,
pub x: f32,
pub y: f32,
pub w: f32,
pub h: f32,
}
#[cfg(feature = "pyo3")]
#[pyo3::pymethods]
impl Ellipse {
#[new]
#[pyo3(signature = (x, y, w, h, filled=true))]
fn new(x: f32, y: f32, w: f32, h: f32, filled: bool) -> Self {
Ellipse { x, y, w, h, filled }
}
}
impl From<Ellipse> for Shape {
fn from(val: Ellipse) -> Self {
Shape::Ellipse(val)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(
feature = "pyo3",
pyo3::pyclass(
eq,
eq_int,
get_all,
set_all,
from_py_object,
module = "xdot_rs.shapes"
)
)]
pub enum PointsType {
Polygon,
Polyline,
BSpline,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(
feature = "pyo3",
pyo3::pyclass(eq, get_all, set_all, from_py_object, module = "xdot_rs.shapes")
)]
pub struct Points {
pub filled: bool,
pub r#type: PointsType,
pub points: Vec<(f32, f32)>,
}
#[cfg(feature = "pyo3")]
#[pyo3::pymethods]
impl Points {
#[new]
#[pyo3(signature = (r#type, points, filled=true))]
fn new(r#type: PointsType, points: Vec<(f32, f32)>, filled: bool) -> Self {
Points {
points,
r#type,
filled,
}
}
}
impl From<Points> for Shape {
fn from(val: Points) -> Self {
Shape::Points(val)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(
feature = "pyo3",
pyo3::pyclass(
eq,
eq_int,
get_all,
set_all,
from_py_object,
module = "xdot_rs.shapes"
)
)]
pub enum TextAlign {
Left,
Center,
Right,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(
feature = "pyo3",
pyo3::pyclass(eq, get_all, set_all, from_py_object, module = "xdot_rs.shapes")
)]
pub struct Text {
pub x: f32,
pub y: f32,
pub align: TextAlign,
pub width: f32,
pub text: String,
}
#[cfg(feature = "pyo3")]
#[pyo3::pymethods]
impl Text {
#[new]
fn new(x: f32, y: f32, align: TextAlign, width: f32, text: String) -> Self {
Text {
x,
y,
align,
width,
text,
}
}
}
impl From<Text> for Shape {
fn from(val: Text) -> Self {
Shape::Text(val)
}
}
#[doc(hidden)]
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(
feature = "pyo3",
pyo3::pyclass(from_py_object, module = "xdot_rs.shapes")
)]
pub struct ExternalImage;
#[cfg(feature = "pyo3")]
#[pyo3::pymodule]
pub mod shapes {
#[pymodule_export]
pub use super::{Ellipse, ExternalImage, Points, PointsType, Text, TextAlign};
}