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>) {
let theme = theme::current(cx).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| {
let items = if let Some(user) = self.user_store.read(cx).current_user() {
vec![
@ -364,14 +369,14 @@ impl CollabTitlebarItem {
.with_margin_left(
titlebar
.toggle_contacts_button
.off_state()
.inactive_state()
.default
.icon_width,
)
.with_margin_top(
titlebar
.toggle_contacts_button
.off_state()
.inactive_state()
.default
.icon_width,
)

View file

@ -798,7 +798,7 @@ impl ContactList {
.width
.or(theme.contact_avatar.height)
.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 line_height = row.name.text.line_height(font_cache);
let cap_height = row.name.text.cap_height(font_cache);
@ -897,7 +897,7 @@ impl ContactList {
.width
.or(theme.contact_avatar.height)
.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 line_height = row.name.text.line_height(font_cache);
let cap_height = row.name.text.cap_height(font_cache);

View file

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

View file

@ -1267,7 +1267,7 @@ impl ProjectPanel {
.filter(|destination| details.path.starts_with(destination))
.is_some()
{
style = entry_style.on_state().default.clone();
style = entry_style.active_state().default.clone();
}
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();
move |state, cx| {
let button_style = button_style.style_for(state).clone();
let context_menu_item =
context_menu_item_style.on_state().style_for(state).clone();
let context_menu_item = context_menu_item_style
.active_state()
.style_for(state)
.clone();
theme::ui::keystroke_label(
"Open a project",

View file

@ -229,7 +229,10 @@ impl PickerDelegate for ProjectSymbolsDelegate {
.with_child(
// Avoid styling the path differently when it is selected, since
// 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()
.with_style(current_style.container)

View file

@ -375,7 +375,7 @@ impl BufferSearchBar {
enum NavButton {}
MouseEventHandler::<NavButton, _>::new(direction as usize, cx, |state, 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())
.contained()
.with_style(style.container)

View file

@ -896,7 +896,7 @@ impl ProjectSearchBar {
enum NavButton {}
MouseEventHandler::<NavButton, _>::new(direction as usize, cx, |state, 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())
.contained()
.with_style(style.container)

View file

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

View file

@ -499,9 +499,9 @@ impl View for PanelButtons {
.with_child(
MouseEventHandler::<Self, _>::new(panel_ix, cx, |state, cx| {
let toggle_state = if is_active {
ToggleState::On
ToggleState::Active
} else {
ToggleState::Off
ToggleState::Inactive
};
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> {
MouseEventHandler::<A, _>::new(0, cx, |state, _| {
let style = if enabled {
style.off_state().style_for(state)
style.inactive_state().style_for(state)
} else {
style.off_state().disabled_style()
style.inactive_state().disabled_style()
};
Svg::new(svg_path)
.with_color(style.color)