Fix inactive tab styles (the verbose way) (#3591)

This PR fixes the inactive tab style to properly show the label using
the muted text color.

I went about fixing this in the most direct way possible, but the
solution leaves a lot to be desired, IMO. I plan to explore some ideas
on how we can improve the state of styling the tab content without
having the same styles repeated all over the place and subsequently
out-of-sync.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers
2023-12-11 15:42:17 -05:00
committed by GitHub
parent fcbc18a380
commit f02a3e8c68
9 changed files with 108 additions and 59 deletions
+6 -5
View File
@@ -106,7 +106,7 @@ pub trait Item: FocusableView + EventEmitter<Self::Event> {
fn tab_description(&self, _: usize, _: &AppContext) -> Option<SharedString> {
None
}
fn tab_content(&self, detail: Option<usize>, cx: &WindowContext) -> AnyElement;
fn tab_content(&self, detail: Option<usize>, selected: bool, cx: &WindowContext) -> AnyElement;
/// (model id, Item)
fn for_each_project_item(
@@ -218,7 +218,7 @@ pub trait ItemHandle: 'static + Send {
fn focus_handle(&self, cx: &WindowContext) -> FocusHandle;
fn tab_tooltip_text(&self, cx: &AppContext) -> Option<SharedString>;
fn tab_description(&self, detail: usize, cx: &AppContext) -> Option<SharedString>;
fn tab_content(&self, detail: Option<usize>, cx: &WindowContext) -> AnyElement;
fn tab_content(&self, detail: Option<usize>, selected: bool, cx: &WindowContext) -> AnyElement;
fn dragged_tab_content(&self, detail: Option<usize>, cx: &WindowContext) -> AnyElement;
fn project_path(&self, cx: &AppContext) -> Option<ProjectPath>;
fn project_entry_ids(&self, cx: &AppContext) -> SmallVec<[ProjectEntryId; 3]>;
@@ -311,12 +311,12 @@ impl<T: Item> ItemHandle for View<T> {
self.read(cx).tab_description(detail, cx)
}
fn tab_content(&self, detail: Option<usize>, cx: &WindowContext) -> AnyElement {
self.read(cx).tab_content(detail, cx)
fn tab_content(&self, detail: Option<usize>, selected: bool, cx: &WindowContext) -> AnyElement {
self.read(cx).tab_content(detail, selected, cx)
}
fn dragged_tab_content(&self, detail: Option<usize>, cx: &WindowContext) -> AnyElement {
self.read(cx).tab_content(detail, cx)
self.read(cx).tab_content(detail, true, cx)
}
fn project_path(&self, cx: &AppContext) -> Option<ProjectPath> {
@@ -941,6 +941,7 @@ pub mod test {
fn tab_content(
&self,
detail: Option<usize>,
selected: bool,
cx: &ui::prelude::WindowContext,
) -> AnyElement {
self.tab_detail.set(detail);
+4 -4
View File
@@ -1424,7 +1424,9 @@ impl Pane {
detail: usize,
cx: &mut ViewContext<'_, Pane>,
) -> impl IntoElement {
let label = item.tab_content(Some(detail), cx);
let is_active = ix == self.active_item_index;
let label = item.tab_content(Some(detail), is_active, cx);
let close_side = &ItemSettings::get_global(cx).close_position;
let (text_color, tab_bg, tab_hover_bg, tab_active_bg) = match ix == self.active_item_index {
@@ -1442,8 +1444,6 @@ impl Pane {
),
};
let is_active = ix == self.active_item_index;
let indicator = maybe!({
let indicator_color = match (item.has_conflict(cx), item.is_dirty(cx)) {
(true, _) => Color::Warning,
@@ -1473,7 +1473,7 @@ impl Pane {
ClosePosition::Left => ui::TabCloseSide::Start,
ClosePosition::Right => ui::TabCloseSide::End,
})
.selected(ix == self.active_item_index())
.selected(is_active)
.on_click(cx.listener(move |pane: &mut Self, event, cx| {
pane.activate_item(ix, true, true, cx)
}))
+14 -6
View File
@@ -12,7 +12,7 @@ use gpui::{
VisualContext, WindowContext,
};
use std::sync::{Arc, Weak};
use ui::{h_stack, Icon, IconElement};
use ui::{h_stack, prelude::*, Icon, IconElement, Label};
pub enum Event {
Close,
@@ -90,14 +90,22 @@ impl Item for SharedScreen {
}
}
fn tab_content(&self, _: Option<usize>, _: &WindowContext<'_>) -> gpui::AnyElement {
fn tab_content(
&self,
_: Option<usize>,
selected: bool,
_: &WindowContext<'_>,
) -> gpui::AnyElement {
h_stack()
.gap_1()
.child(IconElement::new(Icon::Screen))
.child(SharedString::from(format!(
"{}'s screen",
self.user.github_login
)))
.child(
Label::new(format!("{}'s screen", self.user.github_login)).color(if selected {
Color::Default
} else {
Color::Muted
}),
)
.into_any()
}