1use editor::{Editor, EditorElement, EditorStyle};
2use gpui::{TextStyle, View};
3use settings::Settings;
4use theme::ThemeSettings;
5use ui::prelude::*;
6
7pub struct MessageEditor {
8 editor: View<Editor>,
9}
10
11impl MessageEditor {
12 pub fn new(cx: &mut ViewContext<Self>) -> Self {
13 Self {
14 editor: cx.new_view(|cx| {
15 let mut editor = Editor::auto_height(80, cx);
16 editor.set_placeholder_text("Ask anything…", cx);
17
18 editor
19 }),
20 }
21 }
22}
23
24impl Render for MessageEditor {
25 fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
26 let font_size = TextSize::Default.rems(cx);
27 let line_height = font_size.to_pixels(cx.rem_size()) * 1.3;
28
29 v_flex()
30 .size_full()
31 .gap_2()
32 .p_2()
33 .bg(cx.theme().colors().editor_background)
34 .child({
35 let settings = ThemeSettings::get_global(cx);
36 let text_style = TextStyle {
37 color: cx.theme().colors().editor_foreground,
38 font_family: settings.ui_font.family.clone(),
39 font_features: settings.ui_font.features.clone(),
40 font_size: font_size.into(),
41 font_weight: settings.ui_font.weight,
42 line_height: line_height.into(),
43 ..Default::default()
44 };
45
46 EditorElement::new(
47 &self.editor,
48 EditorStyle {
49 background: cx.theme().colors().editor_background,
50 local_player: cx.theme().players().local(),
51 text: text_style,
52 ..Default::default()
53 },
54 )
55 })
56 .child(
57 h_flex()
58 .justify_between()
59 .child(
60 h_flex().child(
61 Button::new("add-context", "Add Context")
62 .style(ButtonStyle::Filled)
63 .icon(IconName::Plus)
64 .icon_position(IconPosition::Start),
65 ),
66 )
67 .child(
68 h_flex()
69 .gap_2()
70 .child(Button::new("codebase", "Codebase").style(ButtonStyle::Filled))
71 .child(Label::new("or"))
72 .child(Button::new("chat", "Chat").style(ButtonStyle::Filled)),
73 ),
74 )
75 }
76}