From 26a7e6b0f9a6b1a3f7aa455766b3eac60af00ff7 Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Fri, 8 Mar 2024 14:15:12 +0100 Subject: [PATCH] fix(segmented_button): invalid tab offset when width is reduced by nav bar --- src/widget/segmented_button/horizontal.rs | 5 ++++- src/widget/tab_bar.rs | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/widget/segmented_button/horizontal.rs b/src/widget/segmented_button/horizontal.rs index d8c8daa7..d62a183b 100644 --- a/src/widget/segmented_button/horizontal.rs +++ b/src/widget/segmented_button/horizontal.rs @@ -119,11 +119,12 @@ where let spacing = f32::from(self.spacing); let size; + let mut reduce_button_offset = false; if state.known_length != num { if state.known_length > num { state.buttons_offset -= state.buttons_offset.min(state.known_length - num); } else { - state.buttons_offset += num - state.known_length; + reduce_button_offset = true; } state.known_length = num; @@ -203,6 +204,8 @@ where if !state.collapsed { state.buttons_offset = 0; + } else if reduce_button_offset { + state.buttons_offset = num - state.buttons_visible; } size diff --git a/src/widget/tab_bar.rs b/src/widget/tab_bar.rs index 8929d48d..bcbb14d7 100644 --- a/src/widget/tab_bar.rs +++ b/src/widget/tab_bar.rs @@ -25,6 +25,8 @@ where let space_xs = theme.cosmic().space_xs(); segmented_button::horizontal(model) + .minimum_button_width(76) + .maximum_button_width(250) .button_height(44) .button_padding([space_s, space_xs, space_s, space_xs]) .style(crate::theme::SegmentedButton::TabBar)