@@ -11,6 +11,20 @@ use stdweb::web::Date;
1111use stdweb:: web:: { document, CanvasRenderingContext2d } ;
1212use yew:: prelude:: * ;
1313
14+ pub enum Screen {
15+ Splash ,
16+ Video ,
17+ Snapshot ,
18+ }
19+
20+ #[ derive( Clone ) ]
21+ pub struct ButtonPosition {
22+ x : u32 ,
23+ y : u32 ,
24+ width : u32 ,
25+ height : u32 ,
26+ }
27+
1428pub enum Msg {
1529 SwapToVideo ,
1630 TakePicture ,
@@ -19,27 +33,13 @@ pub enum Msg {
1933 DownloadButtonClicked ,
2034}
2135
22- pub enum Screen {
23- Splash ,
24- Video ,
25- Snapshot ,
26- }
27-
2836pub struct State {
2937 link : ComponentLink < State > ,
3038 screen : Screen ,
3139 snapshot_data_url : Option < String > ,
3240 download_button_position : Option < ButtonPosition > ,
3341}
3442
35- #[ derive( Clone ) ]
36- pub struct ButtonPosition {
37- x : u32 ,
38- y : u32 ,
39- width : u32 ,
40- height : u32 ,
41- }
42-
4343impl Component for State {
4444 type Message = Msg ;
4545 type Properties = ( ) ;
@@ -82,13 +82,6 @@ impl Component for State {
8282 . replace ( "image/jpeg" , "image/octet-stream" ) ;
8383 download. set_attribute ( "href" , & img) . unwrap ( ) ;
8484
85- js ! { console. log( "Download button clicked" ) ; }
86- /*
87- var canvas = document.getElementById("mycanvas");
88- var img = canvas.toDataURL("image/png");
89- document.write('<img src="'+img+'"/>');
90- */
91-
9285 false
9386 }
9487 Msg :: TakePicture => {
@@ -135,11 +128,6 @@ impl Component for State {
135128 }
136129}
137130
138- fn resize_canvas ( canvas : & CanvasElement ) {
139- canvas. set_width ( canvas. offset_width ( ) as u32 ) ;
140- canvas. set_height ( canvas. offset_height ( ) as u32 ) ;
141- }
142-
143131impl Renderable < State > for State {
144132 fn view ( & self ) -> Html < Self > {
145133 match self . screen {
@@ -168,6 +156,11 @@ impl Renderable<State> for State {
168156 }
169157}
170158
159+ fn resize_canvas ( canvas : & CanvasElement ) {
160+ canvas. set_width ( canvas. offset_width ( ) as u32 ) ;
161+ canvas. set_height ( canvas. offset_height ( ) as u32 ) ;
162+ }
163+
171164fn download_file_name ( ) -> String {
172165 let to_secs = 1000 ;
173166 format ! ( "vision-{}.jpg" , Date :: now( ) as u64 / to_secs as u64 )
0 commit comments