Derive icon paths (#17816)

This PR improves adding and working with icons by using the new
`DerivePathStr` to derive icon paths.

This means paths no longer need to be manually specified, and the
`IconName` and file name will always be consistent between icons.

This PR does not do any work to standardize icons visually, remove
unused icons, or any other such cleanup.

Release Notes:

- N/A
This commit is contained in:
Nate Butler 2024-09-13 21:12:29 -04:00 committed by GitHub
parent ce848375fe
commit e8a2dd92c8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
39 changed files with 96 additions and 226 deletions

View file

@ -262,7 +262,7 @@ impl ActivityIndicator {
if !failed.is_empty() {
return Some(Content {
icon: Some(
Icon::new(IconName::ExclamationTriangle)
Icon::new(IconName::Warning)
.size(IconSize::Small)
.into_any_element(),
),
@ -280,7 +280,7 @@ impl ActivityIndicator {
if let Some(failure) = self.project.read(cx).last_formatting_failure() {
return Some(Content {
icon: Some(
Icon::new(IconName::ExclamationTriangle)
Icon::new(IconName::Warning)
.size(IconSize::Small)
.into_any_element(),
),
@ -333,7 +333,7 @@ impl ActivityIndicator {
}),
AutoUpdateStatus::Errored => Some(Content {
icon: Some(
Icon::new(IconName::ExclamationTriangle)
Icon::new(IconName::Warning)
.size(IconSize::Small)
.into_any_element(),
),

View file

@ -4110,7 +4110,7 @@ impl ContextEditor {
h_flex()
.gap_3()
.child(
Icon::new(IconName::ExclamationTriangle)
Icon::new(IconName::Warning)
.size(IconSize::Small)
.color(Color::Warning),
)
@ -5235,7 +5235,7 @@ fn quote_selection_fold_placeholder(title: String, editor: WeakView<Editor>) ->
ButtonLike::new(fold_id)
.style(ButtonStyle::Filled)
.layer(ElevationIndex::ElevatedSurface)
.child(Icon::new(IconName::TextSelect))
.child(Icon::new(IconName::CursorIBeam))
.child(Label::new(title.clone()).single_line())
.on_click(move |_, cx| {
editor
@ -5339,7 +5339,7 @@ fn render_docs_slash_command_trailer(
div()
.id(("latest-error", row.0))
.child(
Icon::new(IconName::ExclamationTriangle)
Icon::new(IconName::Warning)
.size(IconSize::Small)
.color(Color::Warning),
)

View file

@ -1478,7 +1478,7 @@ impl Render for PromptEditor {
.child(
ModelSelector::new(
self.fs.clone(),
IconButton::new("context", IconName::SlidersAlt)
IconButton::new("context", IconName::SettingsAlt)
.shape(IconButtonShape::Square)
.icon_size(IconSize::Small)
.icon_color(Color::Muted)

View file

@ -193,11 +193,11 @@ impl SlashCommand for DiagnosticsSlashCommand {
.map(|(range, placeholder_type)| SlashCommandOutputSection {
range,
icon: match placeholder_type {
PlaceholderType::Root(_, _) => IconName::ExclamationTriangle,
PlaceholderType::Root(_, _) => IconName::Warning,
PlaceholderType::File(_) => IconName::File,
PlaceholderType::Diagnostic(DiagnosticType::Error, _) => IconName::XCircle,
PlaceholderType::Diagnostic(DiagnosticType::Warning, _) => {
IconName::ExclamationTriangle
IconName::Warning
}
},
label: match placeholder_type {

View file

@ -585,7 +585,7 @@ impl Render for PromptEditor {
.gap_2()
.child(ModelSelector::new(
self.fs.clone(),
IconButton::new("context", IconName::SlidersAlt)
IconButton::new("context", IconName::SettingsAlt)
.shape(IconButtonShape::Square)
.icon_size(IconSize::Small)
.icon_color(Color::Muted)

View file

@ -2831,7 +2831,7 @@ impl Panel for CollabPanel {
fn icon(&self, cx: &gpui::WindowContext) -> Option<ui::IconName> {
CollaborationPanelSettings::get_global(cx)
.button
.then_some(ui::IconName::Collab)
.then_some(ui::IconName::UserGroup)
}
fn icon_tooltip(&self, _cx: &WindowContext) -> Option<&'static str> {

View file

@ -667,7 +667,7 @@ impl Item for ProjectDiagnosticsEditor {
then.child(
h_flex()
.gap_1()
.child(Icon::new(IconName::ExclamationTriangle).color(Color::Warning))
.child(Icon::new(IconName::Warning).color(Color::Warning))
.child(
Label::new(self.summary.warning_count.to_string())
.color(params.text_color()),
@ -804,7 +804,7 @@ fn diagnostic_header_renderer(diagnostic: Diagnostic) -> RenderBlock {
icon.path(IconName::XCircle.path())
.text_color(Color::Error.color(cx))
} else {
icon.path(IconName::ExclamationTriangle.path())
icon.path(IconName::Warning.path())
.text_color(Color::Warning.color(cx))
}
}),

View file

@ -30,7 +30,7 @@ impl Render for DiagnosticIndicator {
(0, warning_count) => h_flex()
.gap_1()
.child(
Icon::new(IconName::ExclamationTriangle)
Icon::new(IconName::Warning)
.size(IconSize::Small)
.color(Color::Warning),
)
@ -52,7 +52,7 @@ impl Render for DiagnosticIndicator {
)
.child(Label::new(error_count.to_string()).size(LabelSize::Small))
.child(
Icon::new(IconName::ExclamationTriangle)
Icon::new(IconName::Warning)
.size(IconSize::Small)
.color(Color::Warning),
)

View file

@ -50,7 +50,7 @@ impl Render for ToolbarControls {
)
})
.child(
IconButton::new("toggle-warnings", IconName::ExclamationTriangle)
IconButton::new("toggle-warnings", IconName::Warning)
.tooltip(move |cx| Tooltip::text(tooltip, cx))
.on_click(cx.listener(|this, _, cx| {
if let Some(editor) = this.editor() {

View file

@ -150,7 +150,7 @@ impl Render for QuickActionBar {
let focus = editor.focus_handle(cx);
PopoverMenu::new("editor-selections-dropdown")
.trigger(
IconButton::new("toggle_editor_selections_icon", IconName::TextCursor)
IconButton::new("toggle_editor_selections_icon", IconName::CursorIBeam)
.shape(IconButtonShape::Square)
.icon_size(IconSize::Small)
.style(ButtonStyle::Subtle)

View file

@ -991,7 +991,7 @@ impl Item for TerminalView {
Some(terminal_task) => match &terminal_task.status {
TaskStatus::Running => (IconName::Play, Color::Disabled, None),
TaskStatus::Unknown => (
IconName::ExclamationTriangle,
IconName::Warning,
Color::Warning,
Some(rerun_button(terminal_task.id.clone())),
),

View file

@ -1,6 +1,7 @@
use gpui::{svg, AnimationElement, Hsla, IntoElement, Rems, Transformation};
use serde::{Deserialize, Serialize};
use strum::{EnumIter, EnumString, IntoStaticStr};
use ui_macros::DerivePathStr;
use crate::{prelude::*, Indicator};
@ -102,15 +103,27 @@ impl IconSize {
}
#[derive(
Debug, PartialEq, Eq, Copy, Clone, EnumIter, EnumString, IntoStaticStr, Serialize, Deserialize,
Debug,
PartialEq,
Eq,
Copy,
Clone,
EnumIter,
EnumString,
IntoStaticStr,
Serialize,
Deserialize,
DerivePathStr,
)]
#[strum(serialize_all = "snake_case")]
#[path_str(prefix = "icons", suffix = ".svg")]
pub enum IconName {
Ai,
AiAnthropic,
AiAnthropicHosted,
AiOpenAi,
AiGoogle,
AiOllama,
AiOpenAi,
AiZed,
ArrowCircle,
ArrowDown,
@ -135,15 +148,13 @@ pub enum IconName {
CaseSensitive,
Check,
ChevronDown,
/// This chevron indicates a popover menu.
ChevronDownSmall,
ChevronDownSmall, // This chevron indicates a popover menu.
ChevronLeft,
ChevronRight,
ChevronUp,
ChevronUpDown,
Close,
Code,
Collab,
Command,
Context,
Control,
@ -153,6 +164,8 @@ pub enum IconName {
CopilotInit,
Copy,
CountdownTimer,
CursorIBeam,
CursorText,
Dash,
DatabaseZap,
Delete,
@ -162,21 +175,20 @@ pub enum IconName {
EllipsisVertical,
Envelope,
Escape,
ExclamationTriangle,
Exit,
ExpandVertical,
ExternalLink,
Eye,
File,
FileCode,
FileDoc,
FileGeneric,
FileGit,
FileLock,
FileRust,
FileText,
FileToml,
FileTree,
FileText,
FileCode,
Filter,
Folder,
FolderOpen,
@ -184,11 +196,11 @@ pub enum IconName {
Font,
FontSize,
FontWeight,
Github,
GenericMinimize,
GenericMaximize,
GenericClose,
GenericMaximize,
GenericMinimize,
GenericRestore,
Github,
Hash,
HistoryRerun,
Indicator,
@ -228,21 +240,21 @@ pub enum IconName {
Rerun,
Return,
Reveal,
Route,
RotateCcw,
RotateCw,
Route,
Save,
Screen,
SearchSelection,
SearchCode,
SearchSelection,
SelectAll,
Server,
Settings,
SettingsAlt,
Shift,
Slash,
SlashSquare,
Sliders,
SlidersAlt,
Snip,
Space,
Sparkle,
@ -260,191 +272,18 @@ pub enum IconName {
SupermavenInit,
Tab,
Terminal,
TextCursor,
TextSelect,
Trash,
TriangleRight,
Undo,
Unpin,
Update,
UserGroup,
Visible,
Warning,
WholeWord,
XCircle,
ZedAssistant,
ZedAssistantFilled,
Visible,
}
impl IconName {
pub fn path(self) -> &'static str {
match self {
IconName::Ai => "icons/ai.svg",
IconName::AiAnthropic => "icons/ai_anthropic.svg",
IconName::AiAnthropicHosted => "icons/ai_anthropic_hosted.svg",
IconName::AiOpenAi => "icons/ai_open_ai.svg",
IconName::AiGoogle => "icons/ai_google.svg",
IconName::AiOllama => "icons/ai_ollama.svg",
IconName::AiZed => "icons/ai_zed.svg",
IconName::ArrowCircle => "icons/arrow_circle.svg",
IconName::ArrowDown => "icons/arrow_down.svg",
IconName::ArrowDownFromLine => "icons/arrow_down_from_line.svg",
IconName::ArrowLeft => "icons/arrow_left.svg",
IconName::ArrowRight => "icons/arrow_right.svg",
IconName::ArrowUp => "icons/arrow_up.svg",
IconName::ArrowUpFromLine => "icons/arrow_up_from_line.svg",
IconName::ArrowUpRight => "icons/arrow_up_right.svg",
IconName::AtSign => "icons/at_sign.svg",
IconName::AudioOff => "icons/speaker_off.svg",
IconName::AudioOn => "icons/speaker_loud.svg",
IconName::Backspace => "icons/backspace.svg",
IconName::Bell => "icons/bell.svg",
IconName::BellDot => "icons/bell_dot.svg",
IconName::BellOff => "icons/bell_off.svg",
IconName::BellRing => "icons/bell_ring.svg",
IconName::Bolt => "icons/bolt.svg",
IconName::Book => "icons/book.svg",
IconName::BookCopy => "icons/book_copy.svg",
IconName::BookPlus => "icons/book_plus.svg",
IconName::CaseSensitive => "icons/case_insensitive.svg",
IconName::Check => "icons/check.svg",
IconName::ChevronDown => "icons/chevron_down.svg",
IconName::ChevronDownSmall => "icons/chevron_down_small.svg",
IconName::ChevronLeft => "icons/chevron_left.svg",
IconName::ChevronRight => "icons/chevron_right.svg",
IconName::ChevronUp => "icons/chevron_up.svg",
IconName::ChevronUpDown => "icons/chevron_up_down.svg",
IconName::Close => "icons/x.svg",
IconName::Code => "icons/code.svg",
IconName::Collab => "icons/user_group_16.svg",
IconName::Command => "icons/command.svg",
IconName::Context => "icons/context.svg",
IconName::Control => "icons/control.svg",
IconName::Copilot => "icons/copilot.svg",
IconName::CopilotDisabled => "icons/copilot_disabled.svg",
IconName::CopilotError => "icons/copilot_error.svg",
IconName::CopilotInit => "icons/copilot_init.svg",
IconName::Copy => "icons/copy.svg",
IconName::CountdownTimer => "icons/countdown_timer.svg",
IconName::Dash => "icons/dash.svg",
IconName::DatabaseZap => "icons/database_zap.svg",
IconName::Delete => "icons/delete.svg",
IconName::Disconnected => "icons/disconnected.svg",
IconName::Download => "icons/download.svg",
IconName::Ellipsis => "icons/ellipsis.svg",
IconName::EllipsisVertical => "icons/ellipsis_vertical.svg",
IconName::Envelope => "icons/feedback.svg",
IconName::Escape => "icons/escape.svg",
IconName::ExclamationTriangle => "icons/warning.svg",
IconName::Exit => "icons/exit.svg",
IconName::ExpandVertical => "icons/expand_vertical.svg",
IconName::ExternalLink => "icons/external_link.svg",
IconName::Eye => "icons/eye.svg",
IconName::File => "icons/file.svg",
IconName::FileDoc => "icons/file_icons/book.svg",
IconName::FileGeneric => "icons/file_icons/file.svg",
IconName::FileGit => "icons/file_icons/git.svg",
IconName::FileLock => "icons/file_icons/lock.svg",
IconName::FileRust => "icons/file_icons/rust.svg",
IconName::FileToml => "icons/file_icons/toml.svg",
IconName::FileTree => "icons/project.svg",
IconName::FileCode => "icons/file_code.svg",
IconName::FileText => "icons/file_text.svg",
IconName::Filter => "icons/filter.svg",
IconName::Folder => "icons/file_icons/folder.svg",
IconName::FolderOpen => "icons/file_icons/folder_open.svg",
IconName::FolderX => "icons/stop_sharing.svg",
IconName::Font => "icons/font.svg",
IconName::FontSize => "icons/font_size.svg",
IconName::FontWeight => "icons/font_weight.svg",
IconName::Github => "icons/github.svg",
IconName::GenericMinimize => "icons/generic_minimize.svg",
IconName::GenericMaximize => "icons/generic_maximize.svg",
IconName::GenericClose => "icons/generic_close.svg",
IconName::GenericRestore => "icons/generic_restore.svg",
IconName::Hash => "icons/hash.svg",
IconName::HistoryRerun => "icons/history_rerun.svg",
IconName::Indicator => "icons/indicator.svg",
IconName::IndicatorX => "icons/indicator_x.svg",
IconName::InlayHint => "icons/inlay_hint.svg",
IconName::Library => "icons/library.svg",
IconName::LineHeight => "icons/line_height.svg",
IconName::Link => "icons/link.svg",
IconName::ListTree => "icons/list_tree.svg",
IconName::MagnifyingGlass => "icons/magnifying_glass.svg",
IconName::MailOpen => "icons/mail_open.svg",
IconName::Maximize => "icons/maximize.svg",
IconName::Menu => "icons/menu.svg",
IconName::MessageBubbles => "icons/conversations.svg",
IconName::Mic => "icons/mic.svg",
IconName::MicMute => "icons/mic_mute.svg",
IconName::Microscope => "icons/microscope.svg",
IconName::Minimize => "icons/minimize.svg",
IconName::Option => "icons/option.svg",
IconName::PageDown => "icons/page_down.svg",
IconName::PageUp => "icons/page_up.svg",
IconName::Pencil => "icons/pencil.svg",
IconName::Person => "icons/person.svg",
IconName::Pin => "icons/pin.svg",
IconName::Play => "icons/play.svg",
IconName::Plus => "icons/plus.svg",
IconName::PocketKnife => "icons/pocket_knife.svg",
IconName::Public => "icons/public.svg",
IconName::PullRequest => "icons/pull_request.svg",
IconName::Quote => "icons/quote.svg",
IconName::Regex => "icons/regex.svg",
IconName::ReplNeutral => "icons/repl_neutral.svg",
IconName::Replace => "icons/replace.svg",
IconName::ReplaceAll => "icons/replace_all.svg",
IconName::ReplaceNext => "icons/replace_next.svg",
IconName::ReplyArrowRight => "icons/reply_arrow_right.svg",
IconName::Rerun => "icons/rerun.svg",
IconName::Return => "icons/return.svg",
IconName::Reveal => "icons/reveal.svg",
IconName::RotateCcw => "icons/rotate_ccw.svg",
IconName::RotateCw => "icons/rotate_cw.svg",
IconName::Route => "icons/route.svg",
IconName::Save => "icons/save.svg",
IconName::Screen => "icons/desktop.svg",
IconName::SearchSelection => "icons/search_selection.svg",
IconName::SearchCode => "icons/search_code.svg",
IconName::SelectAll => "icons/select_all.svg",
IconName::Server => "icons/server.svg",
IconName::Settings => "icons/file_icons/settings.svg",
IconName::Shift => "icons/shift.svg",
IconName::Slash => "icons/slash.svg",
IconName::SlashSquare => "icons/slash_square.svg",
IconName::Sliders => "icons/sliders.svg",
IconName::SlidersAlt => "icons/sliders-alt.svg",
IconName::Snip => "icons/snip.svg",
IconName::Space => "icons/space.svg",
IconName::Sparkle => "icons/sparkle.svg",
IconName::SparkleAlt => "icons/sparkle_alt.svg",
IconName::SparkleFilled => "icons/sparkle_filled.svg",
IconName::Spinner => "icons/spinner.svg",
IconName::Split => "icons/split.svg",
IconName::Star => "icons/star.svg",
IconName::StarFilled => "icons/star_filled.svg",
IconName::Stop => "icons/stop.svg",
IconName::Strikethrough => "icons/strikethrough.svg",
IconName::Supermaven => "icons/supermaven.svg",
IconName::SupermavenDisabled => "icons/supermaven_disabled.svg",
IconName::SupermavenError => "icons/supermaven_error.svg",
IconName::SupermavenInit => "icons/supermaven_init.svg",
IconName::Tab => "icons/tab.svg",
IconName::Terminal => "icons/terminal.svg",
IconName::TextCursor => "icons/text-cursor.svg",
IconName::TextSelect => "icons/text_select.svg",
IconName::Trash => "icons/trash.svg",
IconName::TriangleRight => "icons/triangle_right.svg",
IconName::Unpin => "icons/unpin.svg",
IconName::Update => "icons/update.svg",
IconName::Undo => "icons/undo.svg",
IconName::WholeWord => "icons/word_search.svg",
IconName::XCircle => "icons/error.svg",
IconName::ZedAssistant => "icons/zed_assistant.svg",
IconName::ZedAssistantFilled => "icons/zed_assistant_filled.svg",
IconName::Visible => "icons/visible.svg",
}
}
}
#[derive(IntoElement)]

View file

@ -24,7 +24,7 @@ impl Render for ListHeaderStory {
.child(
ListHeader::new("Section 4")
.end_slot(IconButton::new("action_1", IconName::Bolt))
.end_slot(IconButton::new("action_2", IconName::ExclamationTriangle))
.end_slot(IconButton::new("action_2", IconName::Warning))
.end_slot(IconButton::new("action_3", IconName::Plus)),
)
}

View file

@ -311,15 +311,11 @@ impl Render for LanguageServerPrompt {
.mt(px(-2.0))
.map(|icon| {
if severity == DiagnosticSeverity::ERROR {
icon.path(
IconName::ExclamationTriangle.path(),
)
.text_color(Color::Error.color(cx))
icon.path(IconName::Warning.path())
.text_color(Color::Error.color(cx))
} else {
icon.path(
IconName::ExclamationTriangle.path(),
)
.text_color(Color::Warning.color(cx))
icon.path(IconName::Warning.path())
.text_color(Color::Warning.color(cx))
}
})
}),
@ -421,7 +417,7 @@ impl Render for ErrorMessagePrompt {
.mr_2()
.mt(px(-2.0))
.map(|icon| {
icon.path(IconName::ExclamationTriangle.path())
icon.path(IconName::Warning.path())
.text_color(Color::Error.color(cx))
}),
)