1use gpui2::{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 let theme = theme(cx);
34
35 h_stack().bg(theme.toolbar).p_2().child(
36 h_stack().child(Input::new("Search")).child(
37 IconButton::<Self>::new("replace", Icon::Replace)
38 .when(self.is_replace_open, |this| this.color(IconColor::Accent))
39 .on_click(|buffer_search, cx| {
40 buffer_search.toggle_replace(cx);
41 }),
42 ),
43 )
44 }
45}