basic.rs (4012B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 extern crate euclid; 6 extern crate gleam; 7 extern crate glutin; 8 extern crate webrender; 9 extern crate winit; 10 11 #[path = "common/boilerplate.rs"] 12 mod boilerplate; 13 14 use crate::boilerplate::{Example, HandyDandyRectBuilder}; 15 use euclid::vec2; 16 use webrender::ShaderPrecacheFlags; 17 use webrender::api::*; 18 use webrender::render_api::*; 19 use webrender::api::units::*; 20 21 fn main() { 22 let mut app = App { 23 }; 24 boilerplate::main_wrapper(&mut app, None); 25 } 26 27 struct App { 28 } 29 30 impl Example for App { 31 // Make this the only example to test all shaders for compile errors. 32 const PRECACHE_SHADER_FLAGS: ShaderPrecacheFlags = ShaderPrecacheFlags::FULL_COMPILE; 33 34 fn render( 35 &mut self, 36 _api: &mut RenderApi, 37 builder: &mut DisplayListBuilder, 38 _txn: &mut Transaction, 39 _: DeviceIntSize, 40 pipeline_id: PipelineId, 41 _document_id: DocumentId, 42 ) { 43 let content_bounds = LayoutRect::from_size(LayoutSize::new(800.0, 600.0)); 44 let root_space_and_clip = SpaceAndClipInfo::root_scroll(pipeline_id); 45 let spatial_id = root_space_and_clip.spatial_id; 46 47 builder.push_simple_stacking_context( 48 content_bounds.min, 49 spatial_id, 50 PrimitiveFlags::IS_BACKFACE_VISIBLE, 51 ); 52 53 let complex = ComplexClipRegion::new( 54 (50, 50).to(150, 150), 55 BorderRadius::uniform(20.0), 56 ClipMode::Clip 57 ); 58 let clip_id = builder.define_clip_rounded_rect( 59 root_space_and_clip.spatial_id, 60 complex, 61 ); 62 let clip_chain_id = builder.define_clip_chain(None, [clip_id]); 63 64 builder.push_rect( 65 &CommonItemProperties::new( 66 (100, 100).to(200, 200), 67 SpaceAndClipInfo { spatial_id, clip_chain_id }, 68 ), 69 (100, 100).to(200, 200), 70 ColorF::new(0.0, 1.0, 0.0, 1.0), 71 ); 72 73 builder.push_rect( 74 &CommonItemProperties::new( 75 (250, 100).to(350, 200), 76 SpaceAndClipInfo { spatial_id, clip_chain_id }, 77 ), 78 (250, 100).to(350, 200), 79 ColorF::new(0.0, 1.0, 0.0, 1.0), 80 ); 81 let border_side = BorderSide { 82 color: ColorF::new(0.0, 0.0, 1.0, 1.0), 83 style: BorderStyle::Groove, 84 }; 85 let border_widths = LayoutSideOffsets::new_all_same(10.0); 86 let border_details = BorderDetails::Normal(NormalBorder { 87 top: border_side, 88 right: border_side, 89 bottom: border_side, 90 left: border_side, 91 radius: BorderRadius::uniform(20.0), 92 do_aa: true, 93 }); 94 95 let bounds = (100, 100).to(200, 200); 96 builder.push_border( 97 &CommonItemProperties::new( 98 bounds, 99 SpaceAndClipInfo { spatial_id, clip_chain_id }, 100 ), 101 bounds, 102 border_widths, 103 border_details, 104 ); 105 106 if false { 107 // draw box shadow? 108 let simple_box_bounds = (20, 200).by(50, 50); 109 let offset = vec2(10.0, 10.0); 110 let color = ColorF::new(1.0, 1.0, 1.0, 1.0); 111 let blur_radius = 0.0; 112 let spread_radius = 0.0; 113 let simple_border_radius = 8.0; 114 let box_shadow_type = BoxShadowClipMode::Inset; 115 116 builder.push_box_shadow( 117 &CommonItemProperties::new(content_bounds, root_space_and_clip), 118 simple_box_bounds, 119 offset, 120 color, 121 blur_radius, 122 spread_radius, 123 BorderRadius::uniform(simple_border_radius), 124 box_shadow_type, 125 ); 126 } 127 128 builder.pop_stacking_context(); 129 } 130 }