Make command dispatching work

This commit is contained in:
Conrad Irwin 2023-11-09 13:23:30 -07:00
parent a1d9f351db
commit fa153a0d56
11 changed files with 188 additions and 118 deletions

View file

@ -10,6 +10,7 @@ doctest = false
[dependencies]
editor = { package = "editor2", path = "../editor2" }
ui = { package = "ui2", path = "../ui2" }
gpui = { package = "gpui2", path = "../gpui2" }
menu = { package = "menu2", path = "../menu2" }
settings = { package = "settings2", path = "../settings2" }

View file

@ -5,6 +5,8 @@ use gpui::{
WindowContext,
};
use std::cmp;
use theme::ActiveTheme;
use ui::v_stack;
pub struct Picker<D: PickerDelegate> {
pub delegate: D,
@ -133,7 +135,7 @@ impl<D: PickerDelegate> Picker<D> {
impl<D: PickerDelegate> Render for Picker<D> {
type Element = Div<Self, StatefulInteractivity<Self>, FocusEnabled<Self>>;
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
div()
.context("picker")
.id("picker-container")
@ -146,18 +148,33 @@ impl<D: PickerDelegate> Render for Picker<D> {
.on_action(Self::cancel)
.on_action(Self::confirm)
.on_action(Self::secondary_confirm)
.child(self.editor.clone())
.child(
uniform_list("candidates", self.delegate.match_count(), {
move |this: &mut Self, visible_range, cx| {
let selected_ix = this.delegate.selected_index();
visible_range
.map(|ix| this.delegate.render_match(ix, ix == selected_ix, cx))
.collect()
}
})
.track_scroll(self.scroll_handle.clone())
.size_full(),
v_stack().gap_px().child(
v_stack()
.py_0p5()
.px_1()
.child(div().px_2().py_0p5().child(self.editor.clone())),
),
)
.child(
div()
.h_px()
.w_full()
.bg(cx.theme().colors().element_background),
)
.child(
v_stack().py_0p5().px_1().grow().max_h_96().child(
uniform_list("candidates", self.delegate.match_count(), {
move |this: &mut Self, visible_range, cx| {
let selected_ix = this.delegate.selected_index();
visible_range
.map(|ix| this.delegate.render_match(ix, ix == selected_ix, cx))
.collect()
}
})
.track_scroll(self.scroll_handle.clone())
.size_full(),
),
)
}
}