/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#[path = "common/boilerplate.rs"] mod boilerplate;
usecrate::boilerplate::{Example, HandyDandyRectBuilder}; use euclid::SideOffsets2D; use webrender::api::*; use webrender::render_api::*; use webrender::api::units::*; use winit::dpi::LogicalPosition;
iftrue { // scrolling and clips stuff // let's make a scrollbox let scrollbox = (0, 0).to(300, 400);
builder.push_simple_stacking_context(
root_space_and_clip.spatial_id,
PrimitiveFlags::IS_BACKFACE_VISIBLE,
); // set the scrolling clip let space1 = builder.define_scroll_frame(
root_space_and_clip.spatial_id,
ExternalScrollId(EXT_SCROLL_ID_ROOT, PipelineId::dummy()),
(0, 0).by(1000, 1000),
scrollbox,
LayoutVector2D::zero(),
APZScrollGeneration::default(),
HasScrollLinkedEffect::No,
); let space_and_clip1 = SpaceAndClipInfo {
spatial_id: space1,
clip_chain_id: root_space_and_clip.clip_chain_id,
};
// 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.clip_rect,
ClipChainId::INVALID,
info.spatial_id,
info.flags,
(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.clip_rect,
ClipChainId::INVALID,
info.spatial_id,
info.flags,
(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(
(50, 0).to(100, 50).intersection(&(60, 10).to(110, 60)).unwrap(),
space_and_clip1,
);
builder.push_hit_test(
info.clip_rect,
ClipChainId::INVALID,
info.spatial_id,
info.flags,
(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 // the same stacking context, so note that the rects passed in need to // be relative to the stacking context. let space2 = builder.define_scroll_frame(
space1,
ExternalScrollId(EXT_SCROLL_ID_CONTENT, PipelineId::dummy()),
(0, 100).to(300, 1000),
(0, 100).to(200, 300),
LayoutVector2D::zero(),
APZScrollGeneration::default(),
HasScrollLinkedEffect::No,
); let space_and_clip2 = SpaceAndClipInfo {
spatial_id: space2,
clip_chain_id: root_space_and_clip.clip_chain_id,
};
// give it a giant gray background just to distinguish it and to easily // visually identify the nested scrollbox let info = CommonItemProperties::new(
(-1000, -1000).to(5000, 5000),
space_and_clip2,
);
builder.push_hit_test(
info.clip_rect,
ClipChainId::INVALID,
info.spatial_id,
info.flags,
(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.clip_rect,
ClipChainId::INVALID,
info.spatial_id,
info.flags,
(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 // at a margin of 10px from the bottom, for 40 pixels of scrolling, // and once at a margin of 10px from the top, for 60 pixels of // scrolling. let sticky_id = builder.define_sticky_frame(
space_and_clip2.spatial_id,
(50, 350).by(50, 50),
SideOffsets2D::new(Some(10.0), None, Some(10.0), None),
StickyOffsetBounds::new(-40.0, 60.0),
StickyOffsetBounds::new(0.0, 0.0),
LayoutVector2D::new(0.0, 0.0),
None,
);
// 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(
(250, 350).to(300, 400),
space_and_clip2,
);
builder.push_hit_test(
info.clip_rect,
ClipChainId::INVALID,
info.spatial_id,
info.flags,
(0, 7)
);
builder.push_rect(&info, info.clip_rect, ColorF::new(0.0, 1.0, 1.0, 1.0));
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.