@@ -123,13 +123,13 @@ impl App {
123123 #[ cfg( any( feature = "skia" , feature = "tiny-skia" ) ) ]
124124 #[ cfg( not( feature = "skia-vulkan" ) ) ]
125125 surface_state : None ,
126- #[ cfg( any( feature = "skia" , feature = "tiny-skia" ) ) ]
126+ #[ cfg( any( feature = "skia" , feature = "tiny-skia" , feature = "wasm-draw" ) ) ]
127127 input_state : rupl:: types:: InputState :: default ( ) ,
128- #[ cfg( any( feature = "skia" , feature = "tiny-skia" ) ) ]
128+ #[ cfg( any( feature = "skia" , feature = "tiny-skia" , feature = "wasm-draw" ) ) ]
129129 name : function,
130- #[ cfg( any( feature = "skia" , feature = "tiny-skia" ) ) ]
130+ #[ cfg( any( feature = "skia" , feature = "tiny-skia" , feature = "wasm-draw" ) ) ]
131131 touch_positions : Default :: default ( ) ,
132- #[ cfg( any( feature = "skia" , feature = "tiny-skia" ) ) ]
132+ #[ cfg( any( feature = "skia" , feature = "tiny-skia" , feature = "wasm-draw" ) ) ]
133133 last_touch_positions : Default :: default ( ) ,
134134 }
135135 }
@@ -184,13 +184,13 @@ impl App {
184184 #[ cfg( any( feature = "skia" , feature = "tiny-skia" ) ) ]
185185 #[ cfg( not( feature = "wasm" ) ) ]
186186 surface_state : None ,
187- #[ cfg( any( feature = "skia" , feature = "tiny-skia" ) ) ]
187+ #[ cfg( any( feature = "skia" , feature = "tiny-skia" , feature = "wasm-draw" ) ) ]
188188 input_state : rupl:: types:: InputState :: default ( ) ,
189- #[ cfg( any( feature = "skia" , feature = "tiny-skia" ) ) ]
189+ #[ cfg( any( feature = "skia" , feature = "tiny-skia" , feature = "wasm-draw" ) ) ]
190190 name : _function,
191- #[ cfg( any( feature = "skia" , feature = "tiny-skia" ) ) ]
191+ #[ cfg( any( feature = "skia" , feature = "tiny-skia" , feature = "wasm-draw" ) ) ]
192192 touch_positions : Default :: default ( ) ,
193- #[ cfg( any( feature = "skia" , feature = "tiny-skia" ) ) ]
193+ #[ cfg( any( feature = "skia" , feature = "tiny-skia" , feature = "wasm-draw" ) ) ]
194194 last_touch_positions : Default :: default ( ) ,
195195 }
196196 }
@@ -307,8 +307,49 @@ impl App {
307307 }
308308 }
309309 }
310+ #[ cfg( feature = "wasm" ) ]
311+ #[ cfg( feature = "wasm-draw" ) ]
312+ pub ( crate ) fn main ( & mut self , width : u32 , height : u32 ) {
313+ let mut b = false ;
314+ self . plot . keybinds ( & self . input_state ) ;
315+ self . plot
316+ . set_screen ( width as f64 , height as f64 , true , true ) ;
317+ #[ cfg( feature = "bincode" ) ]
318+ if let Some ( tiny) = std:: mem:: take ( & mut self . tiny ) {
319+ self . plot . apply_tiny ( tiny) ;
320+ }
321+ if let Some ( n) = self . data . update ( & mut self . plot ) {
322+ b = true ;
323+ self . name = n;
324+ } ;
325+ use wasm_bindgen:: prelude:: * ;
326+ use winit:: platform:: web:: WindowExtWebSys ;
327+ let canvas: web_sys:: HtmlCanvasElement = self
328+ . window
329+ . as_ref ( )
330+ . unwrap ( )
331+ . canvas ( )
332+ . expect ( "Failed to get canvas" ) ;
333+ let ctx: web_sys:: CanvasRenderingContext2d = canvas
334+ . get_context ( "2d" )
335+ . expect ( "Failed to get 2d context" )
336+ . expect ( "Failed to get 2d context" )
337+ . dyn_into ( )
338+ . expect ( "Failed to convert to CanvasRenderingContext2d" ) ;
339+ self . plot . update ( width, height, ctx) ;
340+ if b {
341+ let name = self . name . clone ( ) ;
342+ if let Some ( w) = self . window ( ) {
343+ if name. is_empty ( ) {
344+ w. set_title ( "kalc-plot" ) ;
345+ } else {
346+ w. set_title ( & name) ;
347+ }
348+ }
349+ }
350+ }
310351}
311- #[ cfg( feature = "wasm" ) ]
352+ #[ cfg( all ( feature = "wasm" , feature = "tiny-skia" ) ) ]
312353fn draw_buffer_web ( win : & winit:: window:: Window , width : u32 , clamped : wasm_bindgen:: Clamped < & [ u8 ] > ) {
313354 use wasm_bindgen:: prelude:: * ;
314355 let canvas = get_a_canvas ( win) ;
0 commit comments