Skip to content

Commit 01efb5e

Browse files
committed
Make pixel density an accessor like p5.
1 parent 52c0935 commit 01efb5e

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

crates/processing_pyo3/mewnala/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"focused",
2020
"pixel_width",
2121
"pixel_height",
22-
"pixel_density",
2322
)
2423
_DYNAMIC_FUNCTIONS = (
2524
"mouse_x",

crates/processing_pyo3/src/lib.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,9 +1658,24 @@ mod mewnala {
16581658
}
16591659

16601660
#[pyfunction]
1661-
#[pyo3(pass_module)]
1662-
fn pixel_density(module: &Bound<'_, PyModule>, density: f32) -> PyResult<()> {
1663-
graphics!(module).surface.set_pixel_density(density)
1661+
#[pyo3(pass_module, signature = (density=None))]
1662+
fn pixel_density<'py>(
1663+
module: &Bound<'py, PyModule>,
1664+
density: Option<f32>,
1665+
) -> PyResult<Py<PyAny>> {
1666+
let py = module.py();
1667+
match density {
1668+
Some(d) => {
1669+
graphics!(module).surface.set_pixel_density(d)?;
1670+
Ok(py.None())
1671+
}
1672+
None => {
1673+
let graphics = get_graphics(module)?
1674+
.ok_or_else(|| PyRuntimeError::new_err("call size() first"))?;
1675+
let current = graphics.surface.pixel_density()?;
1676+
Ok(current.into_pyobject(py)?.into_any().unbind())
1677+
}
1678+
}
16641679
}
16651680

16661681
#[pyfunction]

0 commit comments

Comments
 (0)