From 36b28d9b96107441e3f8502a61f598fb666ec492 Mon Sep 17 00:00:00 2001 From: Martino Ferrari Date: Sat, 1 Mar 2025 18:46:27 +0100 Subject: Added top, left, bottom and right floating windows alignement (#1169) * feat: added top, left, bottom, right alignement options * feat: implemented extra alignement * feat: added example * doc: updated documentation with extra alignements * doc: moved example in wiki and typo correction * fix: relative position should be positive and not negative * fixes --------- Co-authored-by: Martino Ferrari Co-authored-by: Ivan Molodetskikh --- src/layout/floating.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/layout/floating.rs b/src/layout/floating.rs index 2a4054bd..4fd7c7ee 100644 --- a/src/layout/floating.rs +++ b/src/layout/floating.rs @@ -1206,12 +1206,24 @@ impl FloatingSpace { let area = self.working_area; let mut pos = Point::from((pos.x.0, pos.y.0)); - if relative_to == RelativeTo::TopRight || relative_to == RelativeTo::BottomRight { + if relative_to == RelativeTo::TopRight + || relative_to == RelativeTo::BottomRight + || relative_to == RelativeTo::Right + { pos.x = area.size.w - size.w - pos.x; } - if relative_to == RelativeTo::BottomLeft || relative_to == RelativeTo::BottomRight { + if relative_to == RelativeTo::BottomLeft + || relative_to == RelativeTo::BottomRight + || relative_to == RelativeTo::Bottom + { pos.y = area.size.h - size.h - pos.y; } + if relative_to == RelativeTo::Top || relative_to == RelativeTo::Bottom { + pos.x += area.size.w / 2.0 - size.w / 2.0 + } + if relative_to == RelativeTo::Left || relative_to == RelativeTo::Right { + pos.y += area.size.h / 2.0 - size.h / 2.0 + } pos + self.working_area.loc }) -- cgit