History

Add label docs

Nate Butler committed 2 years ago

Commit 7dbe0511 parent 324fd242 files · +60 −3Browse files

Unified · Split

2 files
  1. crates/ui/src/components/button/button.rs +3 −2
  2. crates/ui/src/components/label/label.rs +57 −1
crates/ui/src/components/button/button.rs+3−2
@@ -7,7 +7,7 @@ use crate::{ · 6 unmodified lines
7 7
8use super::button_icon::ButtonIcon;8use super::button_icon::ButtonIcon;
9 9
10/// [Button] can be use to create a button with a label and an optional icon.10/// An element that creates a button with a label and an optional icon.
11///11///
12/// Common buttons:12/// Common buttons:
13/// - Label, Icon + Label: [Button] (this component)13/// - Label, Icon + Label: [Button] (this component)
@@ -19,7 +19,8 @@ use super::button_icon::ButtonIcon; · 5 unmodified lines
19///19///
20/// # Examples20/// # Examples
21///21///
22/// A button with a label only:22/// **A button with a label**, is typically used in scenarios such as a form, where the button's label
23/// indicates what action will be performed when the button is clicked.
23///24///
24/// ```25/// ```
25/// Button::new("button_id", "Click me!")26/// Button::new("button_id", "Click me!")
crates/ui/src/components/label/label.rs+57−1
@@ -2,6 +2,28 @@ use gpui::WindowContext; · 1 unmodified line
2 2
3use crate::{prelude::*, LabelCommon, LabelLike, LabelSize, LineHeightStyle};3use 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)]
6pub struct Label {28pub struct Label {
7 base: LabelLike,29 base: LabelLike,
@@ -9,6 +31,13 @@ pub struct Label { · 1 unmodified line
9}31}
10 32
11impl Label {33impl 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
20impl LabelCommon for Label {49impl 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 self59 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 self71 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 self83 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 self95 self
39 }96 }
40}
41 97
42impl RenderOnce for Label {98impl RenderOnce for Label {
43 fn render(self, _cx: &mut WindowContext) -> impl IntoElement {99 fn render(self, _cx: &mut WindowContext) -> impl IntoElement {