Render other tab icons in the start slot (#14683)
This PR reworks the rendering for tab icons to allow us to render all of the tab icons—not just file icons—in the tab's start slot. The `Item` trait now has a separate `tab_icon` method that can be used to indicate what icon should be shown for the tab. Release Notes: - N/A
This commit is contained in:
parent
2edf224599
commit
00c3c02f7d
10 changed files with 80 additions and 80 deletions
|
@ -31,7 +31,7 @@ use std::{
|
|||
time::Duration,
|
||||
};
|
||||
use theme::Theme;
|
||||
use ui::Element as _;
|
||||
use ui::{Element as _, Icon};
|
||||
use util::ResultExt;
|
||||
|
||||
pub const LEADER_UPDATE_THROTTLE: Duration = Duration::from_millis(200);
|
||||
|
@ -147,6 +147,11 @@ pub trait Item: FocusableView + EventEmitter<Self::Event> {
|
|||
fn tab_content(&self, _params: TabContentParams, _cx: &WindowContext) -> AnyElement {
|
||||
gpui::Empty.into_any()
|
||||
}
|
||||
|
||||
fn tab_icon(&self, _cx: &WindowContext) -> Option<Icon> {
|
||||
None
|
||||
}
|
||||
|
||||
fn to_item_events(_event: &Self::Event, _f: impl FnMut(ItemEvent)) {}
|
||||
|
||||
fn deactivated(&mut self, _: &mut ViewContext<Self>) {}
|
||||
|
@ -330,6 +335,7 @@ pub trait ItemHandle: 'static + Send {
|
|||
fn tab_tooltip_text(&self, cx: &AppContext) -> Option<SharedString>;
|
||||
fn tab_description(&self, detail: usize, cx: &AppContext) -> Option<SharedString>;
|
||||
fn tab_content(&self, params: TabContentParams, cx: &WindowContext) -> AnyElement;
|
||||
fn tab_icon(&self, cx: &WindowContext) -> Option<Icon>;
|
||||
fn telemetry_event_text(&self, cx: &WindowContext) -> Option<&'static str>;
|
||||
fn dragged_tab_content(&self, params: TabContentParams, cx: &WindowContext) -> AnyElement;
|
||||
fn project_path(&self, cx: &AppContext) -> Option<ProjectPath>;
|
||||
|
@ -441,6 +447,10 @@ impl<T: Item> ItemHandle for View<T> {
|
|||
self.read(cx).tab_content(params, cx)
|
||||
}
|
||||
|
||||
fn tab_icon(&self, cx: &WindowContext) -> Option<Icon> {
|
||||
self.read(cx).tab_icon(cx)
|
||||
}
|
||||
|
||||
fn dragged_tab_content(&self, params: TabContentParams, cx: &WindowContext) -> AnyElement {
|
||||
self.read(cx).tab_content(
|
||||
TabContentParams {
|
||||
|
|
|
@ -10,7 +10,6 @@ use crate::{
|
|||
};
|
||||
use anyhow::Result;
|
||||
use collections::{BTreeSet, HashMap, HashSet, VecDeque};
|
||||
use file_icons::FileIcons;
|
||||
use futures::{stream::FuturesUnordered, StreamExt};
|
||||
use gpui::{
|
||||
actions, anchored, deferred, impl_actions, prelude::*, Action, AnchorCorner, AnyElement,
|
||||
|
@ -1590,6 +1589,7 @@ impl Pane {
|
|||
},
|
||||
cx,
|
||||
);
|
||||
let icon = item.tab_icon(cx);
|
||||
let close_side = &ItemSettings::get_global(cx).close_position;
|
||||
let indicator = render_item_indicator(item.boxed_clone(), cx);
|
||||
let item_id = item.item_id();
|
||||
|
@ -1597,14 +1597,6 @@ impl Pane {
|
|||
let is_last_item = ix == self.items.len() - 1;
|
||||
let position_relative_to_active_item = ix.cmp(&self.active_item_index);
|
||||
|
||||
let file_icon = ItemSettings::get_global(cx)
|
||||
.file_icons
|
||||
.then(|| {
|
||||
item.project_path(cx)
|
||||
.and_then(|path| FileIcons::get_icon(path.path.as_ref(), cx))
|
||||
})
|
||||
.flatten();
|
||||
|
||||
let tab = Tab::new(ix)
|
||||
.position(if is_first_item {
|
||||
TabPosition::First
|
||||
|
@ -1675,14 +1667,12 @@ impl Pane {
|
|||
})
|
||||
.map(|tab| match indicator {
|
||||
Some(indicator) => tab.start_slot(indicator),
|
||||
None => tab.start_slot::<Icon>(file_icon.map(|icon| {
|
||||
Icon::from_path(icon.to_string())
|
||||
.size(IconSize::XSmall)
|
||||
.color(if is_active {
|
||||
Color::Default
|
||||
} else {
|
||||
Color::Muted
|
||||
})
|
||||
None => tab.start_slot::<Icon>(icon.map(|icon| {
|
||||
icon.size(IconSize::XSmall).color(if is_active {
|
||||
Color::Default
|
||||
} else {
|
||||
Color::Muted
|
||||
})
|
||||
})),
|
||||
})
|
||||
.end_slot(
|
||||
|
|
|
@ -7,12 +7,12 @@ use call::participant::{Frame, RemoteVideoTrack};
|
|||
use client::{proto::PeerId, User};
|
||||
use futures::StreamExt;
|
||||
use gpui::{
|
||||
div, img, AppContext, Element, EventEmitter, FocusHandle, FocusableView, InteractiveElement,
|
||||
div, img, AppContext, EventEmitter, FocusHandle, FocusableView, InteractiveElement,
|
||||
ParentElement, Render, SharedString, Styled, Task, View, ViewContext, VisualContext,
|
||||
WindowContext,
|
||||
};
|
||||
use std::sync::{Arc, Weak};
|
||||
use ui::{h_flex, prelude::*, Icon, IconName, Label};
|
||||
use ui::{prelude::*, Icon, IconName, Label};
|
||||
|
||||
pub enum Event {
|
||||
Close,
|
||||
|
@ -93,24 +93,18 @@ impl Item for SharedScreen {
|
|||
}
|
||||
}
|
||||
|
||||
fn tab_icon(&self, _cx: &WindowContext) -> Option<Icon> {
|
||||
Some(Icon::new(IconName::Screen))
|
||||
}
|
||||
|
||||
fn tab_content(&self, params: TabContentParams, _: &WindowContext<'_>) -> gpui::AnyElement {
|
||||
h_flex()
|
||||
.gap_1()
|
||||
.child(Icon::new(IconName::Screen).color(if params.selected {
|
||||
Label::new(format!("{}'s screen", self.user.github_login))
|
||||
.color(if params.selected {
|
||||
Color::Default
|
||||
} else {
|
||||
Color::Muted
|
||||
}))
|
||||
.child(
|
||||
Label::new(format!("{}'s screen", self.user.github_login)).color(
|
||||
if params.selected {
|
||||
Color::Default
|
||||
} else {
|
||||
Color::Muted
|
||||
},
|
||||
),
|
||||
)
|
||||
.into_any()
|
||||
})
|
||||
.into_any_element()
|
||||
}
|
||||
|
||||
fn telemetry_event_text(&self) -> Option<&'static str> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue