Add indicator component
Co-Authored-By: Marshall Bowers <1486634+maxdeviant@users.noreply.github.com>
This commit is contained in:
co-authored by
Marshall Bowers
parent
eed5a698cf
commit
dccdcd3221
@@ -5,6 +5,7 @@ mod context_menu;
|
|||||||
mod disclosure;
|
mod disclosure;
|
||||||
mod divider;
|
mod divider;
|
||||||
mod icon;
|
mod icon;
|
||||||
|
mod indicator;
|
||||||
mod keybinding;
|
mod keybinding;
|
||||||
mod label;
|
mod label;
|
||||||
mod list;
|
mod list;
|
||||||
@@ -24,6 +25,7 @@ pub use context_menu::*;
|
|||||||
pub use disclosure::*;
|
pub use disclosure::*;
|
||||||
pub use divider::*;
|
pub use divider::*;
|
||||||
pub use icon::*;
|
pub use icon::*;
|
||||||
|
pub use indicator::*;
|
||||||
pub use keybinding::*;
|
pub use keybinding::*;
|
||||||
pub use label::*;
|
pub use label::*;
|
||||||
pub use list::*;
|
pub use list::*;
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
use gpui::{AnyView, Div, Position};
|
||||||
|
|
||||||
|
use crate::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub enum IndicatorStyle {
|
||||||
|
#[default]
|
||||||
|
Dot,
|
||||||
|
Bar,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(IntoElement)]
|
||||||
|
pub struct Indicator {
|
||||||
|
position: Position,
|
||||||
|
style: IndicatorStyle,
|
||||||
|
color: Color,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Indicator {
|
||||||
|
pub fn dot() -> Self {
|
||||||
|
Self {
|
||||||
|
position: Position::Relative,
|
||||||
|
style: IndicatorStyle::Dot,
|
||||||
|
color: Color::Default,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn bar() -> Self {
|
||||||
|
Self {
|
||||||
|
position: Position::Relative,
|
||||||
|
style: IndicatorStyle::Dot,
|
||||||
|
color: Color::Default,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn color(mut self, color: Color) -> Self {
|
||||||
|
self.color = color;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn absolute(mut self) -> Self {
|
||||||
|
self.position = Position::Absolute;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RenderOnce for Indicator {
|
||||||
|
type Rendered = Div;
|
||||||
|
|
||||||
|
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||||
|
div()
|
||||||
|
.map(|this| match self.style {
|
||||||
|
IndicatorStyle::Dot => this.w_1p5().h_1p5().rounded_full(),
|
||||||
|
IndicatorStyle::Bar => this.w_full().h_1p5().rounded_t_md(),
|
||||||
|
})
|
||||||
|
.when(self.position == Position::Absolute, |this| this.absolute())
|
||||||
|
.bg(self.color.color(cx))
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user