unsuccessful attempt at making the rect stay in place relative to top right while resizing

This commit is contained in:
Well 2019-07-28 01:01:21 -03:00
parent e44519a76f
commit 8b909c962a
1 changed files with 34 additions and 4 deletions

View File

@ -1,8 +1,8 @@
use euclid::rect;
use gleam::gl;
use glutin::dpi::LogicalSize;
use glutin::ControlFlow;
use webrender::api::*;
use euclid::rect;
pub fn show_window() {
let mut events_loop = glutin::EventsLoop::new();
@ -16,8 +16,7 @@ pub fn show_window() {
glutin::WindowBuilder::new()
.with_title("Test")
.with_dimensions(LogicalSize::new(800.0, 600.0))
.with_transparency(true)//on windows 10 makes everything be slightly transparent even at alpha 1.0
,
.with_transparency(true), //on windows 10 makes everything be slightly transparent even at alpha 1.0
&events_loop,
)
.expect("Error building windowed GL context");
@ -72,7 +71,11 @@ pub fn show_window() {
device_size.height as f32 / device_pixel_ratio,
);
let mut builder = DisplayListBuilder::new(pipeline_id, layout_size);
builder.push_rect(&LayoutPrimitiveInfo::new(rect(80.0, 2.0, 554., 50.)), &SpaceAndClipInfo::root_scroll(pipeline_id), ColorF::new(1., 0., 0.4, 1.));
builder.push_rect(
&LayoutPrimitiveInfo::new(rect(80.0, 2.0, 554., 50.)),
&SpaceAndClipInfo::root_scroll(pipeline_id),
ColorF::new(1., 0., 0.4, 1.),
);
let mut tsn = Transaction::new();
tsn.set_display_list(
@ -96,6 +99,33 @@ pub fn show_window() {
match win_event {
glutin::WindowEvent::CloseRequested => return ControlFlow::Break,
glutin::WindowEvent::Resized(inner_size) => {
let device_size = {
let size = inner_size.to_physical(device_pixel_ratio as f64);
DeviceIntSize::new(size.width as i32, size.height as i32)
};
let layout_size = LayoutSize::new(
device_size.width as f32 / device_pixel_ratio,
device_size.height as f32 / device_pixel_ratio,
);
let mut builder = DisplayListBuilder::new(pipeline_id, layout_size);
builder.push_rect(
&LayoutPrimitiveInfo::new(rect(80.0, 2.0, 554., 50.)),
&SpaceAndClipInfo::root_scroll(pipeline_id),
ColorF::new(1., 0., 0.4, 1.),
);
tsn.set_display_list(
epoch,
Some(background),
layout_size,
builder.finalize(),
true,
);
tsn.set_root_pipeline(pipeline_id);
tsn.generate_frame();
api.set_window_parameters(document_id, device_size, DeviceIntRect::from_size(device_size), device_pixel_ratio)
}
_ => {}
};