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