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
77
88 use super::button_icon::ButtonIcon;
99
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.
1111 ///
1212 /// Common buttons:
1313 /// - Label, Icon + Label: [Button] (this component)
@@ -19,7 +19,8 @@ use super::button_icon::ButtonIcon; · 5 unmodified lines
1919 ///
2020 /// # Examples
2121 ///
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.
2324 ///
2425 /// ```
2526 /// 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
22
33 use crate::{prelude::*, LabelCommon, LabelLike, LabelSize, LineHeightStyle};
44
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+/// ```
527 #[derive(IntoElement)]
628 pub struct Label {
729 base: LabelLike,
@@ -9,6 +31,13 @@ pub struct Label { · 1 unmodified line
931 }
1032
1133 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+ /// ```
1241 pub fn new(label: impl Into<SharedString>) -> Self {
1342 Self {
1443 base: LabelLike::new(),
@@ -18,26 +47,53 @@ impl Label { · 3 unmodified lines
1847 }
1948
2049 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+ /// ```
2157 fn size(mut self, size: LabelSize) -> Self {
2258 self.base = self.base.size(size);
2359 self
2460 }
2561
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+ /// ```
2669 fn line_height_style(mut self, line_height_style: LineHeightStyle) -> Self {
2770 self.base = self.base.line_height_style(line_height_style);
2871 self
2972 }
3073
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+ /// ```
3181 fn color(mut self, color: Color) -> Self {
3282 self.base = self.base.color(color);
3383 self
3484 }
3585
86+ /// Sets the strikethrough property of the label.
87+ ///
88+ /// # Examples
89+ ///
90+ /// ```
91+ /// let my_label = Label::new("Hello, World!").strikethrough(true);
92+ /// ```
3693 fn strikethrough(mut self, strikethrough: bool) -> Self {
3794 self.base = self.base.strikethrough(strikethrough);
3895 self
3996 }
40−}
4197
4298 impl RenderOnce for Label {
4399 fn render(self, _cx: &mut WindowContext) -> impl IntoElement {