Align close tab icon cleanly with unsaved indicator

This commit is contained in:
Nathan Sobo
2021-04-27 16:51:23 -06:00
parent eca9f495a1
commit 58e336354e
3 changed files with 39 additions and 49 deletions
+10 -6
View File
@@ -216,7 +216,7 @@ impl App {
}
pub fn font_cache(&self) -> Arc<FontCache> {
self.0.borrow().font_cache.clone()
self.0.borrow().ctx.font_cache.clone()
}
fn update<T, F: FnOnce(&mut MutableAppContext) -> T>(&mut self, callback: F) -> T {
@@ -326,7 +326,7 @@ impl TestAppContext {
}
pub fn font_cache(&self) -> Arc<FontCache> {
self.0.borrow().font_cache.clone()
self.0.borrow().ctx.font_cache.clone()
}
pub fn platform(&self) -> Rc<dyn platform::Platform> {
@@ -370,7 +370,6 @@ type GlobalActionCallback = dyn FnMut(&dyn Any, &mut MutableAppContext);
pub struct MutableAppContext {
weak_self: Option<rc::Weak<RefCell<Self>>>,
platform: Rc<dyn platform::Platform>,
font_cache: Arc<FontCache>,
assets: Arc<AssetCache>,
ctx: AppContext,
actions: HashMap<TypeId, HashMap<String, Vec<Box<ActionCallback>>>>,
@@ -404,7 +403,6 @@ impl MutableAppContext {
Self {
weak_self: None,
platform,
font_cache: Arc::new(FontCache::new(fonts)),
assets: Arc::new(AssetCache::new(asset_source)),
ctx: AppContext {
models: Default::default(),
@@ -413,6 +411,7 @@ impl MutableAppContext {
ref_counts: Arc::new(Mutex::new(RefCounts::default())),
background: Arc::new(executor::Background::new()),
thread_pool: scoped_pool::Pool::new(num_cpus::get(), "app"),
font_cache: Arc::new(FontCache::new(fonts)),
},
actions: HashMap::new(),
global_actions: HashMap::new(),
@@ -444,7 +443,7 @@ impl MutableAppContext {
}
pub fn font_cache(&self) -> &Arc<FontCache> {
&self.font_cache
&self.ctx.font_cache
}
pub fn foreground_executor(&self) -> &Rc<executor::Foreground> {
@@ -764,7 +763,7 @@ impl MutableAppContext {
let text_layout_cache = TextLayoutCache::new(self.platform.fonts());
let presenter = Rc::new(RefCell::new(Presenter::new(
window_id,
self.font_cache.clone(),
self.ctx.font_cache.clone(),
text_layout_cache,
self.assets.clone(),
self,
@@ -1327,6 +1326,7 @@ pub struct AppContext {
background: Arc<executor::Background>,
ref_counts: Arc<Mutex<RefCounts>>,
thread_pool: scoped_pool::Pool,
font_cache: Arc<FontCache>,
}
impl AppContext {
@@ -1366,6 +1366,10 @@ impl AppContext {
&self.background
}
pub fn font_cache(&self) -> &FontCache {
&self.font_cache
}
pub fn thread_pool(&self) -> &scoped_pool::Pool {
&self.thread_pool
}
+2 -2
View File
@@ -1,3 +1,3 @@
<svg width="10" height="10" viewBox="0 0 10 10" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M0.720011 0.72003C0.860631 0.57958 1.05126 0.50069 1.25001 0.50069C1.44876 0.50069 1.63938 0.57958 1.78001 0.72003L5.00001 3.94003L8.22001 0.72003C8.28871 0.64634 8.37151 0.58724 8.46351 0.54625C8.55551 0.50526 8.65481 0.48322 8.75551 0.48144C8.85621 0.47966 8.95621 0.49819 9.04961 0.53591C9.14301 0.57363 9.22781 0.62977 9.29901 0.70099C9.37031 0.77221 9.42641 0.85705 9.46411 0.95043C9.50181 1.04382 9.52041 1.14385 9.51861 1.24455C9.51681 1.34526 9.49481 1.44457 9.45381 1.53657C9.41281 1.62857 9.35371 1.71137 9.28001 1.78003L6.06001 5.00003L9.28001 8.22003C9.35371 8.28873 9.41281 8.37153 9.45381 8.46353C9.49481 8.55553 9.51681 8.65483 9.51861 8.75553C9.52041 8.85623 9.50181 8.95623 9.46411 9.04963C9.42641 9.14303 9.37031 9.22783 9.29901 9.29903C9.22781 9.37033 9.14301 9.42643 9.04961 9.46413C8.95621 9.50183 8.85621 9.52043 8.75551 9.51863C8.65481 9.51683 8.55551 9.49483 8.46351 9.45383C8.37151 9.41283 8.28871 9.35373 8.22001 9.28003L5.00001 6.06003L1.78001 9.28003C1.63783 9.41253 1.44978 9.48463 1.25548 9.48123C1.06118 9.47773 0.875801 9.39903 0.738381 9.26163C0.600971 9.12423 0.522261 8.93883 0.518831 8.74453C0.515401 8.55023 0.587531 8.36223 0.720011 8.22003L3.94001 5.00003L0.720011 1.78003C0.579561 1.63941 0.500671 1.44878 0.500671 1.25003C0.500671 1.05128 0.579561 0.86066 0.720011 0.72003Z" fill="#000000"/>
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M17.6568 6.34314L12 12M12 12L6.34314 17.6568M12 12L17.6568 17.6568M12 12L6.34314 6.34314" stroke="black" stroke-width="2"/>
</svg>

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 236 B

+27 -41
View File
@@ -1,7 +1,7 @@
use super::{ItemViewHandle, SplitDirection};
use crate::{settings::Settings, watch};
use gpui::{
color::{ColorF, ColorU},
color::ColorU,
elements::*,
geometry::{rect::RectF, vector::vec2f},
keymap::Binding,
@@ -179,6 +179,10 @@ impl Pane {
fn render_tabs(&self, ctx: &AppContext) -> ElementBox {
let settings = smol::block_on(self.settings.read());
let border_color = ColorU::from_u32(0xdbdbdcff);
let line_height = ctx.font_cache().line_height(
ctx.font_cache().default_font(settings.ui_font_family),
settings.ui_font_size,
);
let mut row = Flex::row();
let last_item_ix = self.items.len() - 1;
@@ -196,7 +200,6 @@ impl Pane {
border.right = ix == last_item_ix;
border.bottom = ix != self.active_item;
let padding = 6.;
let mut container = Container::new(
Stack::new()
.with_child(
@@ -211,28 +214,23 @@ impl Pane {
.boxed(),
)
.with_child(
LineBox::new(
settings.ui_font_family,
settings.ui_font_size,
Align::new(Self::render_tab_icon(
mouse_state.hovered,
item.is_dirty(ctx),
))
.right()
.boxed(),
)
Align::new(Self::render_tab_icon(
line_height - 2.,
mouse_state.hovered,
item.is_dirty(ctx),
))
.right()
.boxed(),
)
.boxed(),
)
.with_vertical_padding(padding)
.with_horizontal_padding(10.)
.with_border(border);
if ix == self.active_item {
container = container
.with_background_color(ColorU::white())
.with_padding_bottom(padding + border.width);
.with_padding_bottom(border.width);
} else {
container =
container.with_background_color(ColorU::from_u32(0xeaeaebff));
@@ -260,17 +258,9 @@ impl Pane {
// so that the tab's border doesn't abut the window's border.
row.add_child(
ConstrainedBox::new(
Container::new(
LineBox::new(
settings.ui_font_family,
settings.ui_font_size,
Empty::new().boxed(),
)
Container::new(Empty::new().boxed())
.with_border(Border::bottom(1.0, border_color))
.boxed(),
)
.with_uniform_padding(6.0)
.with_border(Border::bottom(1.0, border_color))
.boxed(),
)
.with_min_width(20.)
.named("fixed-filler"),
@@ -279,34 +269,26 @@ impl Pane {
row.add_child(
Expanded::new(
0.0,
Container::new(
LineBox::new(
settings.ui_font_family,
settings.ui_font_size,
Empty::new().boxed(),
)
Container::new(Empty::new().boxed())
.with_border(Border::bottom(1.0, border_color))
.boxed(),
)
.with_uniform_padding(6.0)
.with_border(Border::bottom(1.0, border_color))
.boxed(),
)
.named("filler"),
);
row.named("tabs")
ConstrainedBox::new(row.boxed())
.with_height(line_height + 16.)
.named("tabs")
}
fn render_tab_icon(tab_hovered: bool, is_modified: bool) -> ElementBox {
fn render_tab_icon(close_icon_size: f32, tab_hovered: bool, is_modified: bool) -> ElementBox {
let modified_color = ColorU::from_u32(0x556de8ff);
if tab_hovered {
let icon = if tab_hovered {
let mut icon = Svg::new("icons/x.svg");
if is_modified {
icon = icon.with_color(modified_color);
}
ConstrainedBox::new(icon.boxed())
.with_width(10.)
.named("close-tab-icon")
icon.named("close-tab-icon")
} else {
let diameter = 8.;
ConstrainedBox::new(
@@ -326,7 +308,11 @@ impl Pane {
.with_width(diameter)
.with_height(diameter)
.named("unsaved-tab-icon")
}
};
ConstrainedBox::new(Align::new(icon).boxed())
.with_width(close_icon_size)
.named("tab-icon")
}
}