chore: Fix several style lints (#17488)
It's not comprehensive enough to start linting on `style` group, but hey, it's a start. Release Notes: - N/A
This commit is contained in:
parent
93249fc82b
commit
e6c1c51b37
361 changed files with 3530 additions and 3587 deletions
|
@ -300,9 +300,9 @@ impl Column for WorkspaceId {
|
|||
.with_context(|| format!("Failed to read WorkspaceId at index {start_index}"))
|
||||
}
|
||||
}
|
||||
impl Into<i64> for WorkspaceId {
|
||||
fn into(self) -> i64 {
|
||||
self.0
|
||||
impl From<WorkspaceId> for i64 {
|
||||
fn from(val: WorkspaceId) -> Self {
|
||||
val.0
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -383,12 +383,12 @@ impl Global for ProjectItemOpeners {}
|
|||
pub fn register_project_item<I: ProjectItem>(cx: &mut AppContext) {
|
||||
let builders = cx.default_global::<ProjectItemOpeners>();
|
||||
builders.push(|project, project_path, cx| {
|
||||
let project_item = <I::Item as project::Item>::try_open(&project, project_path, cx)?;
|
||||
let project_item = <I::Item as project::Item>::try_open(project, project_path, cx)?;
|
||||
let project = project.clone();
|
||||
Some(cx.spawn(|cx| async move {
|
||||
let project_item = project_item.await?;
|
||||
let project_entry_id: Option<ProjectEntryId> =
|
||||
project_item.read_with(&cx, |item, cx| project::Item::entry_id(item, cx))?;
|
||||
project_item.read_with(&cx, project::Item::entry_id)?;
|
||||
let build_workspace_item = Box::new(|cx: &mut ViewContext<Pane>| {
|
||||
Box::new(cx.new_view(|cx| I::for_project_item(project, project_item, cx)))
|
||||
as Box<dyn ItemHandle>
|
||||
|
@ -963,7 +963,7 @@ impl Workspace {
|
|||
.await;
|
||||
this.update(&mut cx, |this, cx| {
|
||||
if let Some(display) = cx.display() {
|
||||
if let Some(display_uuid) = display.uuid().ok() {
|
||||
if let Ok(display_uuid) = display.uuid() {
|
||||
let window_bounds = cx.window_bounds();
|
||||
if let Some(database_id) = workspace_id {
|
||||
cx.background_executor()
|
||||
|
@ -1782,7 +1782,7 @@ impl Workspace {
|
|||
|
||||
let project = self.project.clone();
|
||||
cx.spawn(|workspace, mut cx| async move {
|
||||
let dirty_items = if save_intent == SaveIntent::Close && dirty_items.len() > 0 {
|
||||
let dirty_items = if save_intent == SaveIntent::Close && !dirty_items.is_empty() {
|
||||
let (serialize_tasks, remaining_dirty_items) =
|
||||
workspace.update(&mut cx, |workspace, cx| {
|
||||
let mut remaining_dirty_items = Vec::new();
|
||||
|
@ -2877,9 +2877,7 @@ impl Workspace {
|
|||
direction: SplitDirection,
|
||||
cx: &WindowContext,
|
||||
) -> Option<View<Pane>> {
|
||||
let Some(bounding_box) = self.center.bounding_box_for_pane(&self.active_pane) else {
|
||||
return None;
|
||||
};
|
||||
let bounding_box = self.center.bounding_box_for_pane(&self.active_pane)?;
|
||||
let cursor = self.active_pane.read(cx).pixel_position_of_cursor(cx);
|
||||
let center = match cursor {
|
||||
Some(cursor) if bounding_box.contains(&cursor) => cursor,
|
||||
|
@ -2910,10 +2908,7 @@ impl Workspace {
|
|||
direction: SplitDirection,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
if let Some(to) = self
|
||||
.find_pane_in_direction(direction, cx)
|
||||
.map(|pane| pane.clone())
|
||||
{
|
||||
if let Some(to) = self.find_pane_in_direction(direction, cx) {
|
||||
self.center.swap(&self.active_pane.clone(), &to);
|
||||
cx.notify();
|
||||
}
|
||||
|
@ -3355,7 +3350,7 @@ impl Workspace {
|
|||
|
||||
// if you're already following, find the right pane and focus it.
|
||||
if let Some(follower_state) = self.follower_states.get(&leader_id) {
|
||||
cx.focus_view(&follower_state.pane());
|
||||
cx.focus_view(follower_state.pane());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -3621,7 +3616,7 @@ impl Workspace {
|
|||
return Err(anyhow!("no id for view"));
|
||||
};
|
||||
let id = ViewId::from_proto(id)?;
|
||||
let panel_id = view.panel_id.and_then(|id| proto::PanelId::from_i32(id));
|
||||
let panel_id = view.panel_id.and_then(proto::PanelId::from_i32);
|
||||
|
||||
let pane = this.update(cx, |this, _cx| {
|
||||
let state = this
|
||||
|
@ -4143,7 +4138,7 @@ impl Workspace {
|
|||
let dev_server_project = SerializedDevServerProject {
|
||||
id: dev_server_project_id,
|
||||
dev_server_name: dev_server.name.to_string(),
|
||||
paths: project.paths.iter().map(|path| path.clone()).collect(),
|
||||
paths: project.paths.to_vec(),
|
||||
};
|
||||
Some(SerializedWorkspaceLocation::DevServer(dev_server_project))
|
||||
})
|
||||
|
@ -4961,7 +4956,7 @@ impl ViewId {
|
|||
})
|
||||
}
|
||||
|
||||
pub(crate) fn to_proto(&self) -> proto::ViewId {
|
||||
pub(crate) fn to_proto(self) -> proto::ViewId {
|
||||
proto::ViewId {
|
||||
creator: Some(self.creator),
|
||||
id: self.id,
|
||||
|
@ -5061,7 +5056,7 @@ async fn join_channel_internal(
|
|||
|
||||
let already_in_channel = room.channel_id() == Some(channel_id);
|
||||
let should_prompt = room.is_sharing_project()
|
||||
&& room.remote_participants().len() > 0
|
||||
&& !room.remote_participants().is_empty()
|
||||
&& !already_in_channel;
|
||||
let open_room = if already_in_channel {
|
||||
active_call.room().cloned()
|
||||
|
@ -5266,7 +5261,7 @@ pub fn join_channel(
|
|||
}
|
||||
|
||||
// return ok, we showed the error to the user.
|
||||
return anyhow::Ok(());
|
||||
anyhow::Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -5468,7 +5463,7 @@ pub fn join_hosted_project(
|
|||
.is_ok_and(|workspace| {
|
||||
workspace.project().read(cx).hosted_project_id() == Some(hosted_project_id)
|
||||
})
|
||||
.then(|| workspace)
|
||||
.then_some(workspace)
|
||||
})
|
||||
})?;
|
||||
|
||||
|
@ -5488,8 +5483,7 @@ pub fn join_hosted_project(
|
|||
let window_bounds_override = window_bounds_env_override();
|
||||
cx.update(|cx| {
|
||||
let mut options = (app_state.build_window_options)(None, cx);
|
||||
options.window_bounds =
|
||||
window_bounds_override.map(|bounds| WindowBounds::Windowed(bounds));
|
||||
options.window_bounds = window_bounds_override.map(WindowBounds::Windowed);
|
||||
cx.open_window(options, |cx| {
|
||||
cx.new_view(|cx| {
|
||||
Workspace::new(Default::default(), project, app_state.clone(), cx)
|
||||
|
@ -5563,8 +5557,7 @@ pub fn join_dev_server_project(
|
|||
let window_bounds_override = window_bounds_env_override();
|
||||
cx.update(|cx| {
|
||||
let mut options = (app_state.build_window_options)(None, cx);
|
||||
options.window_bounds =
|
||||
window_bounds_override.map(|bounds| WindowBounds::Windowed(bounds));
|
||||
options.window_bounds = window_bounds_override.map(WindowBounds::Windowed);
|
||||
cx.open_window(options, |cx| {
|
||||
cx.new_view(|cx| {
|
||||
Workspace::new(Some(workspace_id), project, app_state.clone(), cx)
|
||||
|
@ -5626,8 +5619,7 @@ pub fn join_in_room_project(
|
|||
let window_bounds_override = window_bounds_env_override();
|
||||
cx.update(|cx| {
|
||||
let mut options = (app_state.build_window_options)(None, cx);
|
||||
options.window_bounds =
|
||||
window_bounds_override.map(|bounds| WindowBounds::Windowed(bounds));
|
||||
options.window_bounds = window_bounds_override.map(WindowBounds::Windowed);
|
||||
cx.open_window(options, |cx| {
|
||||
cx.new_view(|cx| {
|
||||
Workspace::new(Default::default(), project, app_state.clone(), cx)
|
||||
|
@ -5733,6 +5725,224 @@ fn parse_pixel_size_env_var(value: &str) -> Option<Size<Pixels>> {
|
|||
Some(size(px(width as f32), px(height as f32)))
|
||||
}
|
||||
|
||||
pub fn client_side_decorations(element: impl IntoElement, cx: &mut WindowContext) -> Stateful<Div> {
|
||||
const BORDER_SIZE: Pixels = px(1.0);
|
||||
let decorations = cx.window_decorations();
|
||||
|
||||
if matches!(decorations, Decorations::Client { .. }) {
|
||||
cx.set_client_inset(theme::CLIENT_SIDE_DECORATION_SHADOW);
|
||||
}
|
||||
|
||||
struct GlobalResizeEdge(ResizeEdge);
|
||||
impl Global for GlobalResizeEdge {}
|
||||
|
||||
div()
|
||||
.id("window-backdrop")
|
||||
.bg(transparent_black())
|
||||
.map(|div| match decorations {
|
||||
Decorations::Server => div,
|
||||
Decorations::Client { tiling, .. } => div
|
||||
.when(!(tiling.top || tiling.right), |div| {
|
||||
div.rounded_tr(theme::CLIENT_SIDE_DECORATION_ROUNDING)
|
||||
})
|
||||
.when(!(tiling.top || tiling.left), |div| {
|
||||
div.rounded_tl(theme::CLIENT_SIDE_DECORATION_ROUNDING)
|
||||
})
|
||||
.when(!(tiling.bottom || tiling.right), |div| {
|
||||
div.rounded_br(theme::CLIENT_SIDE_DECORATION_ROUNDING)
|
||||
})
|
||||
.when(!(tiling.bottom || tiling.left), |div| {
|
||||
div.rounded_bl(theme::CLIENT_SIDE_DECORATION_ROUNDING)
|
||||
})
|
||||
.when(!tiling.top, |div| {
|
||||
div.pt(theme::CLIENT_SIDE_DECORATION_SHADOW)
|
||||
})
|
||||
.when(!tiling.bottom, |div| {
|
||||
div.pb(theme::CLIENT_SIDE_DECORATION_SHADOW)
|
||||
})
|
||||
.when(!tiling.left, |div| {
|
||||
div.pl(theme::CLIENT_SIDE_DECORATION_SHADOW)
|
||||
})
|
||||
.when(!tiling.right, |div| {
|
||||
div.pr(theme::CLIENT_SIDE_DECORATION_SHADOW)
|
||||
})
|
||||
.on_mouse_move(move |e, cx| {
|
||||
let size = cx.window_bounds().get_bounds().size;
|
||||
let pos = e.position;
|
||||
|
||||
let new_edge =
|
||||
resize_edge(pos, theme::CLIENT_SIDE_DECORATION_SHADOW, size, tiling);
|
||||
|
||||
let edge = cx.try_global::<GlobalResizeEdge>();
|
||||
if new_edge != edge.map(|edge| edge.0) {
|
||||
cx.window_handle()
|
||||
.update(cx, |workspace, cx| cx.notify(workspace.entity_id()))
|
||||
.ok();
|
||||
}
|
||||
})
|
||||
.on_mouse_down(MouseButton::Left, move |e, cx| {
|
||||
let size = cx.window_bounds().get_bounds().size;
|
||||
let pos = e.position;
|
||||
|
||||
let edge = match resize_edge(
|
||||
pos,
|
||||
theme::CLIENT_SIDE_DECORATION_SHADOW,
|
||||
size,
|
||||
tiling,
|
||||
) {
|
||||
Some(value) => value,
|
||||
None => return,
|
||||
};
|
||||
|
||||
cx.start_window_resize(edge);
|
||||
}),
|
||||
})
|
||||
.size_full()
|
||||
.child(
|
||||
div()
|
||||
.cursor(CursorStyle::Arrow)
|
||||
.map(|div| match decorations {
|
||||
Decorations::Server => div,
|
||||
Decorations::Client { tiling } => div
|
||||
.border_color(cx.theme().colors().border)
|
||||
.when(!(tiling.top || tiling.right), |div| {
|
||||
div.rounded_tr(theme::CLIENT_SIDE_DECORATION_ROUNDING)
|
||||
})
|
||||
.when(!(tiling.top || tiling.left), |div| {
|
||||
div.rounded_tl(theme::CLIENT_SIDE_DECORATION_ROUNDING)
|
||||
})
|
||||
.when(!(tiling.bottom || tiling.right), |div| {
|
||||
div.rounded_br(theme::CLIENT_SIDE_DECORATION_ROUNDING)
|
||||
})
|
||||
.when(!(tiling.bottom || tiling.left), |div| {
|
||||
div.rounded_bl(theme::CLIENT_SIDE_DECORATION_ROUNDING)
|
||||
})
|
||||
.when(!tiling.top, |div| div.border_t(BORDER_SIZE))
|
||||
.when(!tiling.bottom, |div| div.border_b(BORDER_SIZE))
|
||||
.when(!tiling.left, |div| div.border_l(BORDER_SIZE))
|
||||
.when(!tiling.right, |div| div.border_r(BORDER_SIZE))
|
||||
.when(!tiling.is_tiled(), |div| {
|
||||
div.shadow(smallvec::smallvec![gpui::BoxShadow {
|
||||
color: Hsla {
|
||||
h: 0.,
|
||||
s: 0.,
|
||||
l: 0.,
|
||||
a: 0.4,
|
||||
},
|
||||
blur_radius: theme::CLIENT_SIDE_DECORATION_SHADOW / 2.,
|
||||
spread_radius: px(0.),
|
||||
offset: point(px(0.0), px(0.0)),
|
||||
}])
|
||||
}),
|
||||
})
|
||||
.on_mouse_move(|_e, cx| {
|
||||
cx.stop_propagation();
|
||||
})
|
||||
.size_full()
|
||||
.child(element),
|
||||
)
|
||||
.map(|div| match decorations {
|
||||
Decorations::Server => div,
|
||||
Decorations::Client { tiling, .. } => div.child(
|
||||
canvas(
|
||||
|_bounds, cx| {
|
||||
cx.insert_hitbox(
|
||||
Bounds::new(
|
||||
point(px(0.0), px(0.0)),
|
||||
cx.window_bounds().get_bounds().size,
|
||||
),
|
||||
false,
|
||||
)
|
||||
},
|
||||
move |_bounds, hitbox, cx| {
|
||||
let mouse = cx.mouse_position();
|
||||
let size = cx.window_bounds().get_bounds().size;
|
||||
let Some(edge) =
|
||||
resize_edge(mouse, theme::CLIENT_SIDE_DECORATION_SHADOW, size, tiling)
|
||||
else {
|
||||
return;
|
||||
};
|
||||
cx.set_global(GlobalResizeEdge(edge));
|
||||
cx.set_cursor_style(
|
||||
match edge {
|
||||
ResizeEdge::Top | ResizeEdge::Bottom => CursorStyle::ResizeUpDown,
|
||||
ResizeEdge::Left | ResizeEdge::Right => {
|
||||
CursorStyle::ResizeLeftRight
|
||||
}
|
||||
ResizeEdge::TopLeft | ResizeEdge::BottomRight => {
|
||||
CursorStyle::ResizeUpLeftDownRight
|
||||
}
|
||||
ResizeEdge::TopRight | ResizeEdge::BottomLeft => {
|
||||
CursorStyle::ResizeUpRightDownLeft
|
||||
}
|
||||
},
|
||||
&hitbox,
|
||||
);
|
||||
},
|
||||
)
|
||||
.size_full()
|
||||
.absolute(),
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
fn resize_edge(
|
||||
pos: Point<Pixels>,
|
||||
shadow_size: Pixels,
|
||||
window_size: Size<Pixels>,
|
||||
tiling: Tiling,
|
||||
) -> Option<ResizeEdge> {
|
||||
let bounds = Bounds::new(Point::default(), window_size).inset(shadow_size * 1.5);
|
||||
if bounds.contains(&pos) {
|
||||
return None;
|
||||
}
|
||||
|
||||
let corner_size = size(shadow_size * 1.5, shadow_size * 1.5);
|
||||
let top_left_bounds = Bounds::new(Point::new(px(0.), px(0.)), corner_size);
|
||||
if !tiling.top && top_left_bounds.contains(&pos) {
|
||||
return Some(ResizeEdge::TopLeft);
|
||||
}
|
||||
|
||||
let top_right_bounds = Bounds::new(
|
||||
Point::new(window_size.width - corner_size.width, px(0.)),
|
||||
corner_size,
|
||||
);
|
||||
if !tiling.top && top_right_bounds.contains(&pos) {
|
||||
return Some(ResizeEdge::TopRight);
|
||||
}
|
||||
|
||||
let bottom_left_bounds = Bounds::new(
|
||||
Point::new(px(0.), window_size.height - corner_size.height),
|
||||
corner_size,
|
||||
);
|
||||
if !tiling.bottom && bottom_left_bounds.contains(&pos) {
|
||||
return Some(ResizeEdge::BottomLeft);
|
||||
}
|
||||
|
||||
let bottom_right_bounds = Bounds::new(
|
||||
Point::new(
|
||||
window_size.width - corner_size.width,
|
||||
window_size.height - corner_size.height,
|
||||
),
|
||||
corner_size,
|
||||
);
|
||||
if !tiling.bottom && bottom_right_bounds.contains(&pos) {
|
||||
return Some(ResizeEdge::BottomRight);
|
||||
}
|
||||
|
||||
if !tiling.top && pos.y < shadow_size {
|
||||
Some(ResizeEdge::Top)
|
||||
} else if !tiling.bottom && pos.y > window_size.height - shadow_size {
|
||||
Some(ResizeEdge::Bottom)
|
||||
} else if !tiling.left && pos.x < shadow_size {
|
||||
Some(ResizeEdge::Left)
|
||||
} else if !tiling.right && pos.x > window_size.width - shadow_size {
|
||||
Some(ResizeEdge::Right)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
|
@ -5906,7 +6116,7 @@ mod tests {
|
|||
let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project.clone(), cx));
|
||||
|
||||
// When there are no dirty items, there's nothing to do.
|
||||
let item1 = cx.new_view(|cx| TestItem::new(cx));
|
||||
let item1 = cx.new_view(TestItem::new);
|
||||
workspace.update(cx, |w, cx| {
|
||||
w.add_item_to_active_pane(Box::new(item1.clone()), None, true, cx)
|
||||
});
|
||||
|
@ -6381,7 +6591,7 @@ mod tests {
|
|||
|
||||
let pane = workspace.update(cx, |workspace, _| workspace.active_pane().clone());
|
||||
pane.update(cx, |pane, cx| {
|
||||
let item = cx.new_view(|cx| TestItem::new(cx));
|
||||
let item = cx.new_view(TestItem::new);
|
||||
pane.add_item(Box::new(item), true, true, None, cx);
|
||||
});
|
||||
|
||||
|
@ -7189,221 +7399,3 @@ mod tests {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
pub fn client_side_decorations(element: impl IntoElement, cx: &mut WindowContext) -> Stateful<Div> {
|
||||
const BORDER_SIZE: Pixels = px(1.0);
|
||||
let decorations = cx.window_decorations();
|
||||
|
||||
if matches!(decorations, Decorations::Client { .. }) {
|
||||
cx.set_client_inset(theme::CLIENT_SIDE_DECORATION_SHADOW);
|
||||
}
|
||||
|
||||
struct GlobalResizeEdge(ResizeEdge);
|
||||
impl Global for GlobalResizeEdge {}
|
||||
|
||||
div()
|
||||
.id("window-backdrop")
|
||||
.bg(transparent_black())
|
||||
.map(|div| match decorations {
|
||||
Decorations::Server => div,
|
||||
Decorations::Client { tiling, .. } => div
|
||||
.when(!(tiling.top || tiling.right), |div| {
|
||||
div.rounded_tr(theme::CLIENT_SIDE_DECORATION_ROUNDING)
|
||||
})
|
||||
.when(!(tiling.top || tiling.left), |div| {
|
||||
div.rounded_tl(theme::CLIENT_SIDE_DECORATION_ROUNDING)
|
||||
})
|
||||
.when(!(tiling.bottom || tiling.right), |div| {
|
||||
div.rounded_br(theme::CLIENT_SIDE_DECORATION_ROUNDING)
|
||||
})
|
||||
.when(!(tiling.bottom || tiling.left), |div| {
|
||||
div.rounded_bl(theme::CLIENT_SIDE_DECORATION_ROUNDING)
|
||||
})
|
||||
.when(!tiling.top, |div| {
|
||||
div.pt(theme::CLIENT_SIDE_DECORATION_SHADOW)
|
||||
})
|
||||
.when(!tiling.bottom, |div| {
|
||||
div.pb(theme::CLIENT_SIDE_DECORATION_SHADOW)
|
||||
})
|
||||
.when(!tiling.left, |div| {
|
||||
div.pl(theme::CLIENT_SIDE_DECORATION_SHADOW)
|
||||
})
|
||||
.when(!tiling.right, |div| {
|
||||
div.pr(theme::CLIENT_SIDE_DECORATION_SHADOW)
|
||||
})
|
||||
.on_mouse_move(move |e, cx| {
|
||||
let size = cx.window_bounds().get_bounds().size;
|
||||
let pos = e.position;
|
||||
|
||||
let new_edge =
|
||||
resize_edge(pos, theme::CLIENT_SIDE_DECORATION_SHADOW, size, tiling);
|
||||
|
||||
let edge = cx.try_global::<GlobalResizeEdge>();
|
||||
if new_edge != edge.map(|edge| edge.0) {
|
||||
cx.window_handle()
|
||||
.update(cx, |workspace, cx| cx.notify(workspace.entity_id()))
|
||||
.ok();
|
||||
}
|
||||
})
|
||||
.on_mouse_down(MouseButton::Left, move |e, cx| {
|
||||
let size = cx.window_bounds().get_bounds().size;
|
||||
let pos = e.position;
|
||||
|
||||
let edge = match resize_edge(
|
||||
pos,
|
||||
theme::CLIENT_SIDE_DECORATION_SHADOW,
|
||||
size,
|
||||
tiling,
|
||||
) {
|
||||
Some(value) => value,
|
||||
None => return,
|
||||
};
|
||||
|
||||
cx.start_window_resize(edge);
|
||||
}),
|
||||
})
|
||||
.size_full()
|
||||
.child(
|
||||
div()
|
||||
.cursor(CursorStyle::Arrow)
|
||||
.map(|div| match decorations {
|
||||
Decorations::Server => div,
|
||||
Decorations::Client { tiling } => div
|
||||
.border_color(cx.theme().colors().border)
|
||||
.when(!(tiling.top || tiling.right), |div| {
|
||||
div.rounded_tr(theme::CLIENT_SIDE_DECORATION_ROUNDING)
|
||||
})
|
||||
.when(!(tiling.top || tiling.left), |div| {
|
||||
div.rounded_tl(theme::CLIENT_SIDE_DECORATION_ROUNDING)
|
||||
})
|
||||
.when(!(tiling.bottom || tiling.right), |div| {
|
||||
div.rounded_br(theme::CLIENT_SIDE_DECORATION_ROUNDING)
|
||||
})
|
||||
.when(!(tiling.bottom || tiling.left), |div| {
|
||||
div.rounded_bl(theme::CLIENT_SIDE_DECORATION_ROUNDING)
|
||||
})
|
||||
.when(!tiling.top, |div| div.border_t(BORDER_SIZE))
|
||||
.when(!tiling.bottom, |div| div.border_b(BORDER_SIZE))
|
||||
.when(!tiling.left, |div| div.border_l(BORDER_SIZE))
|
||||
.when(!tiling.right, |div| div.border_r(BORDER_SIZE))
|
||||
.when(!tiling.is_tiled(), |div| {
|
||||
div.shadow(smallvec::smallvec![gpui::BoxShadow {
|
||||
color: Hsla {
|
||||
h: 0.,
|
||||
s: 0.,
|
||||
l: 0.,
|
||||
a: 0.4,
|
||||
},
|
||||
blur_radius: theme::CLIENT_SIDE_DECORATION_SHADOW / 2.,
|
||||
spread_radius: px(0.),
|
||||
offset: point(px(0.0), px(0.0)),
|
||||
}])
|
||||
}),
|
||||
})
|
||||
.on_mouse_move(|_e, cx| {
|
||||
cx.stop_propagation();
|
||||
})
|
||||
.size_full()
|
||||
.child(element),
|
||||
)
|
||||
.map(|div| match decorations {
|
||||
Decorations::Server => div,
|
||||
Decorations::Client { tiling, .. } => div.child(
|
||||
canvas(
|
||||
|_bounds, cx| {
|
||||
cx.insert_hitbox(
|
||||
Bounds::new(
|
||||
point(px(0.0), px(0.0)),
|
||||
cx.window_bounds().get_bounds().size,
|
||||
),
|
||||
false,
|
||||
)
|
||||
},
|
||||
move |_bounds, hitbox, cx| {
|
||||
let mouse = cx.mouse_position();
|
||||
let size = cx.window_bounds().get_bounds().size;
|
||||
let Some(edge) =
|
||||
resize_edge(mouse, theme::CLIENT_SIDE_DECORATION_SHADOW, size, tiling)
|
||||
else {
|
||||
return;
|
||||
};
|
||||
cx.set_global(GlobalResizeEdge(edge));
|
||||
cx.set_cursor_style(
|
||||
match edge {
|
||||
ResizeEdge::Top | ResizeEdge::Bottom => CursorStyle::ResizeUpDown,
|
||||
ResizeEdge::Left | ResizeEdge::Right => {
|
||||
CursorStyle::ResizeLeftRight
|
||||
}
|
||||
ResizeEdge::TopLeft | ResizeEdge::BottomRight => {
|
||||
CursorStyle::ResizeUpLeftDownRight
|
||||
}
|
||||
ResizeEdge::TopRight | ResizeEdge::BottomLeft => {
|
||||
CursorStyle::ResizeUpRightDownLeft
|
||||
}
|
||||
},
|
||||
&hitbox,
|
||||
);
|
||||
},
|
||||
)
|
||||
.size_full()
|
||||
.absolute(),
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
fn resize_edge(
|
||||
pos: Point<Pixels>,
|
||||
shadow_size: Pixels,
|
||||
window_size: Size<Pixels>,
|
||||
tiling: Tiling,
|
||||
) -> Option<ResizeEdge> {
|
||||
let bounds = Bounds::new(Point::default(), window_size).inset(shadow_size * 1.5);
|
||||
if bounds.contains(&pos) {
|
||||
return None;
|
||||
}
|
||||
|
||||
let corner_size = size(shadow_size * 1.5, shadow_size * 1.5);
|
||||
let top_left_bounds = Bounds::new(Point::new(px(0.), px(0.)), corner_size);
|
||||
if !tiling.top && top_left_bounds.contains(&pos) {
|
||||
return Some(ResizeEdge::TopLeft);
|
||||
}
|
||||
|
||||
let top_right_bounds = Bounds::new(
|
||||
Point::new(window_size.width - corner_size.width, px(0.)),
|
||||
corner_size,
|
||||
);
|
||||
if !tiling.top && top_right_bounds.contains(&pos) {
|
||||
return Some(ResizeEdge::TopRight);
|
||||
}
|
||||
|
||||
let bottom_left_bounds = Bounds::new(
|
||||
Point::new(px(0.), window_size.height - corner_size.height),
|
||||
corner_size,
|
||||
);
|
||||
if !tiling.bottom && bottom_left_bounds.contains(&pos) {
|
||||
return Some(ResizeEdge::BottomLeft);
|
||||
}
|
||||
|
||||
let bottom_right_bounds = Bounds::new(
|
||||
Point::new(
|
||||
window_size.width - corner_size.width,
|
||||
window_size.height - corner_size.height,
|
||||
),
|
||||
corner_size,
|
||||
);
|
||||
if !tiling.bottom && bottom_right_bounds.contains(&pos) {
|
||||
return Some(ResizeEdge::BottomRight);
|
||||
}
|
||||
|
||||
if !tiling.top && pos.y < shadow_size {
|
||||
Some(ResizeEdge::Top)
|
||||
} else if !tiling.bottom && pos.y > window_size.height - shadow_size {
|
||||
Some(ResizeEdge::Bottom)
|
||||
} else if !tiling.left && pos.x < shadow_size {
|
||||
Some(ResizeEdge::Left)
|
||||
} else if !tiling.right && pos.x > window_size.width - shadow_size {
|
||||
Some(ResizeEdge::Right)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue