-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add more specific margin capabilities #196
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] | ||
#[serde(untagged)] | ||
pub enum Margins { | ||
Int(u32), | ||
Vec(Vec<u32>), | ||
} // format: [top, right, bottom, left] as per HTML | ||
|
||
impl Margins { | ||
pub fn left(self) -> i32 { | ||
self.into_vec()[3] as i32 | ||
} | ||
pub fn right(self) -> i32 { | ||
self.into_vec()[1] as i32 | ||
} | ||
pub fn top(self) -> i32 { | ||
self.into_vec()[0] as i32 | ||
} | ||
pub fn bottom(self) -> i32 { | ||
self.into_vec()[2] as i32 | ||
} | ||
|
||
pub fn into_vec(self) -> Vec<u32> { | ||
match self { | ||
Self::Vec(v) => match v.len() { | ||
1 => vec![v[0], v[0], v[0], v[0]], | ||
2 => vec![v[0], v[0], v[1], v[1]], | ||
3 => vec![v[0], v[1], v[2], v[2]], | ||
4 => v, | ||
0 => { | ||
log::error!("Empty margin or border array"); | ||
vec![10, 10, 10, 10] //assume 5 px borders for now | ||
} | ||
_ => { | ||
log::error!("Too many entries in margin or border array"); | ||
vec![v[0], v[1], v[2], v[3]] //assume later entries are invalid | ||
} | ||
}, | ||
Self::Int(x) => vec![x, x, x, x], | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
use super::WindowState; | ||
use super::WindowType; | ||
use crate::config::ThemeSetting; | ||
use crate::models::Margins; | ||
use crate::models::TagId; | ||
use crate::models::XYHWBuilder; | ||
use crate::models::XYHW; | ||
|
@@ -28,7 +29,7 @@ pub struct Window { | |
pub type_: WindowType, | ||
pub tags: Vec<TagId>, | ||
pub border: i32, | ||
pub margin: i32, | ||
pub margin: Margins, | ||
states: Vec<WindowState>, | ||
pub normal: XYHW, | ||
pub start_loc: Option<XYHW>, | ||
|
@@ -48,7 +49,7 @@ impl Window { | |
type_: WindowType::Normal, | ||
tags: Vec::new(), | ||
border: 1, | ||
margin: 10, | ||
margin: Margins::Int(10), | ||
states: vec![], | ||
normal: XYHWBuilder::default().into(), | ||
floating: None, | ||
|
@@ -59,10 +60,10 @@ impl Window { | |
|
||
pub fn update_for_theme(&mut self, theme: &ThemeSetting) { | ||
if self.type_ == WindowType::Normal { | ||
self.margin = theme.margin as i32; | ||
self.border = theme.border_width as i32; | ||
self.margin = theme.margin.clone(); | ||
self.border = theme.border_width; | ||
} else { | ||
self.margin = 0; | ||
self.margin = Margins::Int(0); | ||
self.border = 0; | ||
} | ||
} | ||
|
@@ -147,9 +148,13 @@ impl Window { | |
value = self.normal.w(); | ||
} else if self.floating() && self.floating.is_some() { | ||
let relative = self.normal + self.floating.unwrap(); | ||
value = relative.w() - (self.margin * 2) - (self.border * 2); | ||
value = relative.w() | ||
- (self.margin.clone().left() + self.margin.clone().right()) | ||
- (self.border * 2); | ||
} else { | ||
value = self.normal.w() - (self.margin * 2) - (self.border * 2); | ||
value = self.normal.w() | ||
- (self.margin.clone().left() + self.margin.clone().right()) | ||
- (self.border * 2); | ||
} | ||
if value < 100 && self.type_ != WindowType::Dock { | ||
value = 100 | ||
|
@@ -162,9 +167,13 @@ impl Window { | |
value = self.normal.h(); | ||
} else if self.floating() && self.floating.is_some() { | ||
let relative = self.normal + self.floating.unwrap(); | ||
value = relative.h() - (self.margin * 2) - (self.border * 2); | ||
value = relative.h() | ||
- (self.margin.clone().top() + self.margin.clone().bottom()) | ||
- (self.border * 2); | ||
} else { | ||
value = self.normal.h() - (self.margin * 2) - (self.border * 2); | ||
value = self.normal.h() | ||
- (self.margin.clone().top() + self.margin.clone().bottom()) | ||
- (self.border * 2); | ||
} | ||
if value < 100 && self.type_ != WindowType::Dock { | ||
value = 100 | ||
|
@@ -193,9 +202,9 @@ impl Window { | |
} | ||
if self.floating() && self.floating.is_some() { | ||
let relative = self.normal + self.floating.unwrap(); | ||
relative.x() + self.margin | ||
relative.x() + self.margin.clone().left() | ||
} else { | ||
self.normal.x() + self.margin | ||
self.normal.x() + self.margin.clone().left() | ||
} | ||
} | ||
|
||
|
@@ -205,9 +214,9 @@ impl Window { | |
} | ||
if self.floating() && self.floating.is_some() { | ||
let relative = self.normal + self.floating.unwrap(); | ||
relative.y() + self.margin | ||
relative.y() + self.margin.clone().bottom() | ||
} else { | ||
self.normal.y() + self.margin | ||
self.normal.y() + self.margin.clone().bottom() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. another question if I may: why are you using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that you mention it, that’s probably right. This might be an artifact from when I was confused and had the HTML top/bottom/ left/right specs backwards. Should probably check over and see if the behaviour is what we’re expecting it to be. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as I am just about to get a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That sounds great! Thanks for reviewing that. I wonder if it's partially related to #248 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Gonna look into this tomorrow, now it's bedtime. Gn8 |
||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mautamu or @lex148: may I ask, why you apply a margin to a floating window?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m not sure exactly why it’s applied. Can try running it without and see what happens.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might test myself as well. Was just curious if there was some reasoning behind that.