ui: Remove usage of DerivePathStr
macro (#30861)
This PR updates the `KnockoutIconName` and `VectorName` enums to manually implement the `path` method instead of using the `DerivePathStr` macro. Release Notes: - N/A
This commit is contained in:
parent
25b4591539
commit
4d827924f0
2 changed files with 24 additions and 18 deletions
|
@ -1,6 +1,7 @@
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use gpui::{Hsla, IntoElement, Point, svg};
|
use gpui::{Hsla, IntoElement, Point, svg};
|
||||||
use strum::{EnumIter, EnumString, IntoStaticStr};
|
use strum::{EnumIter, EnumString, IntoStaticStr};
|
||||||
use ui_macros::DerivePathStr;
|
|
||||||
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
|
@ -8,9 +9,8 @@ const ICON_DECORATION_SIZE: Pixels = px(11.);
|
||||||
|
|
||||||
/// An icon silhouette used to knockout the background of an element for an icon
|
/// An icon silhouette used to knockout the background of an element for an icon
|
||||||
/// to sit on top of it, emulating a stroke/border.
|
/// to sit on top of it, emulating a stroke/border.
|
||||||
#[derive(Debug, PartialEq, Eq, Copy, Clone, EnumIter, EnumString, IntoStaticStr, DerivePathStr)]
|
#[derive(Debug, PartialEq, Eq, Copy, Clone, EnumIter, EnumString, IntoStaticStr)]
|
||||||
#[strum(serialize_all = "snake_case")]
|
#[strum(serialize_all = "snake_case")]
|
||||||
#[path_str(prefix = "icons/knockouts", suffix = ".svg")]
|
|
||||||
pub enum KnockoutIconName {
|
pub enum KnockoutIconName {
|
||||||
XFg,
|
XFg,
|
||||||
XBg,
|
XBg,
|
||||||
|
@ -20,6 +20,14 @@ pub enum KnockoutIconName {
|
||||||
TriangleBg,
|
TriangleBg,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl KnockoutIconName {
|
||||||
|
/// Returns the path to this icon.
|
||||||
|
pub fn path(&self) -> Arc<str> {
|
||||||
|
let file_stem: &'static str = self.into();
|
||||||
|
format!("icons/knockouts/{file_stem}.svg").into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Copy, Clone, EnumIter, EnumString)]
|
#[derive(Debug, PartialEq, Eq, Copy, Clone, EnumIter, EnumString)]
|
||||||
pub enum IconDecorationKind {
|
pub enum IconDecorationKind {
|
||||||
X,
|
X,
|
||||||
|
|
|
@ -1,26 +1,16 @@
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use gpui::{App, IntoElement, Rems, RenderOnce, Size, Styled, Window, svg};
|
use gpui::{App, IntoElement, Rems, RenderOnce, Size, Styled, Window, svg};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use strum::{EnumIter, EnumString, IntoStaticStr};
|
use strum::{EnumIter, EnumString, IntoStaticStr};
|
||||||
use ui_macros::{DerivePathStr, path_str};
|
|
||||||
|
|
||||||
use crate::Color;
|
use crate::Color;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
#[derive(
|
#[derive(
|
||||||
Debug,
|
Debug, PartialEq, Eq, Copy, Clone, EnumIter, EnumString, IntoStaticStr, Serialize, Deserialize,
|
||||||
PartialEq,
|
|
||||||
Eq,
|
|
||||||
Copy,
|
|
||||||
Clone,
|
|
||||||
EnumIter,
|
|
||||||
EnumString,
|
|
||||||
IntoStaticStr,
|
|
||||||
Serialize,
|
|
||||||
Deserialize,
|
|
||||||
DerivePathStr,
|
|
||||||
)]
|
)]
|
||||||
#[strum(serialize_all = "snake_case")]
|
#[strum(serialize_all = "snake_case")]
|
||||||
#[path_str(prefix = "images", suffix = ".svg")]
|
|
||||||
pub enum VectorName {
|
pub enum VectorName {
|
||||||
ZedLogo,
|
ZedLogo,
|
||||||
ZedXCopilot,
|
ZedXCopilot,
|
||||||
|
@ -28,6 +18,14 @@ pub enum VectorName {
|
||||||
AiGrid,
|
AiGrid,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl VectorName {
|
||||||
|
/// Returns the path to this vector image.
|
||||||
|
pub fn path(&self) -> Arc<str> {
|
||||||
|
let file_stem: &'static str = self.into();
|
||||||
|
format!("images/{file_stem}.svg").into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A vector image, such as an SVG.
|
/// A vector image, such as an SVG.
|
||||||
///
|
///
|
||||||
/// A [`Vector`] is different from an [`crate::Icon`] in that it is intended
|
/// A [`Vector`] is different from an [`crate::Icon`] in that it is intended
|
||||||
|
@ -35,7 +33,7 @@ pub enum VectorName {
|
||||||
/// than conforming to the standard size of an icon.
|
/// than conforming to the standard size of an icon.
|
||||||
#[derive(IntoElement, RegisterComponent)]
|
#[derive(IntoElement, RegisterComponent)]
|
||||||
pub struct Vector {
|
pub struct Vector {
|
||||||
path: &'static str,
|
path: Arc<str>,
|
||||||
color: Color,
|
color: Color,
|
||||||
size: Size<Rems>,
|
size: Size<Rems>,
|
||||||
}
|
}
|
||||||
|
@ -160,6 +158,6 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn vector_path() {
|
fn vector_path() {
|
||||||
assert_eq!(VectorName::ZedLogo.path(), "images/zed_logo.svg");
|
assert_eq!(VectorName::ZedLogo.path().as_ref(), "images/zed_logo.svg");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue