Use IconElement in project panel

This commit is contained in:
Marshall Bowers 2023-11-14 15:44:26 -05:00
parent dcdbf43af0
commit 22f024bd5f
2 changed files with 14 additions and 13 deletions

View file

@ -8,7 +8,7 @@ use file_associations::FileAssociations;
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use gpui::{ use gpui::{
actions, div, px, rems, svg, uniform_list, Action, AppContext, AssetSource, AsyncWindowContext, actions, div, px, uniform_list, Action, AppContext, AssetSource, AsyncWindowContext,
ClipboardItem, Component, Div, EventEmitter, FocusHandle, FocusableKeyDispatch, Model, ClipboardItem, Component, Div, EventEmitter, FocusHandle, FocusableKeyDispatch, Model,
MouseButton, ParentElement as _, Pixels, Point, PromptLevel, Render, StatefulInteractive, MouseButton, ParentElement as _, Pixels, Point, PromptLevel, Render, StatefulInteractive,
StatefulInteractivity, StatelessInteractive, Styled, Task, UniformListScrollHandle, View, StatefulInteractivity, StatelessInteractive, Styled, Task, UniformListScrollHandle, View,
@ -31,7 +31,7 @@ use std::{
sync::Arc, sync::Arc,
}; };
use theme::ActiveTheme as _; use theme::ActiveTheme as _;
use ui::{h_stack, v_stack, Label}; use ui::{h_stack, v_stack, IconElement, Label};
use unicase::UniCase; use unicase::UniCase;
use util::{maybe, TryFutureExt}; use util::{maybe, TryFutureExt};
use workspace::{ use workspace::{
@ -1353,14 +1353,7 @@ impl ProjectPanel {
h_stack() h_stack()
.child(if let Some(icon) = &details.icon { .child(if let Some(icon) = &details.icon {
div().child( div().child(IconElement::from_path(icon.to_string()))
// todo!() Marshall: Can we use our `IconElement` component here?
svg()
.size(rems(0.9375))
.flex_none()
.path(icon.to_string())
.text_color(cx.theme().colors().icon),
)
} else { } else {
div() div()
}) })

View file

@ -129,7 +129,7 @@ impl Icon {
#[derive(Component)] #[derive(Component)]
pub struct IconElement { pub struct IconElement {
icon: Icon, path: SharedString,
color: TextColor, color: TextColor,
size: IconSize, size: IconSize,
} }
@ -137,7 +137,15 @@ pub struct IconElement {
impl IconElement { impl IconElement {
pub fn new(icon: Icon) -> Self { pub fn new(icon: Icon) -> Self {
Self { Self {
icon, path: icon.path().into(),
color: TextColor::default(),
size: IconSize::default(),
}
}
pub fn from_path(path: impl Into<SharedString>) -> Self {
Self {
path: path.into(),
color: TextColor::default(), color: TextColor::default(),
size: IconSize::default(), size: IconSize::default(),
} }
@ -162,7 +170,7 @@ impl IconElement {
svg() svg()
.size(svg_size) .size(svg_size)
.flex_none() .flex_none()
.path(self.icon.path()) .path(self.path)
.text_color(self.color.color(cx)) .text_color(self.color.color(cx))
} }
} }