| @@ -2,6 +2,28 @@ use gpui::WindowContext; · 1 unmodified line |
| 2 | | 2 | |
| 3 | use crate::{prelude::*, LabelCommon, LabelLike, LabelSize, LineHeightStyle}; | 3 | use crate::{prelude::*, LabelCommon, LabelLike, LabelSize, LineHeightStyle}; |
| 4 | | 4 | |
| | 5 | /// A struct representing a label element in the UI. |
| | 6 | /// |
| | 7 | /// The `Label` struct stores the label text and common properties for a label element. |
| | 8 | /// It provides methods for modifying these properties. |
| | 9 | /// |
| | 10 | /// # Examples |
| | 11 | /// |
| | 12 | /// ``` |
| | 13 | /// Label::new("Hello, World!") |
| | 14 | /// ``` |
| | 15 | /// |
| | 16 | /// **A colored label**, for example labeling a dangerous action: |
| | 17 | /// |
| | 18 | /// ``` |
| | 19 | /// let my_label = Label::new("Delete").color(Color::Error); |
| | 20 | /// ``` |
| | 21 | /// |
| | 22 | /// **A label with a strikethrough**, for example labeling something that has been deleted: |
| | 23 | /// |
| | 24 | /// ``` |
| | 25 | /// let my_label = Label::new("Deleted").strikethrough(true); |
| | 26 | /// ``` |
| 5 | #[derive(IntoElement)] | 27 | #[derive(IntoElement)] |
| 6 | pub struct Label { | 28 | pub struct Label { |
| 7 | base: LabelLike, | 29 | base: LabelLike, |
| @@ -9,6 +31,13 @@ pub struct Label { · 1 unmodified line |
| 9 | } | 31 | } |
| 10 | | 32 | |
| 11 | impl Label { | 33 | impl Label { |
| | 34 | /// Create a new `Label` with the given text. |
| | 35 | /// |
| | 36 | /// # Examples |
| | 37 | /// |
| | 38 | /// ``` |
| | 39 | /// let my_label = Label::new("Hello, World!"); |
| | 40 | /// ``` |
| 12 | pub fn new(label: impl Into<SharedString>) -> Self { | 41 | pub fn new(label: impl Into<SharedString>) -> Self { |
| 13 | Self { | 42 | Self { |
| 14 | base: LabelLike::new(), | 43 | base: LabelLike::new(), |
| @@ -18,26 +47,53 @@ impl Label { · 3 unmodified lines |
| 18 | } | 47 | } |
| 19 | | 48 | |
| 20 | impl LabelCommon for Label { | 49 | impl LabelCommon for Label { |
| | 50 | /// Sets the size of the label using a [LabelSize]. |
| | 51 | /// |
| | 52 | /// # Examples |
| | 53 | /// |
| | 54 | /// ``` |
| | 55 | /// let my_label = Label::new("Hello, World!").size(LabelSize::Large); |
| | 56 | /// ``` |
| 21 | fn size(mut self, size: LabelSize) -> Self { | 57 | fn size(mut self, size: LabelSize) -> Self { |
| 22 | self.base = self.base.size(size); | 58 | self.base = self.base.size(size); |
| 23 | self | 59 | self |
| 24 | } | 60 | } |
| 25 | | 61 | |
| | 62 | /// Sets the line height style of the label using a [LineHeightStyle]. |
| | 63 | /// |
| | 64 | /// # Examples |
| | 65 | /// |
| | 66 | /// ``` |
| | 67 | /// let my_label = Label::new("Hello, World!").line_height_style(LineHeightStyle::Normal); |
| | 68 | /// ``` |
| 26 | fn line_height_style(mut self, line_height_style: LineHeightStyle) -> Self { | 69 | fn line_height_style(mut self, line_height_style: LineHeightStyle) -> Self { |
| 27 | self.base = self.base.line_height_style(line_height_style); | 70 | self.base = self.base.line_height_style(line_height_style); |
| 28 | self | 71 | self |
| 29 | } | 72 | } |
| 30 | | 73 | |
| | 74 | /// Sets the color of the label using a [Color]. |
| | 75 | /// |
| | 76 | /// # Examples |
| | 77 | /// |
| | 78 | /// ``` |
| | 79 | /// let my_label = Label::new("Hello, World!").color(Color::Primary); |
| | 80 | /// ``` |
| 31 | fn color(mut self, color: Color) -> Self { | 81 | fn color(mut self, color: Color) -> Self { |
| 32 | self.base = self.base.color(color); | 82 | self.base = self.base.color(color); |
| 33 | self | 83 | self |
| 34 | } | 84 | } |
| 35 | | 85 | |
| | 86 | /// Sets the strikethrough property of the label. |
| | 87 | /// |
| | 88 | /// # Examples |
| | 89 | /// |
| | 90 | /// ``` |
| | 91 | /// let my_label = Label::new("Hello, World!").strikethrough(true); |
| | 92 | /// ``` |
| 36 | fn strikethrough(mut self, strikethrough: bool) -> Self { | 93 | fn strikethrough(mut self, strikethrough: bool) -> Self { |
| 37 | self.base = self.base.strikethrough(strikethrough); | 94 | self.base = self.base.strikethrough(strikethrough); |
| 38 | self | 95 | self |
| 39 | } | 96 | } |
| 40 | } | | |
| 41 | | 97 | |
| 42 | impl RenderOnce for Label { | 98 | impl RenderOnce for Label { |
| 43 | fn render(self, _cx: &mut WindowContext) -> impl IntoElement { | 99 | fn render(self, _cx: &mut WindowContext) -> impl IntoElement { |