properly constrained tab
This commit is contained in:
parent
ab9f073443
commit
03a344a272
2 changed files with 95 additions and 81 deletions
|
@ -107,6 +107,9 @@ impl<V: View> DragAndDrop<V> {
|
||||||
Container::new(render(payload, cx))
|
Container::new(render(payload, cx))
|
||||||
.with_margin_left(position.x())
|
.with_margin_left(position.x())
|
||||||
.with_margin_top(position.y())
|
.with_margin_top(position.y())
|
||||||
|
.aligned()
|
||||||
|
.top()
|
||||||
|
.left()
|
||||||
.boxed()
|
.boxed()
|
||||||
})
|
})
|
||||||
.on_up(MouseButton::Left, |_, cx| {
|
.on_up(MouseButton::Left, |_, cx| {
|
||||||
|
|
|
@ -3,6 +3,7 @@ use crate::{toolbar::Toolbar, Item, NewFile, NewSearch, NewTerminal, WeakItemHan
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use collections::{HashMap, HashSet, VecDeque};
|
use collections::{HashMap, HashSet, VecDeque};
|
||||||
use context_menu::{ContextMenu, ContextMenuItem};
|
use context_menu::{ContextMenu, ContextMenuItem};
|
||||||
|
use drag_and_drop::Draggable;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions,
|
actions,
|
||||||
|
@ -906,6 +907,7 @@ impl Pane {
|
||||||
MouseEventHandler::new::<Tab, _, _>(ix, cx, {
|
MouseEventHandler::new::<Tab, _, _>(ix, cx, {
|
||||||
let item = item.clone();
|
let item = item.clone();
|
||||||
let pane = pane.clone();
|
let pane = pane.clone();
|
||||||
|
let detail = detail.clone();
|
||||||
let hovered = mouse_state.hovered;
|
let hovered = mouse_state.hovered;
|
||||||
|
|
||||||
move |_, cx| {
|
move |_, cx| {
|
||||||
|
@ -929,6 +931,7 @@ impl Pane {
|
||||||
cx.dispatch_action(ActivateItem(ix));
|
cx.dispatch_action(ActivateItem(ix));
|
||||||
})
|
})
|
||||||
.on_click(MouseButton::Middle, {
|
.on_click(MouseButton::Middle, {
|
||||||
|
let item = item.clone();
|
||||||
let pane = pane.clone();
|
let pane = pane.clone();
|
||||||
move |_, cx: &mut EventContext| {
|
move |_, cx: &mut EventContext| {
|
||||||
cx.dispatch_action(CloseItem {
|
cx.dispatch_action(CloseItem {
|
||||||
|
@ -937,6 +940,15 @@ impl Pane {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.as_draggable(item, {
|
||||||
|
let pane = pane.clone();
|
||||||
|
let detail = detail.clone();
|
||||||
|
|
||||||
|
move |item, cx: &mut RenderContext<Workspace>| {
|
||||||
|
let pane = pane.clone();
|
||||||
|
Pane::render_tab(item, pane, detail, false, pane_active, tab_active, cx)
|
||||||
|
}
|
||||||
|
})
|
||||||
.boxed()
|
.boxed()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1005,94 +1017,93 @@ impl Pane {
|
||||||
let tab_style = theme.workspace.tab_bar.tab_style(pane_active, tab_active);
|
let tab_style = theme.workspace.tab_bar.tab_style(pane_active, tab_active);
|
||||||
let title = item.tab_content(detail, tab_style, cx);
|
let title = item.tab_content(detail, tab_style, cx);
|
||||||
|
|
||||||
Container::new(
|
Flex::row()
|
||||||
Flex::row()
|
.with_child(
|
||||||
.with_child(
|
Align::new({
|
||||||
Align::new({
|
let diameter = 7.0;
|
||||||
let diameter = 7.0;
|
let icon_color = if item.has_conflict(cx) {
|
||||||
let icon_color = if item.has_conflict(cx) {
|
Some(tab_style.icon_conflict)
|
||||||
Some(tab_style.icon_conflict)
|
} else if item.is_dirty(cx) {
|
||||||
} else if item.is_dirty(cx) {
|
Some(tab_style.icon_dirty)
|
||||||
Some(tab_style.icon_dirty)
|
} else {
|
||||||
} else {
|
None
|
||||||
None
|
};
|
||||||
};
|
|
||||||
|
|
||||||
ConstrainedBox::new(
|
ConstrainedBox::new(
|
||||||
Canvas::new(move |bounds, _, cx| {
|
Canvas::new(move |bounds, _, cx| {
|
||||||
if let Some(color) = icon_color {
|
if let Some(color) = icon_color {
|
||||||
let square =
|
let square = RectF::new(bounds.origin(), vec2f(diameter, diameter));
|
||||||
RectF::new(bounds.origin(), vec2f(diameter, diameter));
|
cx.scene.push_quad(Quad {
|
||||||
cx.scene.push_quad(Quad {
|
bounds: square,
|
||||||
bounds: square,
|
background: Some(color),
|
||||||
background: Some(color),
|
border: Default::default(),
|
||||||
border: Default::default(),
|
corner_radius: diameter / 2.,
|
||||||
corner_radius: diameter / 2.,
|
});
|
||||||
});
|
}
|
||||||
}
|
|
||||||
})
|
|
||||||
.boxed(),
|
|
||||||
)
|
|
||||||
.with_width(diameter)
|
|
||||||
.with_height(diameter)
|
|
||||||
.boxed()
|
|
||||||
})
|
|
||||||
.boxed(),
|
|
||||||
)
|
|
||||||
.with_child(
|
|
||||||
Container::new(Align::new(title).boxed())
|
|
||||||
.with_style(ContainerStyle {
|
|
||||||
margin: Margin {
|
|
||||||
left: tab_style.spacing,
|
|
||||||
right: tab_style.spacing,
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
..Default::default()
|
|
||||||
})
|
})
|
||||||
.boxed(),
|
.boxed(),
|
||||||
)
|
|
||||||
.with_child(
|
|
||||||
Align::new(
|
|
||||||
ConstrainedBox::new(if hovered {
|
|
||||||
let item_id = item.id();
|
|
||||||
enum TabCloseButton {}
|
|
||||||
let icon = Svg::new("icons/x_mark_thin_8.svg");
|
|
||||||
MouseEventHandler::new::<TabCloseButton, _, _>(
|
|
||||||
item_id,
|
|
||||||
cx,
|
|
||||||
|mouse_state, _| {
|
|
||||||
if mouse_state.hovered {
|
|
||||||
icon.with_color(tab_style.icon_close_active).boxed()
|
|
||||||
} else {
|
|
||||||
icon.with_color(tab_style.icon_close).boxed()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.with_padding(Padding::uniform(4.))
|
|
||||||
.with_cursor_style(CursorStyle::PointingHand)
|
|
||||||
.on_click(MouseButton::Left, {
|
|
||||||
let pane = pane.clone();
|
|
||||||
move |_, cx| {
|
|
||||||
cx.dispatch_action(CloseItem {
|
|
||||||
item_id,
|
|
||||||
pane: pane.clone(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.on_click(MouseButton::Middle, |_, cx| cx.propogate_event())
|
|
||||||
.named("close-tab-icon")
|
|
||||||
} else {
|
|
||||||
Empty::new().boxed()
|
|
||||||
})
|
|
||||||
.with_width(tab_style.icon_width)
|
|
||||||
.boxed(),
|
|
||||||
)
|
)
|
||||||
|
.with_width(diameter)
|
||||||
|
.with_height(diameter)
|
||||||
|
.boxed()
|
||||||
|
})
|
||||||
|
.boxed(),
|
||||||
|
)
|
||||||
|
.with_child(
|
||||||
|
Container::new(Align::new(title).boxed())
|
||||||
|
.with_style(ContainerStyle {
|
||||||
|
margin: Margin {
|
||||||
|
left: tab_style.spacing,
|
||||||
|
right: tab_style.spacing,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.boxed(),
|
||||||
|
)
|
||||||
|
.with_child(
|
||||||
|
Align::new(
|
||||||
|
ConstrainedBox::new(if hovered {
|
||||||
|
let item_id = item.id();
|
||||||
|
enum TabCloseButton {}
|
||||||
|
let icon = Svg::new("icons/x_mark_thin_8.svg");
|
||||||
|
MouseEventHandler::new::<TabCloseButton, _, _>(
|
||||||
|
item_id,
|
||||||
|
cx,
|
||||||
|
|mouse_state, _| {
|
||||||
|
if mouse_state.hovered {
|
||||||
|
icon.with_color(tab_style.icon_close_active).boxed()
|
||||||
|
} else {
|
||||||
|
icon.with_color(tab_style.icon_close).boxed()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.with_padding(Padding::uniform(4.))
|
||||||
|
.with_cursor_style(CursorStyle::PointingHand)
|
||||||
|
.on_click(MouseButton::Left, {
|
||||||
|
let pane = pane.clone();
|
||||||
|
move |_, cx| {
|
||||||
|
cx.dispatch_action(CloseItem {
|
||||||
|
item_id,
|
||||||
|
pane: pane.clone(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.on_click(MouseButton::Middle, |_, cx| cx.propogate_event())
|
||||||
|
.named("close-tab-icon")
|
||||||
|
} else {
|
||||||
|
Empty::new().boxed()
|
||||||
|
})
|
||||||
|
.with_width(tab_style.icon_width)
|
||||||
.boxed(),
|
.boxed(),
|
||||||
)
|
)
|
||||||
.boxed(),
|
.boxed(),
|
||||||
)
|
)
|
||||||
.with_style(tab_style.container)
|
.contained()
|
||||||
.boxed()
|
.with_style(tab_style.container)
|
||||||
|
.constrained()
|
||||||
|
.with_height(tab_style.height)
|
||||||
|
.boxed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue