diff --git a/crates/ui/src/list/list.rs b/crates/ui/src/list/list.rs index 5114b7b4..01d65a44 100644 --- a/crates/ui/src/list/list.rs +++ b/crates/ui/src/list/list.rs @@ -109,12 +109,11 @@ pub struct List { max_height: Option, query_input: Option>, last_query: Option, + selectable: bool, loading: bool, - - enable_scrollbar: bool, + scrollbar_visible: bool, vertical_scroll_handle: UniformListScrollHandle, scrollbar_state: Rc>, - pub(crate) size: Size, selected_index: Option, right_clicked_index: Option, @@ -147,7 +146,8 @@ where vertical_scroll_handle: UniformListScrollHandle::new(), scrollbar_state: Rc::new(Cell::new(ScrollbarState::new())), max_height: None, - enable_scrollbar: true, + scrollbar_visible: true, + selectable: true, loading: false, size: Size::default(), _search_task: Task::ready(()), @@ -169,8 +169,9 @@ where self } - pub fn no_scrollbar(mut self) -> Self { - self.enable_scrollbar = false; + /// Set the visibility of the scrollbar, default is true. + pub fn scrollbar_visible(mut self, visible: bool) -> Self { + self.scrollbar_visible = visible; self } @@ -179,6 +180,12 @@ where self } + /// Sets whether the list is selectable, default is true. + pub fn selectable(mut self, selectable: bool) -> Self { + self.selectable = selectable; + self + } + pub fn set_query_input(&mut self, query_input: View, cx: &mut ViewContext) { cx.subscribe(&query_input, Self::on_query_input_event) .detach(); @@ -220,7 +227,7 @@ where } fn render_scrollbar(&self, cx: &mut ViewContext) -> Option { - if !self.enable_scrollbar { + if !self.scrollbar_visible { return None; } @@ -383,34 +390,36 @@ where .w_full() .relative() .children(self.delegate.render_item(ix, cx)) - .when(selected || right_clicked, |this| { - this.child( - div() - .absolute() - .top(px(0.)) - .left(px(0.)) - .right(px(0.)) - .bottom(px(0.)) - .when(selected, |this| this.bg(cx.theme().list_active)) - .border_1() - .border_color(cx.theme().list_active_border), + .when(self.selectable, |this| { + this.when(selected || right_clicked, |this| { + this.child( + div() + .absolute() + .top(px(0.)) + .left(px(0.)) + .right(px(0.)) + .bottom(px(0.)) + .when(selected, |this| this.bg(cx.theme().list_active)) + .border_1() + .border_color(cx.theme().list_active_border), + ) + }) + .on_mouse_down( + MouseButton::Left, + cx.listener(move |this, _, cx| { + this.right_clicked_index = None; + this.selected_index = Some(ix); + this.on_action_confirm(&Confirm, cx); + }), + ) + .on_mouse_down( + MouseButton::Right, + cx.listener(move |this, _, cx| { + this.right_clicked_index = Some(ix); + cx.notify(); + }), ) }) - .on_mouse_down( - MouseButton::Left, - cx.listener(move |this, _, cx| { - this.right_clicked_index = None; - this.selected_index = Some(ix); - this.on_action_confirm(&Confirm, cx); - }), - ) - .on_mouse_down( - MouseButton::Right, - cx.listener(move |this, _, cx| { - this.right_clicked_index = Some(ix); - cx.notify(); - }), - ) } }