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