From ff9438c5ba11e54cadcc7b2646bd9884518e611e Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Mon, 26 Feb 2024 16:26:33 +0100 Subject: [PATCH] refactor!(widget): rename `view_switcher` to `tab_bar` to match Figma docs --- src/theme/style/segmented_button.rs | 14 +++++++------- src/widget/mod.rs | 6 ++---- src/widget/nav_bar.rs | 2 +- src/widget/segmented_button/horizontal.rs | 4 ++-- src/widget/{view_switcher.rs => tab_bar.rs} | 4 ++-- 5 files changed, 14 insertions(+), 16 deletions(-) rename src/widget/{view_switcher.rs => tab_bar.rs} (93%) diff --git a/src/theme/style/segmented_button.rs b/src/theme/style/segmented_button.rs index bb0afa1b..170db8fc 100644 --- a/src/theme/style/segmented_button.rs +++ b/src/theme/style/segmented_button.rs @@ -11,7 +11,7 @@ use iced_core::{border::Radius, Background}; pub enum SegmentedButton { /// A tabbed widget for switching between views in an interface. #[default] - ViewSwitcher, + TabBar, /// A widget for multiple choice selection. Control, /// Or implement any custom theme of your liking. @@ -24,9 +24,9 @@ impl StyleSheet for Theme { #[allow(clippy::too_many_lines)] fn horizontal(&self, style: &Self::Style) -> Appearance { match style { - SegmentedButton::ViewSwitcher => { + SegmentedButton::TabBar => { let cosmic = self.cosmic(); - let active = horizontal::view_switcher_active(cosmic); + let active = horizontal::tab_bar_active(cosmic); Appearance { border_radius: cosmic.corner_radii.radius_0.into(), inactive: ItemStatusAppearance { @@ -95,8 +95,8 @@ impl StyleSheet for Theme { let rad_m = cosmic.corner_radii.radius_m; let rad_0 = cosmic.corner_radii.radius_0; match style { - SegmentedButton::ViewSwitcher => { - let active = vertical::view_switcher_active(cosmic); + SegmentedButton::TabBar => { + let active = vertical::tab_bar_active(cosmic); Appearance { border_radius: cosmic.corner_radii.radius_0.into(), inactive: ItemStatusAppearance { @@ -170,7 +170,7 @@ mod horizontal { } } - pub fn view_switcher_active(cosmic: &cosmic_theme::Theme) -> ItemStatusAppearance { + pub fn tab_bar_active(cosmic: &cosmic_theme::Theme) -> ItemStatusAppearance { let mut neutral_5 = cosmic.palette.neutral_5; neutral_5.alpha = 0.2; let rad_s = cosmic.corner_radii.radius_s; @@ -246,7 +246,7 @@ mod vertical { } } - pub fn view_switcher_active(cosmic: &cosmic_theme::Theme) -> ItemStatusAppearance { + pub fn tab_bar_active(cosmic: &cosmic_theme::Theme) -> ItemStatusAppearance { let mut neutral_5 = cosmic.palette.neutral_5; neutral_5.alpha = 0.2; ItemStatusAppearance { diff --git a/src/widget/mod.rs b/src/widget/mod.rs index ca8e3360..490344d0 100644 --- a/src/widget/mod.rs +++ b/src/widget/mod.rs @@ -173,6 +173,8 @@ pub mod settings; pub mod spin_button; pub use spin_button::{spin_button, SpinButton}; +pub mod tab_bar; + pub mod text; pub use text::{text, Text}; @@ -206,9 +208,5 @@ pub mod tooltip { } } -pub mod view_switcher; -pub use view_switcher::horizontal as horiontal_view_switcher; -pub use view_switcher::vertical as vertical_view_switcher; - pub mod warning; pub use warning::*; diff --git a/src/widget/nav_bar.rs b/src/widget/nav_bar.rs index 096dd55c..d5e2be0b 100644 --- a/src/widget/nav_bar.rs +++ b/src/widget/nav_bar.rs @@ -38,7 +38,7 @@ where .button_spacing(space_xxs) .spacing(space_xxs) .on_activate(on_activate) - .style(crate::theme::SegmentedButton::ViewSwitcher) + .style(crate::theme::SegmentedButton::TabBar) .apply(scrollable) .height(Length::Fill) .apply(container) diff --git a/src/widget/segmented_button/horizontal.rs b/src/widget/segmented_button/horizontal.rs index ac662b7a..c6241c16 100644 --- a/src/widget/segmented_button/horizontal.rs +++ b/src/widget/segmented_button/horizontal.rs @@ -65,7 +65,7 @@ where / num as f32; } - let segmented_selection = matches!(self.style, crate::theme::SegmentedButton::Control); + let segmetned_control = matches!(self.style, crate::theme::SegmentedButton::Control); Box::new( self.model @@ -91,7 +91,7 @@ where let button_bounds = ItemBounds::Button(key, layout_bounds); let mut divider = None; - if self.dividers && segmented_selection && nth + 1 < num { + if self.dividers && segmetned_control && nth + 1 < num { divider = Some(ItemBounds::Divider(Rectangle { width: 1.0, ..bounds diff --git a/src/widget/view_switcher.rs b/src/widget/tab_bar.rs similarity index 93% rename from src/widget/view_switcher.rs rename to src/widget/tab_bar.rs index 5a7d3c07..8c9c55b7 100644 --- a/src/widget/view_switcher.rs +++ b/src/widget/tab_bar.rs @@ -27,7 +27,7 @@ where segmented_button::horizontal(model) .button_height(44) .button_padding([space_s, space_xs, space_s, space_xs]) - .style(crate::theme::SegmentedButton::ViewSwitcher) + .style(crate::theme::SegmentedButton::TabBar) .font_active(Some(crate::font::FONT_SEMIBOLD)) } @@ -49,6 +49,6 @@ where SegmentedButton::new(model) .button_height(44) .button_padding([space_s, space_xs, space_s, space_xs]) - .style(crate::theme::SegmentedButton::ViewSwitcher) + .style(crate::theme::SegmentedButton::TabBar) .font_active(Some(crate::font::FONT_SEMIBOLD)) }