feat(wm): allow f32 width % for custom layouts

This commit allows users to provide an f32 value for the WidthPercentage
on the primary column of a custom layout.
This commit is contained in:
LGUG2Z
2023-06-22 08:49:38 -07:00
parent c4be0636f7
commit 087b08612d
2 changed files with 8 additions and 8 deletions
+3 -3
View File
@@ -72,7 +72,7 @@ impl CustomLayout {
} }
#[must_use] #[must_use]
pub fn primary_width_percentage(&self) -> Option<usize> { pub fn primary_width_percentage(&self) -> Option<f32> {
for column in self.iter() { for column in self.iter() {
if let Column::Primary(Option::Some(ColumnWidth::WidthPercentage(percentage))) = column if let Column::Primary(Option::Some(ColumnWidth::WidthPercentage(percentage))) = column
{ {
@@ -83,7 +83,7 @@ impl CustomLayout {
None None
} }
pub fn set_primary_width_percentage(&mut self, percentage: usize) { pub fn set_primary_width_percentage(&mut self, percentage: f32) {
for column in self.iter_mut() { for column in self.iter_mut() {
if let Column::Primary(Option::Some(ColumnWidth::WidthPercentage(current))) = column { if let Column::Primary(Option::Some(ColumnWidth::WidthPercentage(current))) = column {
*current = percentage; *current = percentage;
@@ -262,7 +262,7 @@ pub enum Column {
#[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema)] #[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema)]
pub enum ColumnWidth { pub enum ColumnWidth {
WidthPercentage(usize), WidthPercentage(f32),
} }
#[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema)] #[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema)]
+5 -5
View File
@@ -683,15 +683,15 @@ impl WindowManager {
if matches!(axis, Axis::Horizontal) { if matches!(axis, Axis::Horizontal) {
let percentage = custom let percentage = custom
.primary_width_percentage() .primary_width_percentage()
.unwrap_or(100 / custom.len()); .unwrap_or(100.0 / (custom.len() as f32));
if no_layout_rules { if no_layout_rules {
match sizing { match sizing {
Sizing::Increase => { Sizing::Increase => {
custom.set_primary_width_percentage(percentage + 5); custom.set_primary_width_percentage(percentage + 5.0);
} }
Sizing::Decrease => { Sizing::Decrease => {
custom.set_primary_width_percentage(percentage - 5); custom.set_primary_width_percentage(percentage - 5.0);
} }
} }
} else { } else {
@@ -700,10 +700,10 @@ impl WindowManager {
if let Layout::Custom(ref mut custom) = rule.1 { if let Layout::Custom(ref mut custom) = rule.1 {
match sizing { match sizing {
Sizing::Increase => { Sizing::Increase => {
custom.set_primary_width_percentage(percentage + 5); custom.set_primary_width_percentage(percentage + 5.0);
} }
Sizing::Decrease => { Sizing::Decrease => {
custom.set_primary_width_percentage(percentage - 5); custom.set_primary_width_percentage(percentage - 5.0);
} }
} }
} }