1+ use std:: sync:: Arc ;
2+
13use bevy:: app:: PluginGroupBuilder ;
24use bevy:: input:: mouse:: MouseMotion ;
35use bevy:: prelude:: * ;
@@ -64,7 +66,7 @@ impl NotationApp {
6466 console_error_panic_hook:: set_once ( ) ;
6567
6668 #[ cfg( target_arch = "wasm32" ) ]
67- app. add_plugin ( crate :: ext :: bevy_web_fullscreen:: FullViewportPlugin ) ;
69+ app. add_plugin ( crate :: wasm :: bevy_web_fullscreen:: FullViewportPlugin ) ;
6870
6971 app. add_plugin ( bevy_egui:: EguiPlugin ) ;
7072 app. add_plugin ( NotationUiPlugin ) ;
@@ -101,13 +103,13 @@ impl NotationApp {
101103
102104 app. add_system_set (
103105 SystemSet :: on_enter ( NotationAssetsStates :: Loaded )
104- . with_system ( setup_window_size. system ( ) ) ,
106+ . with_system ( setup_window_size. system ( ) )
105107 ) ;
106108 app. add_system_set (
107109 SystemSet :: on_update ( NotationAssetsStates :: Loaded )
108110 . with_system ( on_window_resized. system ( ) )
109111 . with_system ( handle_inputs. system ( ) )
110- . with_system ( load_tab. system ( ) ) ,
112+ . with_system ( load_tab. system ( ) )
111113 ) ;
112114
113115 extra ( & mut app) ;
@@ -131,7 +133,7 @@ fn load_tab(
131133 assets : ResMut < Assets < TabAsset > > ,
132134 mut evts : EventWriter < AddTabEvent > ,
133135) {
134- if state. tab . is_none ( ) && state. parse_error . is_none ( ) {
136+ if state. window_width > 0.0 && state . window_height > 0.0 && state . tab . is_none ( ) && state. parse_error . is_none ( ) {
135137 if let Some ( asset) = assets. get ( & state. tab_asset ) {
136138 match Tab :: try_parse_arc ( asset. tab . clone ( ) ) {
137139 Ok ( tab) => {
@@ -148,7 +150,7 @@ fn load_tab(
148150}
149151
150152fn handle_inputs (
151- _keyboard_input : Res < Input < KeyCode > > ,
153+ mut commands : Commands ,
152154 windows : Res < Windows > ,
153155 keyboard_input : Res < Input < KeyCode > > ,
154156 mouse_input : Res < Input < MouseButton > > ,
@@ -160,6 +162,7 @@ fn handle_inputs(
160162 mut mouse_clicked : EventWriter < MouseClickedEvent > ,
161163 mut mouse_dragged : EventWriter < MouseDraggedEvent > ,
162164 mut window_resized_evts : EventWriter < WindowResizedEvent > ,
165+ viewer_query : Query < ( Entity , & Arc < NotationViewer > ) , With < Arc < NotationViewer > > > ,
163166) {
164167 if keyboard_input. pressed ( KeyCode :: LControl ) {
165168 settings. mouse_dragged_panning = true ;
@@ -174,8 +177,9 @@ fn handle_inputs(
174177 crate :: viewer:: control:: ControlView :: play_or_pause ( & mut midi_state, & mut play_control_evts) ;
175178 } else if keyboard_input. just_released ( KeyCode :: Return ) {
176179 crate :: viewer:: control:: ControlView :: play_or_stop ( & mut midi_state, & mut play_control_evts) ;
177- }
178- if mouse_input. just_released ( MouseButton :: Left ) {
180+ } else if keyboard_input. just_released ( KeyCode :: Backslash ) {
181+ crate :: viewer:: control:: ControlView :: toggle_layout_mode ( & mut commands, & mut state, & mut settings, & viewer_query) ;
182+ } else if mouse_input. just_released ( MouseButton :: Left ) {
179183 windows
180184 . get_primary ( )
181185 . and_then ( |x| x. cursor_position ( ) )
@@ -193,9 +197,19 @@ fn handle_inputs(
193197 }
194198}
195199
196- fn setup_window_size ( window : Res < WindowDescriptor > , mut app_state : ResMut < NotationAppState > ) {
197- app_state. window_width = window. width ;
198- app_state. window_height = window. height ;
200+ fn setup_window_size (
201+ window : Res < WindowDescriptor > ,
202+ mut app_state : ResMut < NotationAppState > ,
203+ ) {
204+ #[ cfg( target_arch = "wasm32" ) ]
205+ let ( width, height) = crate :: wasm:: bevy_web_fullscreen:: get_viewport_size ( ) ;
206+
207+ #[ cfg( not( target_arch = "wasm32" ) ) ]
208+ let ( width, height) = ( window. width , window. height ) ;
209+
210+ println ! ( "setup_window_size(): {} {} " , width, height) ;
211+ app_state. window_width = width;
212+ app_state. window_height = height;
199213}
200214
201215fn on_window_resized (
@@ -208,6 +222,7 @@ fn on_window_resized(
208222 if evt. width as usize != window. width as usize
209223 || evt. height as usize != window. height as usize
210224 {
225+ println ! ( "on_window_resized(): {} {} -> {} {} " , window. width, window. height, evt. width, evt. height) ;
211226 window. width = evt. width ;
212227 window. height = evt. height ;
213228 app_state. window_width = evt. width ;
0 commit comments