1use gpui::{Div, Render, View, VisualContext};
2
3use crate::prelude::*;
4use crate::{h_stack, Icon, IconButton, IconColor, Input};
5
6#[derive(Clone)]
7pub struct BufferSearch {
8 is_replace_open: bool,
9}
10
11impl BufferSearch {
12 pub fn new() -> Self {
13 Self {
14 is_replace_open: false,
15 }
16 }
17
18 fn toggle_replace(&mut self, cx: &mut ViewContext<Self>) {
19 self.is_replace_open = !self.is_replace_open;
20
21 cx.notify();
22 }
23
24 pub fn view(cx: &mut WindowContext) -> View<Self> {
25 cx.build_view(|cx| Self::new())
26 }
27}
28
29impl Render for BufferSearch {
30 type Element = Div<Self>;
31
32 fn render(&mut self, cx: &mut ViewContext<Self>) -> Div<Self> {
33 h_stack()
34 .bg(cx.theme().colors().toolbar_background)
35 .p_2()
36 .child(
37 h_stack().child(Input::new("Search")).child(
38 IconButton::<Self>::new("replace", Icon::Replace)
39 .when(self.is_replace_open, |this| this.color(IconColor::Accent))
40 .on_click(|buffer_search, cx| {
41 buffer_search.toggle_replace(cx);
42 }),
43 ),
44 )
45 }
46}