onboarding: Go back to not having system be separate (#35499)
Going back to having system be mutually exclusive with light/dark to simplify the system. We instead just show both light and dark when system is selected Release Notes: - N/A --------- Co-authored-by: Danilo Leal <daniloleal09@gmail.com> Co-authored-by: Anthony Eid <hello@anthonyeid.me>
This commit is contained in:
parent
0ceb5b7d90
commit
2ccf81f2f8
3 changed files with 415 additions and 310 deletions
|
@ -1,42 +1,24 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use client::TelemetrySettings;
|
||||
use fs::Fs;
|
||||
use gpui::{App, Entity, IntoElement, Window};
|
||||
use gpui::{App, IntoElement, Window};
|
||||
use settings::{BaseKeymap, Settings, update_settings_file};
|
||||
use theme::{Appearance, ThemeMode, ThemeName, ThemeRegistry, ThemeSelection, ThemeSettings};
|
||||
use theme::{
|
||||
Appearance, SystemAppearance, ThemeMode, ThemeName, ThemeRegistry, ThemeSelection,
|
||||
ThemeSettings,
|
||||
};
|
||||
use ui::{
|
||||
ParentElement as _, StatefulInteractiveElement, SwitchField, ToggleButtonGroup,
|
||||
ToggleButtonSimple, ToggleButtonWithIcon, prelude::*, rems_from_px,
|
||||
};
|
||||
use vim_mode_setting::VimModeSetting;
|
||||
|
||||
use crate::theme_preview::ThemePreviewTile;
|
||||
use crate::theme_preview::{ThemePreviewStyle, ThemePreviewTile};
|
||||
|
||||
/// separates theme "mode" ("dark" | "light" | "system") into two separate states
|
||||
/// - appearance = "dark" | "light"
|
||||
/// - "system" true/false
|
||||
/// when system selected:
|
||||
/// - toggling between light and dark does not change theme.mode, just which variant will be changed
|
||||
/// when system not selected:
|
||||
/// - toggling between light and dark does change theme.mode
|
||||
/// selecting a theme preview will always change theme.["light" | "dark"] to the selected theme,
|
||||
///
|
||||
/// this allows for selecting a dark and light theme option regardless of whether the mode is set to system or not
|
||||
/// it does not support setting theme to a static value
|
||||
fn render_theme_section(window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
fn render_theme_section(_window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
let theme_selection = ThemeSettings::get_global(cx).theme_selection.clone();
|
||||
let system_appearance = theme::SystemAppearance::global(cx);
|
||||
let appearance_state = window.use_state(cx, |_, _cx| {
|
||||
theme_selection
|
||||
.as_ref()
|
||||
.and_then(|selection| selection.mode())
|
||||
.and_then(|mode| match mode {
|
||||
ThemeMode::System => None,
|
||||
ThemeMode::Light => Some(Appearance::Light),
|
||||
ThemeMode::Dark => Some(Appearance::Dark),
|
||||
})
|
||||
.unwrap_or(*system_appearance)
|
||||
});
|
||||
let appearance = *appearance_state.read(cx);
|
||||
let theme_selection = theme_selection.unwrap_or_else(|| ThemeSelection::Dynamic {
|
||||
mode: match *system_appearance {
|
||||
Appearance::Light => ThemeMode::Light,
|
||||
|
@ -45,70 +27,13 @@ fn render_theme_section(window: &mut Window, cx: &mut App) -> impl IntoElement {
|
|||
light: ThemeName("One Light".into()),
|
||||
dark: ThemeName("One Dark".into()),
|
||||
});
|
||||
let theme_registry = ThemeRegistry::global(cx);
|
||||
|
||||
let current_theme_name = theme_selection.theme(appearance);
|
||||
let theme_mode = theme_selection.mode().unwrap_or_default();
|
||||
|
||||
// let theme_mode = theme_selection.mode();
|
||||
// TODO: Clean this up once the "System" button inside the
|
||||
// toggle button group is done
|
||||
|
||||
let selected_index = match appearance {
|
||||
Appearance::Light => 0,
|
||||
Appearance::Dark => 1,
|
||||
};
|
||||
|
||||
let theme_seed = 0xBEEF as f32;
|
||||
|
||||
const LIGHT_THEMES: [&'static str; 3] = ["One Light", "Ayu Light", "Gruvbox Light"];
|
||||
const DARK_THEMES: [&'static str; 3] = ["One Dark", "Ayu Dark", "Gruvbox Dark"];
|
||||
|
||||
let theme_names = match appearance {
|
||||
Appearance::Light => LIGHT_THEMES,
|
||||
Appearance::Dark => DARK_THEMES,
|
||||
};
|
||||
let themes = theme_names
|
||||
.map(|theme_name| theme_registry.get(theme_name))
|
||||
.map(Result::unwrap);
|
||||
|
||||
let theme_previews = themes.map(|theme| {
|
||||
let is_selected = theme.name == current_theme_name;
|
||||
let name = theme.name.clone();
|
||||
let colors = cx.theme().colors();
|
||||
|
||||
v_flex()
|
||||
.id(name.clone())
|
||||
.w_full()
|
||||
.items_center()
|
||||
.gap_1()
|
||||
.child(
|
||||
div()
|
||||
.w_full()
|
||||
.border_2()
|
||||
.border_color(colors.border_transparent)
|
||||
.rounded(ThemePreviewTile::CORNER_RADIUS)
|
||||
.map(|this| {
|
||||
if is_selected {
|
||||
this.border_color(colors.border_selected)
|
||||
} else {
|
||||
this.opacity(0.8).hover(|s| s.border_color(colors.border))
|
||||
}
|
||||
})
|
||||
.child(ThemePreviewTile::new(theme.clone(), theme_seed)),
|
||||
)
|
||||
.child(Label::new(name).color(Color::Muted).size(LabelSize::Small))
|
||||
.on_click({
|
||||
let theme_name = theme.name.clone();
|
||||
move |_, _, cx| {
|
||||
let fs = <dyn Fs>::global(cx);
|
||||
let theme_name = theme_name.clone();
|
||||
update_settings_file::<ThemeSettings>(fs, cx, move |settings, _| {
|
||||
settings.set_theme(theme_name, appearance);
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
let theme_mode = theme_selection
|
||||
.mode()
|
||||
.unwrap_or_else(|| match *system_appearance {
|
||||
Appearance::Light => ThemeMode::Light,
|
||||
Appearance::Dark => ThemeMode::Dark,
|
||||
});
|
||||
|
||||
return v_flex()
|
||||
.gap_2()
|
||||
|
@ -116,93 +41,148 @@ fn render_theme_section(window: &mut Window, cx: &mut App) -> impl IntoElement {
|
|||
h_flex().justify_between().child(Label::new("Theme")).child(
|
||||
ToggleButtonGroup::single_row(
|
||||
"theme-selector-onboarding-dark-light",
|
||||
[
|
||||
ToggleButtonSimple::new("Light", {
|
||||
let appearance_state = appearance_state.clone();
|
||||
[ThemeMode::Light, ThemeMode::Dark, ThemeMode::System].map(|mode| {
|
||||
const MODE_NAMES: [SharedString; 3] = [
|
||||
SharedString::new_static("Light"),
|
||||
SharedString::new_static("Dark"),
|
||||
SharedString::new_static("System"),
|
||||
];
|
||||
ToggleButtonSimple::new(
|
||||
MODE_NAMES[mode as usize].clone(),
|
||||
move |_, _, cx| {
|
||||
write_appearance_change(&appearance_state, Appearance::Light, cx);
|
||||
}
|
||||
}),
|
||||
ToggleButtonSimple::new("Dark", {
|
||||
let appearance_state = appearance_state.clone();
|
||||
move |_, _, cx| {
|
||||
write_appearance_change(&appearance_state, Appearance::Dark, cx);
|
||||
}
|
||||
}),
|
||||
// TODO: Properly put the System back as a button within this group
|
||||
// Currently, given "System" is not an option in the Appearance enum,
|
||||
// this button doesn't get selected
|
||||
ToggleButtonSimple::new("System", {
|
||||
let theme = theme_selection.clone();
|
||||
move |_, _, cx| {
|
||||
toggle_system_theme_mode(theme.clone(), appearance, cx);
|
||||
}
|
||||
})
|
||||
.selected(theme_mode == ThemeMode::System),
|
||||
],
|
||||
write_mode_change(mode, cx);
|
||||
},
|
||||
)
|
||||
}),
|
||||
)
|
||||
.selected_index(selected_index)
|
||||
.selected_index(theme_mode as usize)
|
||||
.style(ui::ToggleButtonGroupStyle::Outlined)
|
||||
.button_width(rems_from_px(64.)),
|
||||
),
|
||||
)
|
||||
.child(h_flex().gap_4().justify_between().children(theme_previews));
|
||||
.child(
|
||||
h_flex()
|
||||
.gap_4()
|
||||
.justify_between()
|
||||
.children(render_theme_previews(&theme_selection, cx)),
|
||||
);
|
||||
|
||||
fn write_appearance_change(
|
||||
appearance_state: &Entity<Appearance>,
|
||||
new_appearance: Appearance,
|
||||
fn render_theme_previews(
|
||||
theme_selection: &ThemeSelection,
|
||||
cx: &mut App,
|
||||
) {
|
||||
let fs = <dyn Fs>::global(cx);
|
||||
appearance_state.write(cx, new_appearance);
|
||||
) -> [impl IntoElement; 3] {
|
||||
let system_appearance = SystemAppearance::global(cx);
|
||||
let theme_registry = ThemeRegistry::global(cx);
|
||||
|
||||
update_settings_file::<ThemeSettings>(fs, cx, move |settings, _| {
|
||||
if settings.theme.as_ref().and_then(ThemeSelection::mode) == Some(ThemeMode::System) {
|
||||
return;
|
||||
}
|
||||
let new_mode = match new_appearance {
|
||||
let theme_seed = 0xBEEF as f32;
|
||||
let theme_mode = theme_selection
|
||||
.mode()
|
||||
.unwrap_or_else(|| match *system_appearance {
|
||||
Appearance::Light => ThemeMode::Light,
|
||||
Appearance::Dark => ThemeMode::Dark,
|
||||
};
|
||||
settings.set_mode(new_mode);
|
||||
});
|
||||
let appearance = match theme_mode {
|
||||
ThemeMode::Light => Appearance::Light,
|
||||
ThemeMode::Dark => Appearance::Dark,
|
||||
ThemeMode::System => *system_appearance,
|
||||
};
|
||||
let current_theme_name = theme_selection.theme(appearance);
|
||||
|
||||
const LIGHT_THEMES: [&'static str; 3] = ["One Light", "Ayu Light", "Gruvbox Light"];
|
||||
const DARK_THEMES: [&'static str; 3] = ["One Dark", "Ayu Dark", "Gruvbox Dark"];
|
||||
const FAMILY_NAMES: [SharedString; 3] = [
|
||||
SharedString::new_static("One"),
|
||||
SharedString::new_static("Ayu"),
|
||||
SharedString::new_static("Gruvbox"),
|
||||
];
|
||||
|
||||
let theme_names = match appearance {
|
||||
Appearance::Light => LIGHT_THEMES,
|
||||
Appearance::Dark => DARK_THEMES,
|
||||
};
|
||||
|
||||
let themes = theme_names.map(|theme| theme_registry.get(theme).unwrap());
|
||||
|
||||
let theme_previews = [0, 1, 2].map(|index| {
|
||||
let theme = &themes[index];
|
||||
let is_selected = theme.name == current_theme_name;
|
||||
let name = theme.name.clone();
|
||||
let colors = cx.theme().colors();
|
||||
|
||||
v_flex()
|
||||
.id(name.clone())
|
||||
.w_full()
|
||||
.items_center()
|
||||
.gap_1()
|
||||
.child(
|
||||
h_flex()
|
||||
.relative()
|
||||
.w_full()
|
||||
.border_2()
|
||||
.border_color(colors.border_transparent)
|
||||
.rounded(ThemePreviewTile::ROOT_RADIUS)
|
||||
.map(|this| {
|
||||
if is_selected {
|
||||
this.border_color(colors.border_selected)
|
||||
} else {
|
||||
this.opacity(0.8).hover(|s| s.border_color(colors.border))
|
||||
}
|
||||
})
|
||||
.map(|this| {
|
||||
if theme_mode == ThemeMode::System {
|
||||
let (light, dark) = (
|
||||
theme_registry.get(LIGHT_THEMES[index]).unwrap(),
|
||||
theme_registry.get(DARK_THEMES[index]).unwrap(),
|
||||
);
|
||||
this.child(
|
||||
ThemePreviewTile::new(light, theme_seed)
|
||||
.style(ThemePreviewStyle::SideBySide(dark)),
|
||||
)
|
||||
} else {
|
||||
this.child(
|
||||
ThemePreviewTile::new(theme.clone(), theme_seed)
|
||||
.style(ThemePreviewStyle::Bordered),
|
||||
)
|
||||
}
|
||||
}),
|
||||
)
|
||||
.child(
|
||||
Label::new(FAMILY_NAMES[index].clone())
|
||||
.color(Color::Muted)
|
||||
.size(LabelSize::Small),
|
||||
)
|
||||
.on_click({
|
||||
let theme_name = theme.name.clone();
|
||||
move |_, _, cx| {
|
||||
write_theme_change(theme_name.clone(), theme_mode, cx);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
theme_previews
|
||||
}
|
||||
|
||||
fn write_mode_change(mode: ThemeMode, cx: &mut App) {
|
||||
let fs = <dyn Fs>::global(cx);
|
||||
update_settings_file::<ThemeSettings>(fs, cx, move |settings, _cx| {
|
||||
settings.set_mode(mode);
|
||||
});
|
||||
}
|
||||
|
||||
fn toggle_system_theme_mode(
|
||||
theme_selection: ThemeSelection,
|
||||
appearance: Appearance,
|
||||
cx: &mut App,
|
||||
) {
|
||||
fn write_theme_change(theme: impl Into<Arc<str>>, theme_mode: ThemeMode, cx: &mut App) {
|
||||
let fs = <dyn Fs>::global(cx);
|
||||
|
||||
update_settings_file::<ThemeSettings>(fs, cx, move |settings, _| {
|
||||
settings.theme = Some(match theme_selection {
|
||||
ThemeSelection::Static(theme_name) => ThemeSelection::Dynamic {
|
||||
let theme = theme.into();
|
||||
update_settings_file::<ThemeSettings>(fs, cx, move |settings, cx| {
|
||||
if theme_mode == ThemeMode::System {
|
||||
settings.theme = Some(ThemeSelection::Dynamic {
|
||||
mode: ThemeMode::System,
|
||||
light: theme_name.clone(),
|
||||
dark: theme_name.clone(),
|
||||
},
|
||||
ThemeSelection::Dynamic {
|
||||
mode: ThemeMode::System,
|
||||
light,
|
||||
dark,
|
||||
} => {
|
||||
let mode = match appearance {
|
||||
Appearance::Light => ThemeMode::Light,
|
||||
Appearance::Dark => ThemeMode::Dark,
|
||||
};
|
||||
ThemeSelection::Dynamic { mode, light, dark }
|
||||
}
|
||||
ThemeSelection::Dynamic {
|
||||
mode: _,
|
||||
light,
|
||||
dark,
|
||||
} => ThemeSelection::Dynamic {
|
||||
mode: ThemeMode::System,
|
||||
light,
|
||||
dark,
|
||||
},
|
||||
});
|
||||
light: ThemeName(theme.clone()),
|
||||
dark: ThemeName(theme.clone()),
|
||||
});
|
||||
} else {
|
||||
let appearance = *SystemAppearance::global(cx);
|
||||
settings.set_theme(theme.clone(), appearance);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue