diff options
Diffstat (limited to 'third_party/webrender/examples/scrolling.rs')
-rw-r--r-- | third_party/webrender/examples/scrolling.rs | 82 |
1 files changed, 35 insertions, 47 deletions
diff --git a/third_party/webrender/examples/scrolling.rs b/third_party/webrender/examples/scrolling.rs index 034af952449..745c4f9bd34 100644 --- a/third_party/webrender/examples/scrolling.rs +++ b/third_party/webrender/examples/scrolling.rs @@ -2,11 +2,11 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -extern crate euclid; -extern crate gleam; -extern crate glutin; -extern crate webrender; -extern crate winit; +use euclid; +use gleam; +use glutin; +use webrender; +use winit; #[path = "common/boilerplate.rs"] mod boilerplate; @@ -14,17 +14,12 @@ mod boilerplate; use crate::boilerplate::{Example, HandyDandyRectBuilder}; use euclid::SideOffsets2D; use webrender::api::*; -use webrender::render_api::*; use webrender::api::units::*; use winit::dpi::LogicalPosition; -const EXT_SCROLL_ID_ROOT: u64 = 1; -const EXT_SCROLL_ID_CONTENT: u64 = 2; - struct App { cursor_position: WorldPoint, - scroll_origin: LayoutPoint, } impl Example for App { @@ -56,7 +51,7 @@ impl Example for App { // set the scrolling clip let space_and_clip1 = builder.define_scroll_frame( &root_space_and_clip, - ExternalScrollId(EXT_SCROLL_ID_ROOT, PipelineId::dummy()), + None, (0, 0).by(1000, 1000), scrollbox, ScrollSensitivity::ScriptAndInputEvents, @@ -65,22 +60,22 @@ impl Example for App { // now put some content into it. // start with a white background - let info = CommonItemProperties::new((0, 0).to(1000, 1000), space_and_clip1); - builder.push_hit_test(&info, (0, 1)); + let mut info = CommonItemProperties::new((0, 0).to(1000, 1000), space_and_clip1); + info.hit_info = Some((0, 1)); builder.push_rect(&info, info.clip_rect, ColorF::new(1.0, 1.0, 1.0, 1.0)); // let's make a 50x50 blue square as a visual reference - let info = CommonItemProperties::new((0, 0).to(50, 50), space_and_clip1); - builder.push_hit_test(&info, (0, 2)); + let mut info = CommonItemProperties::new((0, 0).to(50, 50), space_and_clip1); + info.hit_info = Some((0, 2)); builder.push_rect(&info, info.clip_rect, ColorF::new(0.0, 0.0, 1.0, 1.0)); // and a 50x50 green square next to it with an offset clip // to see what that looks like - let info = CommonItemProperties::new( + let mut info = CommonItemProperties::new( (50, 0).to(100, 50).intersection(&(60, 10).to(110, 60)).unwrap(), space_and_clip1, ); - builder.push_hit_test(&info, (0, 3)); + info.hit_info = Some((0, 3)); builder.push_rect(&info, info.clip_rect, ColorF::new(0.0, 1.0, 0.0, 1.0)); // Below the above rectangles, set up a nested scrollbox. It's still in @@ -88,7 +83,7 @@ impl Example for App { // be relative to the stacking context. let space_and_clip2 = builder.define_scroll_frame( &space_and_clip1, - ExternalScrollId(EXT_SCROLL_ID_CONTENT, PipelineId::dummy()), + None, (0, 100).to(300, 1000), (0, 100).to(200, 300), ScrollSensitivity::ScriptAndInputEvents, @@ -97,17 +92,17 @@ impl Example for App { // give it a giant gray background just to distinguish it and to easily // visually identify the nested scrollbox - let info = CommonItemProperties::new( + let mut info = CommonItemProperties::new( (-1000, -1000).to(5000, 5000), space_and_clip2, ); - builder.push_hit_test(&info, (0, 4)); + info.hit_info = Some((0, 4)); builder.push_rect(&info, info.clip_rect, ColorF::new(0.5, 0.5, 0.5, 1.0)); // add a teal square to visualize the scrolling/clipping behaviour // as you scroll the nested scrollbox - let info = CommonItemProperties::new((0, 200).to(50, 250), space_and_clip2); - builder.push_hit_test(&info, (0, 5)); + let mut info = CommonItemProperties::new((0, 200).to(50, 250), space_and_clip2); + info.hit_info = Some((0, 5)); builder.push_rect(&info, info.clip_rect, ColorF::new(0.0, 1.0, 1.0, 1.0)); // Add a sticky frame. It will "stick" twice while scrolling, once @@ -123,14 +118,14 @@ impl Example for App { LayoutVector2D::new(0.0, 0.0) ); - let info = CommonItemProperties::new( + let mut info = CommonItemProperties::new( (50, 350).by(50, 50), SpaceAndClipInfo { spatial_id: sticky_id, clip_id: space_and_clip2.clip_id, }, ); - builder.push_hit_test(&info, (0, 6)); + info.hit_info = Some((0, 6)); builder.push_rect( &info, info.clip_rect, @@ -139,11 +134,11 @@ impl Example for App { // just for good measure add another teal square further down and to // the right, which can be scrolled into view by the user - let info = CommonItemProperties::new( + let mut info = CommonItemProperties::new( (250, 350).to(300, 400), space_and_clip2, ); - builder.push_hit_test(&info, (0, 7)); + info.hit_info = Some((0, 7)); builder.push_rect(&info, info.clip_rect, ColorF::new(0.0, 1.0, 1.0, 1.0)); builder.pop_stacking_context(); @@ -164,10 +159,10 @@ impl Example for App { .. } => { let offset = match key { - winit::VirtualKeyCode::Down => Some(LayoutVector2D::new(0.0, -10.0)), - winit::VirtualKeyCode::Up => Some(LayoutVector2D::new(0.0, 10.0)), - winit::VirtualKeyCode::Right => Some(LayoutVector2D::new(-10.0, 0.0)), - winit::VirtualKeyCode::Left => Some(LayoutVector2D::new(10.0, 0.0)), + winit::VirtualKeyCode::Down => Some((0.0, -10.0)), + winit::VirtualKeyCode::Up => Some((0.0, 10.0)), + winit::VirtualKeyCode::Right => Some((-10.0, 0.0)), + winit::VirtualKeyCode::Left => Some((10.0, 0.0)), _ => None, }; let zoom = match key { @@ -178,18 +173,15 @@ impl Example for App { }; if let Some(offset) = offset { - self.scroll_origin += offset; - - txn.scroll_node_with_id( - self.scroll_origin, - ExternalScrollId(EXT_SCROLL_ID_CONTENT, PipelineId::dummy()), - ScrollClamping::ToContentBounds, + txn.scroll( + ScrollLocation::Delta(LayoutVector2D::new(offset.0, offset.1)), + self.cursor_position, ); - txn.generate_frame(0); + txn.generate_frame(); } if let Some(zoom) = zoom { txn.set_pinch_zoom(ZoomFactor::new(zoom)); - txn.generate_frame(0); + txn.generate_frame(); } } winit::WindowEvent::CursorMoved { position: LogicalPosition { x, y }, .. } => { @@ -202,21 +194,18 @@ impl Example for App { winit::MouseScrollDelta::PixelDelta(pos) => (pos.x as f32, pos.y as f32), }; - self.scroll_origin += LayoutVector2D::new(dx, dy); - - txn.scroll_node_with_id( - self.scroll_origin, - ExternalScrollId(EXT_SCROLL_ID_CONTENT, PipelineId::dummy()), - ScrollClamping::ToContentBounds, + txn.scroll( + ScrollLocation::Delta(LayoutVector2D::new(dx, dy)), + self.cursor_position, ); - - txn.generate_frame(0); + txn.generate_frame(); } winit::WindowEvent::MouseInput { .. } => { let results = api.hit_test( document_id, None, self.cursor_position, + HitTestFlags::FIND_ALL ); println!("Hit test results:"); @@ -237,7 +226,6 @@ impl Example for App { fn main() { let mut app = App { cursor_position: WorldPoint::zero(), - scroll_origin: LayoutPoint::zero(), }; boilerplate::main_wrapper(&mut app, None); } |