From 1dae45c58d7eabeda21ef490d712915890bf6cff Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Mon, 17 Jun 2024 09:16:28 +0300 Subject: Refactor layout to fractional-logical Lets borders, gaps, and everything else stay pixel-perfect even with fractional scale. Allows setting fractional border widths, gaps, struts. See the new wiki .md for more details. --- src/layout/opening_window.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/layout/opening_window.rs') diff --git a/src/layout/opening_window.rs b/src/layout/opening_window.rs index 38eb89ab..d265c463 100644 --- a/src/layout/opening_window.rs +++ b/src/layout/opening_window.rs @@ -55,8 +55,8 @@ impl OpenAnimation { &self, renderer: &mut GlesRenderer, elements: &[impl RenderElement], - geo_size: Size, - location: Point, + geo_size: Size, + location: Point, scale: Scale, ) -> anyhow::Result { let progress = self.anim.value(); @@ -75,17 +75,17 @@ impl OpenAnimation { let texture_size = geo.size.to_f64().to_logical(scale); if Shaders::get(renderer).program(ProgramType::Open).is_some() { - let mut area = Rectangle::from_loc_and_size(location.to_f64() + offset, texture_size); + let mut area = Rectangle::from_loc_and_size(location + offset, texture_size); // Expand the area a bit to allow for more varied effects. let mut target_size = area.size.upscale(1.5); target_size.w = f64::max(area.size.w + 1000., target_size.w); target_size.h = f64::max(area.size.h + 1000., target_size.h); - let diff = target_size.to_point() - area.size.to_point(); - area.loc -= diff.downscale(2.); - area.size += diff.to_size(); + let diff = (target_size.to_point() - area.size.to_point()).downscale(2.); + let diff = diff.to_physical_precise_round(scale).to_logical(scale); + area.loc -= diff; + area.size += diff.upscale(2.).to_size(); - let area = area.to_i32_up(); let area_loc = Vec2::new(area.loc.x as f32, area.loc.y as f32); let area_size = Vec2::new(area.size.w as f32, area.size.h as f32); @@ -135,7 +135,7 @@ impl OpenAnimation { let elem = PrimaryGpuTextureRenderElement(elem); - let center = geo_size.to_point().to_f64().downscale(2.); + let center = geo_size.to_point().downscale(2.); let elem = RescaleRenderElement::from_element( elem, (center - offset).to_physical_precise_round(scale), @@ -144,7 +144,7 @@ impl OpenAnimation { let elem = RelocateRenderElement::from_element( elem, - (location.to_f64() + offset).to_physical_precise_round(scale), + (location + offset).to_physical_precise_round(scale), Relocate::Relative, ); -- cgit