Clean up Indicator (#11275)

This PR cleans up the `Indicator` component:

- Renamed `IndicatorStyle` to `IndicatorKind` and made it private.
- Fixed `Indicator::bar()` to construct an indicator using the right
`IndicatorKind`.
- Removed the `IndicatorIcon`, since we didn't actually end up using it.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-05-01 18:10:35 -04:00 committed by GitHub
parent fa0253bc5a
commit 74f8ef0364
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,9 +1,7 @@
use gpui::Transformation;
use crate::{prelude::*, AnyIcon}; use crate::{prelude::*, AnyIcon};
#[derive(Default)] #[derive(Default)]
pub enum IndicatorStyle { enum IndicatorKind {
#[default] #[default]
Dot, Dot,
Bar, Bar,
@ -12,28 +10,28 @@ pub enum IndicatorStyle {
#[derive(IntoElement)] #[derive(IntoElement)]
pub struct Indicator { pub struct Indicator {
style: IndicatorStyle, kind: IndicatorKind,
pub color: Color, pub color: Color,
} }
impl Indicator { impl Indicator {
pub fn dot() -> Self { pub fn dot() -> Self {
Self { Self {
style: IndicatorStyle::Dot, kind: IndicatorKind::Dot,
color: Color::Default, color: Color::Default,
} }
} }
pub fn bar() -> Self { pub fn bar() -> Self {
Self { Self {
style: IndicatorStyle::Dot, kind: IndicatorKind::Bar,
color: Color::Default, color: Color::Default,
} }
} }
pub fn icon(icon: impl Into<AnyIcon>) -> Self { pub fn icon(icon: impl Into<AnyIcon>) -> Self {
Self { Self {
style: IndicatorStyle::Icon(icon.into()), kind: IndicatorKind::Icon(icon.into()),
color: Color::Default, color: Color::Default,
} }
} }
@ -48,15 +46,15 @@ impl RenderOnce for Indicator {
fn render(self, cx: &mut WindowContext) -> impl IntoElement { fn render(self, cx: &mut WindowContext) -> impl IntoElement {
let container = div().flex_none(); let container = div().flex_none();
match self.style { match self.kind {
IndicatorStyle::Icon(icon) => container IndicatorKind::Icon(icon) => container
.child(icon.map(|icon| icon.custom_size(rems_from_px(8.)).color(self.color))), .child(icon.map(|icon| icon.custom_size(rems_from_px(8.)).color(self.color))),
IndicatorStyle::Dot => container IndicatorKind::Dot => container
.w_1p5() .w_1p5()
.h_1p5() .h_1p5()
.rounded_full() .rounded_full()
.bg(self.color.color(cx)), .bg(self.color.color(cx)),
IndicatorStyle::Bar => container IndicatorKind::Bar => container
.w_full() .w_full()
.h_1p5() .h_1p5()
.rounded_t_md() .rounded_t_md()
@ -64,33 +62,3 @@ impl RenderOnce for Indicator {
} }
} }
} }
#[derive(IntoElement)]
pub struct IndicatorIcon {
icon: Icon,
transformation: Option<Transformation>,
}
impl IndicatorIcon {
pub fn new(icon: Icon) -> Self {
Self {
icon,
transformation: None,
}
}
pub fn transformation(mut self, transformation: Transformation) -> Self {
self.transformation = Some(transformation);
self
}
}
impl RenderOnce for IndicatorIcon {
fn render(self, _cx: &mut WindowContext) -> impl IntoElement {
self.icon
.custom_size(rems_from_px(8.))
.when_some(self.transformation, |this, transformation| {
this.transform(transformation)
})
}
}