Skip to content

Commit

Permalink
fix(segmented_button): adjust layout and drawing to designs
Browse files Browse the repository at this point in the history
  • Loading branch information
mmstick committed Mar 8, 2024
1 parent 2d8c0a4 commit fb108e3
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/widget/segmented_button/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ where
button: Entity,
) -> (f32, f32) {
let mut width = 0.0f32;
let mut height = 0.0f32;

// Add text to measurement if text was given.
if let Some((text, entry)) = self
Expand All @@ -345,7 +344,6 @@ where

let size = paragraph.min_bounds();
width += size.width;
height += size.height;
}

// Add indent to measurement if found.
Expand All @@ -370,10 +368,8 @@ where

// Add button padding to the max size found
width += f32::from(self.button_padding[0]) + f32::from(self.button_padding[2]);
height += f32::from(self.button_padding[1]) + f32::from(self.button_padding[3]);
height = height.max(f32::from(self.button_height));

(width, height)
(width, f32::from(self.button_height))
}

pub(super) fn max_button_dimensions(
Expand Down Expand Up @@ -1074,7 +1070,6 @@ where
);

bounds.x += offset;
bounds.width -= offset;
} else {
// Draw the selection indicator if widget is a segmented selection, and the item is selected.
if key_is_active {
Expand Down Expand Up @@ -1109,7 +1104,6 @@ where
let offset = 16.0 + f32::from(self.button_spacing);

bounds.x += offset;
bounds.width -= offset;
}
}
}
Expand All @@ -1126,6 +1120,11 @@ where
0.0
};

bounds.width = original_bounds.width
- (bounds.x - original_bounds.x)
- close_icon_width
- f32::from(self.button_padding[2]);

if self.model.text(key).is_some() {
bounds.y = center_y;

Expand All @@ -1135,7 +1134,8 @@ where
bounds.position(),
apply_alpha(status_appearance.text_color),
Rectangle {
width: bounds.width - close_icon_width,
x: bounds.x,
width: bounds.width,
..original_bounds
},
);
Expand Down

0 comments on commit fb108e3

Please sign in to comment.