pub struct Icon {
pub id: Option<NodeId>,
pub source: IconSource,
pub color: Option<Color>,
pub size: Option<f32>,
pub stroke: Option<Stroke>,
}Expand description
A vector icon rendered from an SVG path, file, or inline SVG content.
Icons default to the theme’s primary text colour and 24x24 layout points.
Use color(), size(), and stroke() to customise.
§Example
ⓘ
// From an SVG path string
Icon::path("M12 2L2 22h20L12 2z")
.size(20.0)
.color(theme.tokens.colors.primary)
// From a file
Icon::file("assets/icons/star.svg").size(16.0)
// From inline SVG
Icon::svg("<svg>...</svg>")Fields§
§id: Option<NodeId>Explicit node identity.
source: IconSourceThe vector graphic source.
color: Option<Color>Fill colour (falls back to the theme’s primary text colour).
size: Option<f32>Layout size in points (default: 24.0).
stroke: Option<Stroke>Optional stroke (when set, the fill is suppressed).
Implementations§
Source§impl Icon
impl Icon
pub fn path(path: impl Into<String>) -> Icon
pub fn file(path: impl Into<String>) -> Icon
pub fn svg(content: impl Into<String>) -> Icon
pub fn new(path: impl Into<String>) -> Icon
pub fn size(self, s: f32) -> Icon
pub fn color(self, c: Color) -> Icon
pub fn stroke(self, s: Stroke) -> Icon
pub fn into_node(self) -> Node
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Icon
impl<'de> Deserialize<'de> for Icon
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Icon, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Icon, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Lower for Icon
impl Lower for Icon
Source§fn lower(&self, cx: &mut LoweringContext<'_>) -> NodeId
fn lower(&self, cx: &mut LoweringContext<'_>) -> NodeId
Lower this widget into the IR, returning the root node id.
Source§impl Serialize for Icon
impl Serialize for Icon
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
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<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
Mutably borrows from an owned value. Read more
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>
Convert
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>
Convert
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)
Convert
&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)
Convert
&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> 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>
Converts
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>
Converts
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