Remove avatar shape (#18810)
This PR re-removes `AvatarShape` as it is unused. The previous time it was removed incorrectly, resulting in square avatars! Release Notes: - N/A
This commit is contained in:
parent
25a97a6a2b
commit
65c9b15796
1 changed files with 4 additions and 40 deletions
|
@ -2,16 +2,6 @@ use crate::prelude::*;
|
||||||
|
|
||||||
use gpui::{img, AnyElement, Hsla, ImageSource, Img, IntoElement, Styled};
|
use gpui::{img, AnyElement, Hsla, ImageSource, Img, IntoElement, Styled};
|
||||||
|
|
||||||
/// The shape of an [`Avatar`].
|
|
||||||
#[derive(Debug, Default, PartialEq, Clone)]
|
|
||||||
pub enum AvatarShape {
|
|
||||||
/// The avatar is shown in a circle.
|
|
||||||
#[default]
|
|
||||||
Circle,
|
|
||||||
/// The avatar is shown in a rectangle with rounded corners.
|
|
||||||
RoundedRectangle,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// An element that renders a user avatar with customizable appearance options.
|
/// An element that renders a user avatar with customizable appearance options.
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
|
@ -43,27 +33,6 @@ impl Avatar {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the shape of the avatar image.
|
|
||||||
///
|
|
||||||
/// This method allows the shape of the avatar to be specified using an [`AvatarShape`].
|
|
||||||
/// It modifies the corner radius of the image to match the specified shape.
|
|
||||||
///
|
|
||||||
/// # Examples
|
|
||||||
///
|
|
||||||
/// ```
|
|
||||||
/// use ui::{Avatar, AvatarShape};
|
|
||||||
///
|
|
||||||
/// Avatar::new("path/to/image.png").shape(AvatarShape::Circle);
|
|
||||||
/// ```
|
|
||||||
///
|
|
||||||
pub fn shape(mut self, shape: AvatarShape) -> Self {
|
|
||||||
self.image = match shape {
|
|
||||||
AvatarShape::Circle => self.image.rounded_full(),
|
|
||||||
AvatarShape::RoundedRectangle => self.image.rounded_md(),
|
|
||||||
};
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Applies a grayscale filter to the avatar image.
|
/// Applies a grayscale filter to the avatar image.
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
|
@ -102,11 +71,7 @@ impl Avatar {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RenderOnce for Avatar {
|
impl RenderOnce for Avatar {
|
||||||
fn render(mut self, cx: &mut WindowContext) -> impl IntoElement {
|
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
||||||
if self.image.style().corner_radii.top_left.is_none() {
|
|
||||||
self = self.shape(AvatarShape::Circle);
|
|
||||||
}
|
|
||||||
|
|
||||||
let border_width = if self.border_color.is_some() {
|
let border_width = if self.border_color.is_some() {
|
||||||
px(2.)
|
px(2.)
|
||||||
} else {
|
} else {
|
||||||
|
@ -118,16 +83,15 @@ impl RenderOnce for Avatar {
|
||||||
|
|
||||||
div()
|
div()
|
||||||
.size(container_size)
|
.size(container_size)
|
||||||
.map(|mut div| {
|
.rounded_full()
|
||||||
div.style().corner_radii = self.image.style().corner_radii.clone();
|
.overflow_hidden()
|
||||||
div
|
|
||||||
})
|
|
||||||
.when_some(self.border_color, |this, color| {
|
.when_some(self.border_color, |this, color| {
|
||||||
this.border(border_width).border_color(color)
|
this.border(border_width).border_color(color)
|
||||||
})
|
})
|
||||||
.child(
|
.child(
|
||||||
self.image
|
self.image
|
||||||
.size(image_size)
|
.size(image_size)
|
||||||
|
.rounded_full()
|
||||||
.bg(cx.theme().colors().ghost_element_background),
|
.bg(cx.theme().colors().ghost_element_background),
|
||||||
)
|
)
|
||||||
.children(self.indicator.map(|indicator| div().child(indicator)))
|
.children(self.indicator.map(|indicator| div().child(indicator)))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue