From 790d6687311174f2bae4ce05dde9b24a1c65753c Mon Sep 17 00:00:00 2001 From: Danilo Guanabara Date: Wed, 17 Jun 2020 18:17:50 -0300 Subject: [PATCH] Fixing IDE layout by taking into consideration the new scene origin (https://github.com/enso-org/ide/pull/573) Original commit: https://github.com/enso-org/ide/commit/7038d2702fe209dc6f1e34726d501ab957cc2c31 --- gui/src/rust/ensogl/src/control/io/mouse.rs | 5 +++- .../src/display/navigation/navigator.rs | 6 +---- .../display/navigation/navigator/events.rs | 4 +-- gui/src/rust/ide/src/view/layout.rs | 27 ++++++++++--------- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/gui/src/rust/ensogl/src/control/io/mouse.rs b/gui/src/rust/ensogl/src/control/io/mouse.rs index a7f5073b5fa..58ca7769b64 100644 --- a/gui/src/rust/ensogl/src/control/io/mouse.rs +++ b/gui/src/rust/ensogl/src/control/io/mouse.rs @@ -140,8 +140,11 @@ pub struct MouseFrpCallbackHandles { /// Bind FRP graph to MouseManager. pub fn bind_frp_to_mouse(frp:&enso_frp::io::Mouse, mouse_manager:&MouseManager) -> MouseFrpCallbackHandles { + let dom_shape = mouse_manager.dom.clone_ref().shape(); let on_move = enclose!((frp.position => frp) move |e:&OnMove| { - frp.emit(Vector2(e.client_x() as f32,e.client_y() as f32)); + let position = Vector2(e.client_x() as f32,e.client_y() as f32); + let position = position - Vector2(dom_shape.width,dom_shape.height) / 2.0; + frp.emit(position); }); let on_down = enclose!((frp.down => frp) move |_:&OnDown | frp.emit(())); let on_up = enclose!((frp.up => frp) move |_:&OnUp | frp.emit(())); diff --git a/gui/src/rust/ensogl/src/display/navigation/navigator.rs b/gui/src/rust/ensogl/src/display/navigation/navigator.rs index 87c59814375..2e0b79556f8 100644 --- a/gui/src/rust/ensogl/src/display/navigation/navigator.rs +++ b/gui/src/rust/ensogl/src/display/navigation/navigator.rs @@ -62,11 +62,7 @@ impl Navigator { let distance_to_show_full_ui = dom.shape().height / 2.0 / fovy_slope; let movement_scale_for_distance = distance / distance_to_show_full_ui; - // FIXME: Adding - here as panning was accidentally inverted by some recent changes. - // Issue tracked by wdanilo and notdanilo. - let dx = - pan.movement.x * movement_scale_for_distance; - let dy = - pan.movement.y * movement_scale_for_distance; - let diff = Vector3::new(dx,dy,0.0); + let diff = Vector3::new(pan.movement.x,pan.movement.y,0.0)*movement_scale_for_distance; simulator.update_target_value(|p| p - diff); }); diff --git a/gui/src/rust/ensogl/src/display/navigation/navigator/events.rs b/gui/src/rust/ensogl/src/display/navigation/navigator/events.rs index 5ad0254751c..8c10d43a73f 100644 --- a/gui/src/rust/ensogl/src/display/navigation/navigator/events.rs +++ b/gui/src/rust/ensogl/src/display/navigation/navigator/events.rs @@ -232,8 +232,8 @@ impl NavigatorEvents { let zoom_event = ZoomEvent::new(position,amount,zoom_speed); data.on_zoom(zoom_event); } else { - let x = event.delta_x() as f32; - let y = -event.delta_y() as f32; + let x = -event.delta_x() as f32; + let y = event.delta_y() as f32; let movement = Vector2::new(x,y); let pan_event = PanEvent::new(movement); data.on_pan(pan_event); diff --git a/gui/src/rust/ide/src/view/layout.rs b/gui/src/rust/ide/src/view/layout.rs index 7e41d193ef0..4ca99197eb9 100644 --- a/gui/src/rust/ide/src/view/layout.rs +++ b/gui/src/rust/ide/src/view/layout.rs @@ -10,11 +10,11 @@ use crate::view::node_editor::NodeEditor; use crate::view::node_searcher::NodeSearcher; use enso_callback as callback; -use enso_frp::io::keyboard; +use enso_frp as frp; +use frp::io::keyboard; use ensogl::application::Application; use ensogl::display::shape::text::glyph::font; use ensogl::display::traits::*; -use ensogl::display::Uniform; use ensogl::display::world::World; use nalgebra::Vector2; use nalgebra::zero; @@ -32,14 +32,13 @@ shared! { ViewLayout /// Initial implementation of ViewLayout with a TextEditor and NodeEditor. #[derive(Debug)] pub struct ViewLayoutData { + network : frp::Network, + mouse_position_sampler : frp::Sampler>, text_editor : TextEditor, node_editor : NodeEditor, node_searcher : NodeSearcher, size : Vector2, logger : Logger, - /// FIXME[dg]: This is a provisional code. Getting the mouse position from Uniform is bad. Mouse - /// position should be retrieved from the frp network instead. - mouse_position : Uniform>, node_searcher_show_action : Option } @@ -65,7 +64,7 @@ impl ViewLayoutData { fn update_text_editor(&mut self) { let screen_size = self.size; - let position = Vector2::new(0.0,screen_size.y / 2.0); + let position = Vector2::new(-screen_size.x / 2.0,0.0); let size = Vector2::new(screen_size.x,screen_size.y / 2.0); let padding = TemporaryPadding { left : 10.0, @@ -80,7 +79,7 @@ impl ViewLayoutData { fn update_graph_editor(&mut self) { let screen_size = self.size; - let position = Vector3::new(50.0, screen_size.y * 3.0 / 4.0, 0.0); + let position = Vector3::new(50.0 - screen_size.x / 2.0, screen_size.y / 4.0, 0.0); self.node_editor.set_position(position); } @@ -112,11 +111,13 @@ impl ViewLayout { world.add_child(&text_editor.display_object()); world.add_child(&node_editor); world.add_child(&node_searcher); - let size = zero(); - let mouse_position = world.scene().mouse.position.clone_ref(); + let size = zero(); + let scene = world.scene(); + let mouse = &scene.mouse.frp; + frp::new_network! { network def mouse_position_sampler = mouse.position.sampler(); } let node_searcher_show_action = None; - let data = ViewLayoutData{text_editor,node_editor,node_searcher,size,logger,mouse_position, - node_searcher_show_action}; + let data = ViewLayoutData{network,text_editor,node_editor,node_searcher,size,logger, + node_searcher_show_action,mouse_position_sampler}; let rc = Rc::new(RefCell::new(data)); Ok(Self {rc}.init(world,kb_actions)) } @@ -127,9 +128,9 @@ impl ViewLayout { let keys = &[keyboard::Key::Tab]; let node_searcher_show_action = keyboard_actions.add_action(keys, move || { let mut layout = layout.borrow_mut(); - let position = layout.mouse_position.get(); + let position = *layout.mouse_position_sampler.value(); //TODO[dg]: Test it when graph scene panning is working. - let node_searcher_position = Vector3::new(position.x as f32,position.y as f32,0.0); + let node_searcher_position = Vector3::new(position.x,position.y,0.0); layout.node_searcher.set_position(node_searcher_position); layout.node_searcher.show(); });