Fix DockItem::tabs, the items should use trait object to support difference type.

This commit is contained in:
Jason Lee 2024-09-06 18:04:26 +08:00
parent 9baada4fb4
commit b6374313b2
2 changed files with 16 additions and 17 deletions

View file

@ -70,18 +70,18 @@ impl StoryWorkspace {
vec![
DockItem::tabs(
vec![
StoryContainer::panel::<ButtonStory>(cx),
StoryContainer::panel::<InputStory>(cx),
StoryContainer::panel::<DropdownStory>(cx),
StoryContainer::panel::<ModalStory>(cx),
StoryContainer::panel::<PopupStory>(cx),
StoryContainer::panel::<ListStory>(cx),
StoryContainer::panel::<SwitchStory>(cx),
StoryContainer::panel::<ProgressStory>(cx),
StoryContainer::panel::<TableStory>(cx),
StoryContainer::panel::<ImageStory>(cx),
StoryContainer::panel::<ResizableStory>(cx),
StoryContainer::panel::<ScrollableStory>(cx),
Arc::new(StoryContainer::panel::<ButtonStory>(cx)),
Arc::new(StoryContainer::panel::<InputStory>(cx)),
Arc::new(StoryContainer::panel::<DropdownStory>(cx)),
Arc::new(StoryContainer::panel::<ModalStory>(cx)),
Arc::new(StoryContainer::panel::<PopupStory>(cx)),
Arc::new(StoryContainer::panel::<ListStory>(cx)),
Arc::new(StoryContainer::panel::<SwitchStory>(cx)),
Arc::new(StoryContainer::panel::<ProgressStory>(cx)),
Arc::new(StoryContainer::panel::<TableStory>(cx)),
Arc::new(StoryContainer::panel::<ImageStory>(cx)),
Arc::new(StoryContainer::panel::<ResizableStory>(cx)),
Arc::new(StoryContainer::panel::<ScrollableStory>(cx)),
],
None,
&dock_area,
@ -89,8 +89,8 @@ impl StoryWorkspace {
),
DockItem::tabs(
vec![
StoryContainer::panel::<ProgressStory>(cx),
StoryContainer::panel::<TextStory>(cx),
Arc::new(StoryContainer::panel::<ProgressStory>(cx)),
Arc::new(StoryContainer::panel::<TextStory>(cx)),
],
None,
&dock_area,

View file

@ -89,15 +89,14 @@ impl DockItem {
/// Create DockItem with tabs layout, items are displayed as tabs.
///
/// The `active_ix` is the index of the active tab, if `None` the first tab is active.
pub fn tabs<P: Panel>(
items: Vec<View<P>>,
pub fn tabs(
items: Vec<Arc<dyn PanelView>>,
active_ix: Option<usize>,
dock_area: &View<DockArea>,
cx: &mut WindowContext,
) -> Self {
let mut new_items: Vec<Arc<dyn PanelView>> = vec![];
for item in items.into_iter() {
let item: Arc<dyn PanelView> = Arc::new(item);
new_items.push(item)
}
Self::new_tabs(new_items, active_ix, dock_area, cx)