From dacfd70fb4390b52b04dd66dcb562db4e13e49e8 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Tue, 20 Jun 2023 15:46:30 -0700 Subject: [PATCH] Remove unescessary enum --- crates/context_menu/src/context_menu.rs | 22 +++---------------- crates/theme/src/theme.rs | 29 ++++++------------------- crates/workspace/src/dock.rs | 9 ++------ 3 files changed, 12 insertions(+), 48 deletions(-) diff --git a/crates/context_menu/src/context_menu.rs b/crates/context_menu/src/context_menu.rs index e140177c5c..de78b51e9c 100644 --- a/crates/context_menu/src/context_menu.rs +++ b/crates/context_menu/src/context_menu.rs @@ -9,7 +9,6 @@ use gpui::{ }; use menu::*; use std::{any::TypeId, borrow::Cow, sync::Arc, time::Duration}; -use theme::ToggleState; pub fn init(cx: &mut AppContext) { cx.add_action(ContextMenu::select_first); @@ -329,12 +328,7 @@ impl ContextMenu { Flex::column().with_children(self.items.iter().enumerate().map(|(ix, item)| { match item { ContextMenuItem::Item { label, .. } => { - let toggle_state = if Some(ix) == self.selected_index { - ToggleState::Active - } else { - ToggleState::Inactive - }; - let style = style.item.in_state(toggle_state); + let style = style.item.in_state(self.selected_index == Some(ix)); let style = style.style_for(&mut Default::default()); match label { @@ -367,12 +361,7 @@ impl ContextMenu { .with_children(self.items.iter().enumerate().map(|(ix, item)| { match item { ContextMenuItem::Item { action, .. } => { - let toggle_state = if Some(ix) == self.selected_index { - ToggleState::Active - } else { - ToggleState::Inactive - }; - let style = style.item.in_state(toggle_state); + let style = style.item.in_state(self.selected_index == Some(ix)); let style = style.style_for(&mut Default::default()); match action { @@ -419,12 +408,7 @@ impl ContextMenu { let action = action.clone(); let view_id = self.parent_view_id; MouseEventHandler::::new(ix, cx, |state, _| { - let toggle_state = if Some(ix) == self.selected_index { - ToggleState::Active - } else { - ToggleState::Inactive - }; - let style = style.item.in_state(toggle_state); + let style = style.item.in_state(self.selected_index == Some(ix)); let style = style.style_for(state); let keystroke = match &action { ContextMenuItemAction::Action(action) => Some( diff --git a/crates/theme/src/theme.rs b/crates/theme/src/theme.rs index 8f9f228129..586f444ebb 100644 --- a/crates/theme/src/theme.rs +++ b/crates/theme/src/theme.rs @@ -816,37 +816,22 @@ pub struct Toggleable { inactive: T, } -#[derive(Copy, Clone, Debug, Default, Hash, PartialEq, Eq)] -pub enum ToggleState { - #[default] - Inactive, - Active, -} - -impl> From for ToggleState { - fn from(item: T) -> Self { - match *item.borrow() { - true => Self::Active, - false => Self::Inactive, - } - } -} - impl Toggleable { pub fn new(active: T, inactive: T) -> Self { Self { active, inactive } } - pub fn in_state(&self, state: impl Into) -> &T { - match state.into() { - ToggleState::Inactive => &self.inactive, - ToggleState::Active => &self.active, + pub fn in_state(&self, active: bool) -> &T { + if active { + &self.inactive + } else { + &self.active } } pub fn active_state(&self) -> &T { - self.in_state(ToggleState::Active) + self.in_state(true) } pub fn inactive_state(&self) -> &T { - self.in_state(ToggleState::Inactive) + self.in_state(false) } } diff --git a/crates/workspace/src/dock.rs b/crates/workspace/src/dock.rs index ec00ddece8..9d23c6aca4 100644 --- a/crates/workspace/src/dock.rs +++ b/crates/workspace/src/dock.rs @@ -6,7 +6,7 @@ use gpui::{ }; use serde::Deserialize; use std::rc::Rc; -use theme::{ThemeSettings, ToggleState}; +use theme::ThemeSettings; pub trait Panel: View { fn position(&self, cx: &WindowContext) -> DockPosition; @@ -498,12 +498,7 @@ impl View for PanelButtons { Stack::new() .with_child( MouseEventHandler::::new(panel_ix, cx, |state, cx| { - let toggle_state = if is_active { - ToggleState::Active - } else { - ToggleState::Inactive - }; - let style = button_style.in_state(toggle_state); + let style = button_style.in_state(is_active); let style = style.style_for(state); Flex::row()