label.rs

 1use gpui::WindowContext;
 2
 3use crate::{prelude::*, LabelCommon, LabelLike, LabelSize, LineHeightStyle};
 4
 5#[derive(IntoElement)]
 6pub struct Label {
 7    base: LabelLike,
 8    label: SharedString,
 9}
10
11impl Label {
12    pub fn new(label: impl Into<SharedString>) -> Self {
13        Self {
14            base: LabelLike::new(),
15            label: label.into(),
16        }
17    }
18}
19
20impl LabelCommon for Label {
21    fn size(mut self, size: LabelSize) -> Self {
22        self.base = self.base.size(size);
23        self
24    }
25
26    fn line_height_style(mut self, line_height_style: LineHeightStyle) -> Self {
27        self.base = self.base.line_height_style(line_height_style);
28        self
29    }
30
31    fn color(mut self, color: Color) -> Self {
32        self.base = self.base.color(color);
33        self
34    }
35
36    fn strikethrough(mut self, strikethrough: bool) -> Self {
37        self.base = self.base.strikethrough(strikethrough);
38        self
39    }
40}
41
42impl RenderOnce for Label {
43    type Rendered = LabelLike;
44
45    fn render(self, _cx: &mut WindowContext) -> Self::Rendered {
46        self.base.child(self.label)
47    }
48}