mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-04 07:29:32 +00:00
Document components/avatar
Co-Authored-By: Antonio Scandurra <me@as-cii.com>
This commit is contained in:
parent
9747c10ce8
commit
5359762051
1 changed files with 27 additions and 0 deletions
|
@ -8,6 +8,16 @@ pub enum Shape {
|
||||||
RoundedRectangle,
|
RoundedRectangle,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// An element that renders a user avatar with customizable appearance options.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// Avatar::new("path/to/image.png")
|
||||||
|
/// .shape(Shape::Circle)
|
||||||
|
/// .grayscale(true)
|
||||||
|
/// .border_color(cx.theme().colors().border)
|
||||||
|
/// ```
|
||||||
#[derive(IntoElement)]
|
#[derive(IntoElement)]
|
||||||
pub struct Avatar {
|
pub struct Avatar {
|
||||||
image: Img,
|
image: Img,
|
||||||
|
@ -66,6 +76,16 @@ impl Avatar {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the shape of the avatar image.
|
||||||
|
///
|
||||||
|
/// This method allows the shape of the avatar to be specified using the [Shape] enum.
|
||||||
|
/// It modifies the corner radius of the image to match the specified shape.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// Avatar::new("path/to/image.png").shape(Shape::Circle);
|
||||||
|
/// ```
|
||||||
pub fn shape(mut self, shape: Shape) -> Self {
|
pub fn shape(mut self, shape: Shape) -> Self {
|
||||||
self.image = match shape {
|
self.image = match shape {
|
||||||
Shape::Circle => self.image.rounded_full(),
|
Shape::Circle => self.image.rounded_full(),
|
||||||
|
@ -74,6 +94,13 @@ impl Avatar {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Applies a grayscale filter to the avatar image.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// let avatar = Avatar::new("path/to/image.png").grayscale(true);
|
||||||
|
/// ```
|
||||||
pub fn grayscale(mut self, grayscale: bool) -> Self {
|
pub fn grayscale(mut self, grayscale: bool) -> Self {
|
||||||
self.image = self.image.grayscale(grayscale);
|
self.image = self.image.grayscale(grayscale);
|
||||||
self
|
self
|
||||||
|
|
Loading…
Reference in a new issue