list: Add cx argument to ListDelegate. (#361)
Following #360 TableDelegate changes.
This commit is contained in:
parent
536bb60900
commit
c02cb802cb
4 changed files with 16 additions and 16 deletions
|
|
@ -2,7 +2,7 @@ use core::time;
|
||||||
|
|
||||||
use fake::Fake;
|
use fake::Fake;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, div, px, relative, AnyElement, ElementId, FocusHandle, FocusableView,
|
actions, div, px, relative, AnyElement, AppContext, ElementId, FocusHandle, FocusableView,
|
||||||
InteractiveElement, IntoElement, ParentElement, Render, RenderOnce, Styled, Task, Timer, View,
|
InteractiveElement, IntoElement, ParentElement, Render, RenderOnce, Styled, Task, Timer, View,
|
||||||
ViewContext, VisualContext, WindowContext,
|
ViewContext, VisualContext, WindowContext,
|
||||||
};
|
};
|
||||||
|
|
@ -140,11 +140,11 @@ struct CompanyListDelegate {
|
||||||
impl ListDelegate for CompanyListDelegate {
|
impl ListDelegate for CompanyListDelegate {
|
||||||
type Item = CompanyListItem;
|
type Item = CompanyListItem;
|
||||||
|
|
||||||
fn items_count(&self) -> usize {
|
fn items_count(&self, _: &AppContext) -> usize {
|
||||||
self.matched_companies.len()
|
self.matched_companies.len()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn confirmed_index(&self) -> Option<usize> {
|
fn confirmed_index(&self, _: &AppContext) -> Option<usize> {
|
||||||
self.confirmed_index
|
self.confirmed_index
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use std::{sync::Arc, time::Duration};
|
||||||
|
|
||||||
use fake::Fake;
|
use fake::Fake;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, div, prelude::FluentBuilder as _, px, FocusHandle, FocusableView,
|
actions, div, prelude::FluentBuilder as _, px, AppContext, FocusHandle, FocusableView,
|
||||||
InteractiveElement as _, IntoElement, ParentElement, Render, SharedString, Styled, Task, Timer,
|
InteractiveElement as _, IntoElement, ParentElement, Render, SharedString, Styled, Task, Timer,
|
||||||
View, ViewContext, VisualContext as _, WeakView, WindowContext,
|
View, ViewContext, VisualContext as _, WeakView, WindowContext,
|
||||||
};
|
};
|
||||||
|
|
@ -33,11 +33,11 @@ pub struct ListItemDeletegate {
|
||||||
impl ListDelegate for ListItemDeletegate {
|
impl ListDelegate for ListItemDeletegate {
|
||||||
type Item = ListItem;
|
type Item = ListItem;
|
||||||
|
|
||||||
fn items_count(&self) -> usize {
|
fn items_count(&self, _: &AppContext) -> usize {
|
||||||
self.matches.len()
|
self.matches.len()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn confirmed_index(&self) -> Option<usize> {
|
fn confirmed_index(&self, _: &AppContext) -> Option<usize> {
|
||||||
self.confirmed_index
|
self.confirmed_index
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -118,11 +118,11 @@ where
|
||||||
{
|
{
|
||||||
type Item = ListItem;
|
type Item = ListItem;
|
||||||
|
|
||||||
fn items_count(&self) -> usize {
|
fn items_count(&self, _: &AppContext) -> usize {
|
||||||
self.delegate.len()
|
self.delegate.len()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn confirmed_index(&self) -> Option<usize> {
|
fn confirmed_index(&self, _: &AppContext) -> Option<usize> {
|
||||||
self.selected_index
|
self.selected_index
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ pub trait ListDelegate: Sized + 'static {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the number of items in the list.
|
/// Return the number of items in the list.
|
||||||
fn items_count(&self) -> usize;
|
fn items_count(&self, cx: &AppContext) -> usize;
|
||||||
|
|
||||||
/// Render the item at the given index.
|
/// Render the item at the given index.
|
||||||
///
|
///
|
||||||
|
|
@ -64,7 +64,7 @@ pub trait ListDelegate: Sized + 'static {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the confirmed index of the selected item.
|
/// Return the confirmed index of the selected item.
|
||||||
fn confirmed_index(&self) -> Option<usize> {
|
fn confirmed_index(&self, cx: &AppContext) -> Option<usize> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -261,7 +261,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_action_confirm(&mut self, _: &Confirm, cx: &mut ViewContext<Self>) {
|
fn on_action_confirm(&mut self, _: &Confirm, cx: &mut ViewContext<Self>) {
|
||||||
if self.delegate.items_count() == 0 {
|
if self.delegate.items_count(cx) == 0 {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -270,7 +270,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_action_select_prev(&mut self, _: &SelectPrev, cx: &mut ViewContext<Self>) {
|
fn on_action_select_prev(&mut self, _: &SelectPrev, cx: &mut ViewContext<Self>) {
|
||||||
if self.delegate.items_count() == 0 {
|
if self.delegate.items_count(cx) == 0 {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -278,7 +278,7 @@ where
|
||||||
if selected_index > 0 {
|
if selected_index > 0 {
|
||||||
self.selected_index = Some(selected_index - 1);
|
self.selected_index = Some(selected_index - 1);
|
||||||
} else {
|
} else {
|
||||||
self.selected_index = Some(self.delegate.items_count() - 1);
|
self.selected_index = Some(self.delegate.items_count(cx) - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.scroll_to_selected_item(cx);
|
self.scroll_to_selected_item(cx);
|
||||||
|
|
@ -286,12 +286,12 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_action_select_next(&mut self, _: &SelectNext, cx: &mut ViewContext<Self>) {
|
fn on_action_select_next(&mut self, _: &SelectNext, cx: &mut ViewContext<Self>) {
|
||||||
if self.delegate.items_count() == 0 {
|
if self.delegate.items_count(cx) == 0 {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(selected_index) = self.selected_index {
|
if let Some(selected_index) = self.selected_index {
|
||||||
if selected_index < self.delegate.items_count() - 1 {
|
if selected_index < self.delegate.items_count(cx) - 1 {
|
||||||
self.selected_index = Some(selected_index + 1);
|
self.selected_index = Some(selected_index + 1);
|
||||||
} else {
|
} else {
|
||||||
self.selected_index = Some(0);
|
self.selected_index = Some(0);
|
||||||
|
|
@ -325,7 +325,7 @@ where
|
||||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||||
let view = cx.view().clone();
|
let view = cx.view().clone();
|
||||||
let vertical_scroll_handle = self.vertical_scroll_handle.clone();
|
let vertical_scroll_handle = self.vertical_scroll_handle.clone();
|
||||||
let items_count = self.delegate.items_count();
|
let items_count = self.delegate.items_count(cx);
|
||||||
let sizing_behavior = if self.max_height.is_some() {
|
let sizing_behavior = if self.max_height.is_some() {
|
||||||
ListSizingBehavior::Infer
|
ListSizingBehavior::Infer
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue