Skip to content

Commit 20f4cec

Browse files
committed
fmt.
1 parent 78247e0 commit 20f4cec

File tree

2 files changed

+43
-15
lines changed

2 files changed

+43
-15
lines changed

crates/processing_pyo3/src/graphics.rs

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use bevy::prelude::Entity;
22
use processing::prelude::*;
3-
use pyo3::exceptions::PyRuntimeError;
4-
use pyo3::prelude::*;
5-
use pyo3::types::PyAny;
3+
use pyo3::{exceptions::PyRuntimeError, prelude::*, types::PyAny};
64

75
use crate::glfw::GlfwContext;
86

@@ -16,8 +14,8 @@ pub struct Graphics {
1614
impl Graphics {
1715
#[new]
1816
pub fn new(width: u32, height: u32) -> PyResult<Self> {
19-
let glfw_ctx = GlfwContext::new(width, height)
20-
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
17+
let glfw_ctx =
18+
GlfwContext::new(width, height).map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
2119

2220
init().map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
2321

@@ -65,10 +63,26 @@ impl Graphics {
6563
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
6664
}
6765

68-
pub fn rect(&self, x: f32, y: f32, w: f32, h: f32, tl: f32, tr: f32, br: f32, bl: f32) -> PyResult<()> {
66+
pub fn rect(
67+
&self,
68+
x: f32,
69+
y: f32,
70+
w: f32,
71+
h: f32,
72+
tl: f32,
73+
tr: f32,
74+
br: f32,
75+
bl: f32,
76+
) -> PyResult<()> {
6977
graphics_record_command(
7078
self.surface,
71-
DrawCommand::Rect { x, y, w, h, radii: [tl, tr, br, bl] },
79+
DrawCommand::Rect {
80+
x,
81+
y,
82+
w,
83+
h,
84+
radii: [tl, tr, br, bl],
85+
},
7286
)
7387
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
7488
}
@@ -84,12 +98,12 @@ impl Graphics {
8498

8599
if let Some(ref draw) = draw_fn {
86100
Python::attach(|py| {
87-
draw.call0(py).map_err(|e| PyRuntimeError::new_err(format!("{e}")))
101+
draw.call0(py)
102+
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
88103
})?;
89104
}
90105

91-
graphics_end_draw(self.surface)
92-
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
106+
graphics_end_draw(self.surface).map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
93107
}
94108
Ok(())
95109
}
@@ -108,7 +122,12 @@ fn parse_color(args: &[f32]) -> PyResult<(f32, f32, f32, f32)> {
108122
Ok((v, v, v, args[1] / 255.0))
109123
}
110124
3 => Ok((args[0] / 255.0, args[1] / 255.0, args[2] / 255.0, 1.0)),
111-
4 => Ok((args[0] / 255.0, args[1] / 255.0, args[2] / 255.0, args[3] / 255.0)),
125+
4 => Ok((
126+
args[0] / 255.0,
127+
args[1] / 255.0,
128+
args[2] / 255.0,
129+
args[3] / 255.0,
130+
)),
112131
_ => Err(PyRuntimeError::new_err("color requires 1-4 arguments")),
113132
}
114133
}

crates/processing_pyo3/src/lib.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
mod glfw;
1212
mod graphics;
1313

14-
use graphics::{get_graphics, get_graphics_mut, Graphics};
15-
use pyo3::prelude::*;
16-
use pyo3::types::PyAny;
14+
use graphics::{Graphics, get_graphics, get_graphics_mut};
15+
use pyo3::{prelude::*, types::PyAny};
1716

1817
#[pymodule]
1918
fn processing(m: &Bound<'_, PyModule>) -> PyResult<()> {
@@ -82,6 +81,16 @@ fn stroke_weight(module: &Bound<'_, PyModule>, weight: f32) -> PyResult<()> {
8281

8382
#[pyfunction]
8483
#[pyo3(pass_module, signature = (x, y, w, h, tl=0.0, tr=0.0, br=0.0, bl=0.0))]
85-
fn rect(module: &Bound<'_, PyModule>, x: f32, y: f32, w: f32, h: f32, tl: f32, tr: f32, br: f32, bl: f32) -> PyResult<()> {
84+
fn rect(
85+
module: &Bound<'_, PyModule>,
86+
x: f32,
87+
y: f32,
88+
w: f32,
89+
h: f32,
90+
tl: f32,
91+
tr: f32,
92+
br: f32,
93+
bl: f32,
94+
) -> PyResult<()> {
8695
get_graphics(module)?.rect(x, y, w, h, tl, tr, br, bl)
8796
}

0 commit comments

Comments
 (0)