fix(komorebi): account for border offset and width in layout

The layout should leave the space configured for the border, so that the
border always stays within the workspace bounds.

Border offset is cleaned up, as it is no longer a rect, but instead just
a fixed value.

The rect function for adjusting padding now takes a concrete value, as
the optional has no local meaning to the operation, being equivalent to
the default value.

A margin function is added to centralize the notion of increasing the
size of a rect by the given margin, the opposite of the padding
operation.
This commit is contained in:
James Tucker
2024-02-25 11:33:23 -08:00
committed by جاد
parent dc3ffb3bcb
commit 5ee827ecaf
7 changed files with 42 additions and 57 deletions

View File

@@ -189,7 +189,7 @@ impl Arrangement for DefaultLayout {
dimensions
.iter_mut()
.for_each(|l| l.add_padding(container_padding));
.for_each(|l| l.add_padding(container_padding.unwrap_or_default()));
dimensions
}
@@ -312,7 +312,7 @@ impl Arrangement for CustomLayout {
dimensions
.iter_mut()
.for_each(|l| l.add_padding(container_padding));
.for_each(|l| l.add_padding(container_padding.unwrap_or_default()));
dimensions
}

View File

@@ -27,13 +27,20 @@ impl From<RECT> for Rect {
}
impl Rect {
pub fn add_padding(&mut self, padding: Option<i32>) {
if let Some(padding) = padding {
self.left += padding;
self.top += padding;
self.right -= padding * 2;
self.bottom -= padding * 2;
}
/// decrease the size of self by the padding amount.
pub fn add_padding(&mut self, padding: i32) {
self.left += padding;
self.top += padding;
self.right -= padding * 2;
self.bottom -= padding * 2;
}
/// increase the size of self by the margin amount.
pub fn add_margin(&mut self, margin: i32) {
self.left -= margin;
self.top -= margin;
self.right += margin * 2;
self.bottom += margin * 2;
}
#[must_use]