Rename Shape to AvatarShape (#3986)

This PR renames the `Shape` enum to `AvatarShape`, since it seems pretty
specific to `Avatar`s.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-01-09 16:21:27 -05:00 committed by GitHub
parent 7ed3f5f392
commit a579ef17d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,10 +1,13 @@
use crate::prelude::*; use crate::prelude::*;
use gpui::{img, Hsla, ImageSource, Img, IntoElement, Styled}; use gpui::{img, Hsla, ImageSource, Img, IntoElement, Styled};
/// The shape of an [`Avatar`].
#[derive(Debug, Default, PartialEq, Clone)] #[derive(Debug, Default, PartialEq, Clone)]
pub enum Shape { pub enum AvatarShape {
/// The avatar is shown in a circle.
#[default] #[default]
Circle, Circle,
/// The avatar is shown in a rectangle with rounded corners.
RoundedRectangle, RoundedRectangle,
} }
@ -14,7 +17,7 @@ pub enum Shape {
/// ///
/// ``` /// ```
/// Avatar::new("path/to/image.png") /// Avatar::new("path/to/image.png")
/// .shape(Shape::Circle) /// .shape(AvatarShape::Circle)
/// .grayscale(true) /// .grayscale(true)
/// .border_color(cx.theme().colors().border) /// .border_color(cx.theme().colors().border)
/// ``` /// ```
@ -28,7 +31,7 @@ pub struct Avatar {
impl RenderOnce for Avatar { impl RenderOnce for Avatar {
fn render(mut self, cx: &mut WindowContext) -> impl IntoElement { fn render(mut self, cx: &mut WindowContext) -> impl IntoElement {
if self.image.style().corner_radii.top_left.is_none() { if self.image.style().corner_radii.top_left.is_none() {
self = self.shape(Shape::Circle); self = self.shape(AvatarShape::Circle);
} }
let size = cx.rem_size(); let size = cx.rem_size();
@ -84,12 +87,12 @@ impl Avatar {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// Avatar::new("path/to/image.png").shape(Shape::Circle); /// Avatar::new("path/to/image.png").shape(AvatarShape::Circle);
/// ``` /// ```
pub fn shape(mut self, shape: Shape) -> Self { pub fn shape(mut self, shape: AvatarShape) -> Self {
self.image = match shape { self.image = match shape {
Shape::Circle => self.image.rounded_full(), AvatarShape::Circle => self.image.rounded_full(),
Shape::RoundedRectangle => self.image.rounded_md(), AvatarShape::RoundedRectangle => self.image.rounded_md(),
}; };
self self
} }