11use bevy:: prelude:: Entity ;
22use 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
75use crate :: glfw:: GlfwContext ;
86
@@ -16,8 +14,8 @@ pub struct Graphics {
1614impl 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}
0 commit comments