Rename on/off states to active/inactive

This commit is contained in:
Piotr Osiewicz 2023-06-14 15:12:38 +02:00 committed by Mikayla Maki
parent e92015b12f
commit 0256f89dd6
No known key found for this signature in database
10 changed files with 47 additions and 36 deletions

View file

@ -299,7 +299,12 @@ impl CollabTitlebarItem {
pub fn toggle_user_menu(&mut self, _: &ToggleUserMenu, cx: &mut ViewContext<Self>) { pub fn toggle_user_menu(&mut self, _: &ToggleUserMenu, cx: &mut ViewContext<Self>) {
let theme = theme::current(cx).clone(); let theme = theme::current(cx).clone();
let avatar_style = theme.workspace.titlebar.leader_avatar.clone(); let avatar_style = theme.workspace.titlebar.leader_avatar.clone();
let item_style = theme.context_menu.item.off_state().disabled_style().clone(); let item_style = theme
.context_menu
.item
.inactive_state()
.disabled_style()
.clone();
self.user_menu.update(cx, |user_menu, cx| { self.user_menu.update(cx, |user_menu, cx| {
let items = if let Some(user) = self.user_store.read(cx).current_user() { let items = if let Some(user) = self.user_store.read(cx).current_user() {
vec![ vec![
@ -364,14 +369,14 @@ impl CollabTitlebarItem {
.with_margin_left( .with_margin_left(
titlebar titlebar
.toggle_contacts_button .toggle_contacts_button
.off_state() .inactive_state()
.default .default
.icon_width, .icon_width,
) )
.with_margin_top( .with_margin_top(
titlebar titlebar
.toggle_contacts_button .toggle_contacts_button
.off_state() .inactive_state()
.default .default
.icon_width, .icon_width,
) )

View file

@ -798,7 +798,7 @@ impl ContactList {
.width .width
.or(theme.contact_avatar.height) .or(theme.contact_avatar.height)
.unwrap_or(0.); .unwrap_or(0.);
let row = &theme.project_row.off_state().default; let row = &theme.project_row.inactive_state().default;
let tree_branch = theme.tree_branch; let tree_branch = theme.tree_branch;
let line_height = row.name.text.line_height(font_cache); let line_height = row.name.text.line_height(font_cache);
let cap_height = row.name.text.cap_height(font_cache); let cap_height = row.name.text.cap_height(font_cache);
@ -897,7 +897,7 @@ impl ContactList {
.width .width
.or(theme.contact_avatar.height) .or(theme.contact_avatar.height)
.unwrap_or(0.); .unwrap_or(0.);
let row = &theme.project_row.off_state().default; let row = &theme.project_row.inactive_state().default;
let tree_branch = theme.tree_branch; let tree_branch = theme.tree_branch;
let line_height = row.name.text.line_height(font_cache); let line_height = row.name.text.line_height(font_cache);
let cap_height = row.name.text.cap_height(font_cache); let cap_height = row.name.text.cap_height(font_cache);

View file

@ -330,9 +330,9 @@ impl ContextMenu {
match item { match item {
ContextMenuItem::Item { label, .. } => { ContextMenuItem::Item { label, .. } => {
let toggle_state = if Some(ix) == self.selected_index { let toggle_state = if Some(ix) == self.selected_index {
ToggleState::On ToggleState::Active
} else { } else {
ToggleState::Off ToggleState::Inactive
}; };
let style = style.item.in_state(toggle_state); let style = style.item.in_state(toggle_state);
let style = style.style_for(&mut Default::default()); let style = style.style_for(&mut Default::default());
@ -368,9 +368,9 @@ impl ContextMenu {
match item { match item {
ContextMenuItem::Item { action, .. } => { ContextMenuItem::Item { action, .. } => {
let toggle_state = if Some(ix) == self.selected_index { let toggle_state = if Some(ix) == self.selected_index {
ToggleState::On ToggleState::Active
} else { } else {
ToggleState::Off ToggleState::Inactive
}; };
let style = style.item.in_state(toggle_state); let style = style.item.in_state(toggle_state);
let style = style.style_for(&mut Default::default()); let style = style.style_for(&mut Default::default());
@ -420,9 +420,9 @@ impl ContextMenu {
let view_id = self.parent_view_id; let view_id = self.parent_view_id;
MouseEventHandler::<MenuItem, ContextMenu>::new(ix, cx, |state, _| { MouseEventHandler::<MenuItem, ContextMenu>::new(ix, cx, |state, _| {
let toggle_state = if Some(ix) == self.selected_index { let toggle_state = if Some(ix) == self.selected_index {
ToggleState::On ToggleState::Active
} else { } else {
ToggleState::Off ToggleState::Inactive
}; };
let style = style.item.in_state(toggle_state); let style = style.item.in_state(toggle_state);
let style = style.style_for(state); let style = style.style_for(state);

View file

@ -1267,7 +1267,7 @@ impl ProjectPanel {
.filter(|destination| details.path.starts_with(destination)) .filter(|destination| details.path.starts_with(destination))
.is_some() .is_some()
{ {
style = entry_style.on_state().default.clone(); style = entry_style.active_state().default.clone();
} }
let row_container_style = if show_editor { let row_container_style = if show_editor {
@ -1409,8 +1409,10 @@ impl View for ProjectPanel {
let context_menu_item_style = theme::current(cx).context_menu.item.clone(); let context_menu_item_style = theme::current(cx).context_menu.item.clone();
move |state, cx| { move |state, cx| {
let button_style = button_style.style_for(state).clone(); let button_style = button_style.style_for(state).clone();
let context_menu_item = let context_menu_item = context_menu_item_style
context_menu_item_style.on_state().style_for(state).clone(); .active_state()
.style_for(state)
.clone();
theme::ui::keystroke_label( theme::ui::keystroke_label(
"Open a project", "Open a project",

View file

@ -229,7 +229,10 @@ impl PickerDelegate for ProjectSymbolsDelegate {
.with_child( .with_child(
// Avoid styling the path differently when it is selected, since // Avoid styling the path differently when it is selected, since
// the symbol's syntax highlighting doesn't change when selected. // the symbol's syntax highlighting doesn't change when selected.
Label::new(path.to_string(), style.off_state().default.label.clone()), Label::new(
path.to_string(),
style.inactive_state().default.label.clone(),
),
) )
.contained() .contained()
.with_style(current_style.container) .with_style(current_style.container)

View file

@ -375,7 +375,7 @@ impl BufferSearchBar {
enum NavButton {} enum NavButton {}
MouseEventHandler::<NavButton, _>::new(direction as usize, cx, |state, cx| { MouseEventHandler::<NavButton, _>::new(direction as usize, cx, |state, cx| {
let theme = theme::current(cx); let theme = theme::current(cx);
let style = theme.search.option_button.off_state().style_for(state); let style = theme.search.option_button.inactive_state().style_for(state);
Label::new(icon, style.text.clone()) Label::new(icon, style.text.clone())
.contained() .contained()
.with_style(style.container) .with_style(style.container)

View file

@ -896,7 +896,7 @@ impl ProjectSearchBar {
enum NavButton {} enum NavButton {}
MouseEventHandler::<NavButton, _>::new(direction as usize, cx, |state, cx| { MouseEventHandler::<NavButton, _>::new(direction as usize, cx, |state, cx| {
let theme = theme::current(cx); let theme = theme::current(cx);
let style = theme.search.option_button.off_state().style_for(state); let style = theme.search.option_button.inactive_state().style_for(state);
Label::new(icon, style.text.clone()) Label::new(icon, style.text.clone())
.contained() .contained()
.with_style(style.container) .with_style(style.container)

View file

@ -812,40 +812,41 @@ pub struct Interactive<T> {
#[derive(Clone, Copy, Debug, Default, Deserialize)] #[derive(Clone, Copy, Debug, Default, Deserialize)]
pub struct Toggleable<T> { pub struct Toggleable<T> {
on: T, active: T,
off: T, inactive: T,
} }
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)] #[derive(Copy, Clone, Debug, Default, Hash, PartialEq, Eq)]
pub enum ToggleState { pub enum ToggleState {
Off, #[default]
On, Inactive,
Active,
} }
impl<T: std::borrow::Borrow<bool>> From<T> for ToggleState { impl<T: std::borrow::Borrow<bool>> From<T> for ToggleState {
fn from(item: T) -> Self { fn from(item: T) -> Self {
match *item.borrow() { match *item.borrow() {
true => Self::On, true => Self::Active,
false => Self::Off, false => Self::Inactive,
} }
} }
} }
impl<T> Toggleable<T> { impl<T> Toggleable<T> {
pub fn new(on: T, off: T) -> Self { pub fn new(active: T, inactive: T) -> Self {
Self { on, off } Self { active, inactive }
} }
pub fn in_state(&self, state: impl Into<ToggleState>) -> &T { pub fn in_state(&self, state: impl Into<ToggleState>) -> &T {
match state.into() { match state.into() {
ToggleState::Off => &self.off, ToggleState::Inactive => &self.inactive,
ToggleState::On => &self.on, ToggleState::Active => &self.active,
} }
} }
pub fn on_state(&self) -> &T { pub fn active_state(&self) -> &T {
self.in_state(ToggleState::On) self.in_state(ToggleState::Active)
} }
pub fn off_state(&self) -> &T { pub fn inactive_state(&self) -> &T {
self.in_state(ToggleState::Off) self.in_state(ToggleState::Inactive)
} }
} }

View file

@ -499,9 +499,9 @@ impl View for PanelButtons {
.with_child( .with_child(
MouseEventHandler::<Self, _>::new(panel_ix, cx, |state, cx| { MouseEventHandler::<Self, _>::new(panel_ix, cx, |state, cx| {
let toggle_state = if is_active { let toggle_state = if is_active {
ToggleState::On ToggleState::Active
} else { } else {
ToggleState::Off ToggleState::Inactive
}; };
let style = button_style.in_state(toggle_state); let style = button_style.in_state(toggle_state);

View file

@ -231,9 +231,9 @@ fn nav_button<A: Action, F: 'static + Fn(&mut Toolbar, &mut ViewContext<Toolbar>
) -> AnyElement<Toolbar> { ) -> AnyElement<Toolbar> {
MouseEventHandler::<A, _>::new(0, cx, |state, _| { MouseEventHandler::<A, _>::new(0, cx, |state, _| {
let style = if enabled { let style = if enabled {
style.off_state().style_for(state) style.inactive_state().style_for(state)
} else { } else {
style.off_state().disabled_style() style.inactive_state().disabled_style()
}; };
Svg::new(svg_path) Svg::new(svg_path)
.with_color(style.color) .with_color(style.color)