Merge branch 'gpui2-ui' into gpui2

This commit is contained in:
Marshall Bowers 2023-10-13 17:44:28 -04:00
commit 5e43c332f1
5 changed files with 63 additions and 21 deletions

View file

@ -1,20 +1,47 @@
use crate::prelude::*;
use crate::EditorPane;
use gpui3::{view, Context, View};
#[derive(Element)]
#[element(view_state = "EditorPane")]
pub struct BufferSearch {}
use crate::prelude::*;
use crate::{h_stack, Icon, IconButton, IconColor, Input};
pub struct BufferSearch {
is_replace_open: bool,
}
impl BufferSearch {
pub fn new() -> Self {
Self {}
Self {
is_replace_open: false,
}
}
fn render(
&mut self,
_view: &mut EditorPane,
cx: &mut ViewContext<EditorPane>,
) -> impl Element<ViewState = EditorPane> {
div().child("This is where Buffer Search goes.")
fn toggle_replace(&mut self, cx: &mut ViewContext<Self>) {
self.is_replace_open = !self.is_replace_open;
cx.notify();
}
pub fn view(cx: &mut WindowContext) -> View<Self> {
let theme = theme(cx);
view(cx.entity(|cx| Self::new()), Self::render)
}
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element<ViewState = Self> {
let theme = theme(cx);
h_stack()
.fill(theme.highest.base.default.background)
.p_2()
.child(
h_stack()
.child(Input::new("Search (↑/↓ for previous/next query)"))
.child(
IconButton::<Self>::new(Icon::Replace)
.when(self.is_replace_open, |this| this.color(IconColor::Accent))
.on_click(|buffer_search, cx| {
buffer_search.toggle_replace(cx);
}),
),
)
}
}

View file

@ -14,11 +14,13 @@ pub struct EditorPane {
path: PathBuf,
symbols: Vec<Symbol>,
buffer: Buffer<Self>,
buffer_search: View<BufferSearch>,
is_buffer_search_open: bool,
}
impl EditorPane {
pub fn new(
cx: &mut WindowContext,
tabs: Vec<Tab<Self>>,
path: PathBuf,
symbols: Vec<Symbol>,
@ -29,6 +31,7 @@ impl EditorPane {
path,
symbols,
buffer,
buffer_search: BufferSearch::view(cx),
is_buffer_search_open: false,
}
}
@ -43,7 +46,7 @@ impl EditorPane {
let theme = theme(cx);
view(
cx.entity(|cx| hello_world_rust_editor_with_status_example(&theme)),
cx.entity(|cx| hello_world_rust_editor_with_status_example(cx)),
Self::render,
)
}
@ -69,7 +72,7 @@ impl EditorPane {
IconButton::new(Icon::MagicWand),
]),
)
.children(Some(BufferSearch::new()).filter(|_| self.is_buffer_search_open))
.children(Some(self.buffer_search.clone()).filter(|_| self.is_buffer_search_open))
.child(self.buffer.clone())
}
}