Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
ui: Add `inline_code` method to label (#29306)
Danilo Lealba3d82629e5b
diff --git a/crates/agent/src/ui/animated_label.rs b/crates/agent/src/ui/animated_label.rsindex c08d11e9931..c2b4107730d 100644--- a/crates/agent/src/ui/animated_label.rs+++ b/crates/agent/src/ui/animated_label.rs@@ -73,6 +73,11 @@ impl LabelCommon for AnimatedLabel {self.base = self.base.buffer_font(cx);self}++ fn inline_code(mut self, cx: &App) -> Self {+ self.base = self.base.inline_code(cx);+ self+ }}impl RenderOnce for AnimatedLabel {diff --git a/crates/ui/src/components/label/highlighted_label.rs b/crates/ui/src/components/label/highlighted_label.rsindex 1a6cd89d15a..72f54e08da8 100644--- a/crates/ui/src/components/label/highlighted_label.rs+++ b/crates/ui/src/components/label/highlighted_label.rs@@ -78,6 +78,11 @@ impl LabelCommon for HighlightedLabel {self.base = self.base.buffer_font(cx);self}++ fn inline_code(mut self, cx: &App) -> Self {+ self.base = self.base.inline_code(cx);+ self+ }}pub fn highlight_ranges(diff --git a/crates/ui/src/components/label/label.rs b/crates/ui/src/components/label/label.rsindex b278e6dab8b..019ece023e5 100644--- a/crates/ui/src/components/label/label.rs+++ b/crates/ui/src/components/label/label.rs@@ -189,6 +189,12 @@ impl LabelCommon for Label {self.base = self.base.buffer_font(cx);self}++ /// Styles the label to look like inline code.+ fn inline_code(mut self, cx: &App) -> Self {+ self.base = self.base.inline_code(cx);+ self+ }}impl RenderOnce for Label {@@ -206,7 +212,7 @@ impl Component for Label {Some("A text label component that supports various styles, sizes, and formatting options.")}- fn preview(_window: &mut Window, _cx: &mut App) -> Option<AnyElement> {+ fn preview(_window: &mut Window, cx: &mut App) -> Option<AnyElement> {Some(v_flex().gap_6()@@ -235,6 +241,7 @@ impl Component for Label {single_example("Italic", Label::new("Code Comment").italic().into_any_element()),single_example("Strikethrough", Label::new("Deprecated Feature").strikethrough().into_any_element()),single_example("Underline", Label::new("Clickable Link").underline().into_any_element()),+ single_example("Inline Code", Label::new("fn main() {}").inline_code(cx).into_any_element()),],),example_group_with_title(diff --git a/crates/ui/src/components/label/label_like.rs b/crates/ui/src/components/label/label_like.rsindex d0a981ae1c1..1fa6b14c83d 100644--- a/crates/ui/src/components/label/label_like.rs+++ b/crates/ui/src/components/label/label_like.rs@@ -64,6 +64,9 @@ pub trait LabelCommon {/// Sets the font to the buffer'sfn buffer_font(self, cx: &App) -> Self;++ /// Styles the label to look like inline code.+ fn inline_code(self, cx: &App) -> Self;}/// A label-like element that can be used to create a custom label when@@ -183,6 +186,16 @@ impl LabelCommon for LabelLike {.font(theme::ThemeSettings::get_global(cx).buffer_font.clone());self}++ fn inline_code(mut self, cx: &App) -> Self {+ self.base = self+ .base+ .font(theme::ThemeSettings::get_global(cx).buffer_font.clone())+ .bg(cx.theme().colors().element_background)+ .rounded_sm()+ .px_0p5();+ self+ }}impl ParentElement for LabelLike {@@ -248,7 +261,7 @@ impl Component for LabelLike {)}- fn preview(_window: &mut Window, _cx: &mut App) -> Option<AnyElement> {+ fn preview(_window: &mut Window, cx: &mut App) -> Option<AnyElement> {Some(v_flex().gap_6()@@ -269,6 +282,7 @@ impl Component for LabelLike {single_example("Italic", LabelLike::new().italic().child("Italic text").into_any_element()),single_example("Underline", LabelLike::new().underline().child("Underlined text").into_any_element()),single_example("Strikethrough", LabelLike::new().strikethrough().child("Strikethrough text").into_any_element()),+ single_example("Inline Code", LabelLike::new().inline_code(cx).child("const value = 42;").into_any_element()),],),example_group_with_title(