1use gpui::prelude::*;
12use gpui::{div, px, App, IntoElement, SharedString, Window};
13
14use crate::devtools::Probed;
15use crate::theme::{theme, ColorName, Size};
16
17#[derive(IntoElement)]
22pub struct Mark {
23 content: SharedString,
24 color: ColorName,
25 size: Option<Size>,
26}
27
28impl Mark {
29 pub fn new(content: impl Into<SharedString>) -> Self {
30 Mark {
31 content: content.into(),
32 color: ColorName::Yellow,
33 size: None,
34 }
35 }
36
37 pub fn color(mut self, color: ColorName) -> Self {
39 self.color = color;
40 self
41 }
42
43 pub fn size(mut self, size: Size) -> Self {
45 self.size = Some(size);
46 self
47 }
48}
49
50impl RenderOnce for Mark {
51 fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
52 let t = theme(cx);
53 let bg = if t.scheme.is_dark() {
56 t.color(self.color, 5).alpha(0.35)
57 } else {
58 t.color(self.color, 2).hsla()
59 };
60 let fg = t.text().hsla();
61
62 let mut el = div()
63 .px(px(4.0))
64 .rounded(px(t.radius(Size::Xs)))
65 .bg(bg)
66 .text_color(fg)
67 .child(self.content);
68 if let Some(size) = self.size {
69 el = el.text_size(px(t.font_size(size)));
70 }
71 el.probe("Mark")
72 }
73}