pub struct Icon { /* private fields */ }Expand description
A GPUI component that renders a typed Phosphor icon through GPUI’s svg()
element.
The component defaults to the first enabled weight, a 16px square, and the
current GPUI text color. Use Icon::try_new or Icon::try_with_weight
when a disabled weight should be reported before the component is rendered.
Implementations§
Source§impl Icon
impl Icon
Sourcepub fn new(name: IconName) -> Self
pub fn new(name: IconName) -> Self
Create an icon using the first enabled weight.
Examples found in repository?
10 fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
11 div()
12 .flex()
13 .gap_4()
14 .size_full()
15 .justify_center()
16 .items_center()
17 .bg(rgb(0x17171b))
18 .child(
19 Icon::new(IconName::Heart)
20 .size(px(48.0))
21 .color(rgb(0xf472b6)),
22 )
23 .child(
24 Icon::new(IconName::Star)
25 .size(px(48.0))
26 .color(rgb(0xfacc15)),
27 )
28 .child(
29 Icon::new(IconName::Rocket)
30 .weight(Weight::Regular)
31 .size(px(48.0))
32 .color(rgb(0x60a5fa)),
33 )
34 .child(
35 Icon::new(IconName::Pulse)
36 .size(px(48.0))
37 .color(rgb(0x34d399)),
38 )
39 }Sourcepub fn try_new(name: IconName, weight: Weight) -> Result<Self, IconError>
pub fn try_new(name: IconName, weight: Weight) -> Result<Self, IconError>
Create an icon and validate that its weight is enabled.
Sourcepub const fn icon_weight(&self) -> Weight
pub const fn icon_weight(&self) -> Weight
Return the selected visual weight.
Sourcepub fn weight(self, weight: Weight) -> Self
pub fn weight(self, weight: Weight) -> Self
Set the visual weight without validating its feature flag.
Use Icon::try_with_weight when invalid feature configuration should
be handled as a Result.
Examples found in repository?
10 fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
11 div()
12 .flex()
13 .gap_4()
14 .size_full()
15 .justify_center()
16 .items_center()
17 .bg(rgb(0x17171b))
18 .child(
19 Icon::new(IconName::Heart)
20 .size(px(48.0))
21 .color(rgb(0xf472b6)),
22 )
23 .child(
24 Icon::new(IconName::Star)
25 .size(px(48.0))
26 .color(rgb(0xfacc15)),
27 )
28 .child(
29 Icon::new(IconName::Rocket)
30 .weight(Weight::Regular)
31 .size(px(48.0))
32 .color(rgb(0x60a5fa)),
33 )
34 .child(
35 Icon::new(IconName::Pulse)
36 .size(px(48.0))
37 .color(rgb(0x34d399)),
38 )
39 }Sourcepub fn try_with_weight(self, weight: Weight) -> Result<Self, IconError>
pub fn try_with_weight(self, weight: Weight) -> Result<Self, IconError>
Set the visual weight and validate that it is enabled.
Sourcepub fn size(self, size: impl Into<Pixels>) -> Self
pub fn size(self, size: impl Into<Pixels>) -> Self
Set the rendered square size.
Examples found in repository?
10 fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
11 div()
12 .flex()
13 .gap_4()
14 .size_full()
15 .justify_center()
16 .items_center()
17 .bg(rgb(0x17171b))
18 .child(
19 Icon::new(IconName::Heart)
20 .size(px(48.0))
21 .color(rgb(0xf472b6)),
22 )
23 .child(
24 Icon::new(IconName::Star)
25 .size(px(48.0))
26 .color(rgb(0xfacc15)),
27 )
28 .child(
29 Icon::new(IconName::Rocket)
30 .weight(Weight::Regular)
31 .size(px(48.0))
32 .color(rgb(0x60a5fa)),
33 )
34 .child(
35 Icon::new(IconName::Pulse)
36 .size(px(48.0))
37 .color(rgb(0x34d399)),
38 )
39 }Sourcepub fn color(self, color: impl Into<Hsla>) -> Self
pub fn color(self, color: impl Into<Hsla>) -> Self
Set the SVG’s color. If omitted, GPUI’s current text color is used.
Examples found in repository?
10 fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
11 div()
12 .flex()
13 .gap_4()
14 .size_full()
15 .justify_center()
16 .items_center()
17 .bg(rgb(0x17171b))
18 .child(
19 Icon::new(IconName::Heart)
20 .size(px(48.0))
21 .color(rgb(0xf472b6)),
22 )
23 .child(
24 Icon::new(IconName::Star)
25 .size(px(48.0))
26 .color(rgb(0xfacc15)),
27 )
28 .child(
29 Icon::new(IconName::Rocket)
30 .weight(Weight::Regular)
31 .size(px(48.0))
32 .color(rgb(0x60a5fa)),
33 )
34 .child(
35 Icon::new(IconName::Pulse)
36 .size(px(48.0))
37 .color(rgb(0x34d399)),
38 )
39 }Sourcepub fn text_color(self, color: impl Into<Hsla>) -> Self
pub fn text_color(self, color: impl Into<Hsla>) -> Self
Set the SVG’s color. This is an alias for Icon::color.
Sourcepub const fn icon_color(&self) -> Option<Hsla>
pub const fn icon_color(&self) -> Option<Hsla>
Return the explicitly configured color, if there is one.
Sourcepub fn path(&self) -> Result<SharedString, IconError>
pub fn path(&self) -> Result<SharedString, IconError>
Resolve the selected icon to its namespaced GPUI asset path.
Trait Implementations§
Source§impl IntoElement for Icon
impl IntoElement for Icon
Source§type Element = Component<Icon>
type Element = Component<Icon>
Source§fn into_element(self) -> Self::Element
fn into_element(self) -> Self::Element
Element.Source§fn into_any_element(self) -> AnyElement
fn into_any_element(self) -> AnyElement
AnyElement.Source§impl RenderOnce for Icon
impl RenderOnce for Icon
Source§fn render(self, window: &mut Window, _cx: &mut App) -> impl IntoElement
fn render(self, window: &mut Window, _cx: &mut App) -> impl IntoElement
Render::render() method
which takes a mutable reference.Auto Trait Implementations§
impl Freeze for Icon
impl RefUnwindSafe for Icon
impl Send for Icon
impl Sync for Icon
impl Unpin for Icon
impl UnsafeUnpin for Icon
impl UnwindSafe for Icon
Blanket Implementations§
Source§impl<E> AnimationExt for Ewhere
E: IntoElement + 'static,
impl<E> AnimationExt for Ewhere
E: IntoElement + 'static,
Source§fn with_animation(
self,
id: impl Into<ElementId>,
animation: Animation,
animator: impl Fn(Self, f32) -> Self + 'static,
) -> AnimationElement<Self>where
Self: Sized,
fn with_animation(
self,
id: impl Into<ElementId>,
animation: Animation,
animator: impl Fn(Self, f32) -> Self + 'static,
) -> AnimationElement<Self>where
Self: Sized,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> FluentBuilder for Twhere
T: IntoElement,
impl<T> FluentBuilder for Twhere
T: IntoElement,
Source§fn map<U>(self, f: impl FnOnce(Self) -> U) -> Uwhere
Self: Sized,
fn map<U>(self, f: impl FnOnce(Self) -> U) -> Uwhere
Self: Sized,
Source§fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Selfwhere
Self: Sized,
fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Selfwhere
Self: Sized,
Source§fn when_else(
self,
condition: bool,
then: impl FnOnce(Self) -> Self,
else_fn: impl FnOnce(Self) -> Self,
) -> Selfwhere
Self: Sized,
fn when_else(
self,
condition: bool,
then: impl FnOnce(Self) -> Self,
else_fn: impl FnOnce(Self) -> Self,
) -> Selfwhere
Self: Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more