Start bringing back the current call section of the collab panel
Co-authored-by: Nathan <nathan@zed.dev>
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1753,7 +1753,7 @@ impl EditorElement {
|
||||
let gutter_width;
|
||||
let gutter_margin;
|
||||
if snapshot.show_gutter {
|
||||
let descent = cx.text_system().descent(font_id, font_size).unwrap();
|
||||
let descent = cx.text_system().descent(font_id, font_size);
|
||||
|
||||
let gutter_padding_factor = 3.5;
|
||||
gutter_padding = (em_width * gutter_padding_factor).round();
|
||||
@@ -3628,7 +3628,7 @@ fn compute_auto_height_layout(
|
||||
let gutter_width;
|
||||
let gutter_margin;
|
||||
if snapshot.show_gutter {
|
||||
let descent = cx.text_system().descent(font_id, font_size).unwrap();
|
||||
let descent = cx.text_system().descent(font_id, font_size);
|
||||
let gutter_padding_factor = 3.5;
|
||||
gutter_padding = (em_width * gutter_padding_factor).round();
|
||||
gutter_width = max_line_number_width + gutter_padding * 2.0;
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
use crate::{Bounds, Element, IntoElement, Pixels, StyleRefinement, Styled, WindowContext};
|
||||
|
||||
pub fn canvas(callback: impl 'static + FnOnce(Bounds<Pixels>, &mut WindowContext)) -> Canvas {
|
||||
Canvas {
|
||||
paint_callback: Box::new(callback),
|
||||
style: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Canvas {
|
||||
paint_callback: Box<dyn FnOnce(Bounds<Pixels>, &mut WindowContext)>,
|
||||
style: StyleRefinement,
|
||||
}
|
||||
|
||||
impl IntoElement for Canvas {
|
||||
type Element = Self;
|
||||
|
||||
fn element_id(&self) -> Option<crate::ElementId> {
|
||||
None
|
||||
}
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Element for Canvas {
|
||||
type State = ();
|
||||
|
||||
fn layout(
|
||||
&mut self,
|
||||
_: Option<Self::State>,
|
||||
cx: &mut WindowContext,
|
||||
) -> (crate::LayoutId, Self::State) {
|
||||
let layout_id = cx.request_layout(&self.style.clone().into(), []);
|
||||
(layout_id, ())
|
||||
}
|
||||
|
||||
fn paint(self, bounds: Bounds<Pixels>, _: &mut (), cx: &mut WindowContext) {
|
||||
(self.paint_callback)(bounds, cx)
|
||||
}
|
||||
}
|
||||
|
||||
impl Styled for Canvas {
|
||||
fn style(&mut self) -> &mut crate::StyleRefinement {
|
||||
&mut self.style
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
mod canvas;
|
||||
mod div;
|
||||
mod img;
|
||||
mod overlay;
|
||||
@@ -5,6 +6,7 @@ mod svg;
|
||||
mod text;
|
||||
mod uniform_list;
|
||||
|
||||
pub use canvas::*;
|
||||
pub use div::*;
|
||||
pub use img::*;
|
||||
pub use overlay::*;
|
||||
|
||||
@@ -72,7 +72,7 @@ impl TextSystem {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bounding_box(&self, font_id: FontId, font_size: Pixels) -> Result<Bounds<Pixels>> {
|
||||
pub fn bounding_box(&self, font_id: FontId, font_size: Pixels) -> Bounds<Pixels> {
|
||||
self.read_metrics(font_id, |metrics| metrics.bounding_box(font_size))
|
||||
}
|
||||
|
||||
@@ -89,9 +89,9 @@ impl TextSystem {
|
||||
let bounds = self
|
||||
.platform_text_system
|
||||
.typographic_bounds(font_id, glyph_id)?;
|
||||
self.read_metrics(font_id, |metrics| {
|
||||
Ok(self.read_metrics(font_id, |metrics| {
|
||||
(bounds / metrics.units_per_em as f32 * font_size.0).map(px)
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn advance(&self, font_id: FontId, font_size: Pixels, ch: char) -> Result<Size<Pixels>> {
|
||||
@@ -100,28 +100,28 @@ impl TextSystem {
|
||||
.glyph_for_char(font_id, ch)
|
||||
.ok_or_else(|| anyhow!("glyph not found for character '{}'", ch))?;
|
||||
let result = self.platform_text_system.advance(font_id, glyph_id)?
|
||||
/ self.units_per_em(font_id)? as f32;
|
||||
/ self.units_per_em(font_id) as f32;
|
||||
|
||||
Ok(result * font_size)
|
||||
}
|
||||
|
||||
pub fn units_per_em(&self, font_id: FontId) -> Result<u32> {
|
||||
pub fn units_per_em(&self, font_id: FontId) -> u32 {
|
||||
self.read_metrics(font_id, |metrics| metrics.units_per_em as u32)
|
||||
}
|
||||
|
||||
pub fn cap_height(&self, font_id: FontId, font_size: Pixels) -> Result<Pixels> {
|
||||
pub fn cap_height(&self, font_id: FontId, font_size: Pixels) -> Pixels {
|
||||
self.read_metrics(font_id, |metrics| metrics.cap_height(font_size))
|
||||
}
|
||||
|
||||
pub fn x_height(&self, font_id: FontId, font_size: Pixels) -> Result<Pixels> {
|
||||
pub fn x_height(&self, font_id: FontId, font_size: Pixels) -> Pixels {
|
||||
self.read_metrics(font_id, |metrics| metrics.x_height(font_size))
|
||||
}
|
||||
|
||||
pub fn ascent(&self, font_id: FontId, font_size: Pixels) -> Result<Pixels> {
|
||||
pub fn ascent(&self, font_id: FontId, font_size: Pixels) -> Pixels {
|
||||
self.read_metrics(font_id, |metrics| metrics.ascent(font_size))
|
||||
}
|
||||
|
||||
pub fn descent(&self, font_id: FontId, font_size: Pixels) -> Result<Pixels> {
|
||||
pub fn descent(&self, font_id: FontId, font_size: Pixels) -> Pixels {
|
||||
self.read_metrics(font_id, |metrics| metrics.descent(font_size))
|
||||
}
|
||||
|
||||
@@ -130,24 +130,24 @@ impl TextSystem {
|
||||
font_id: FontId,
|
||||
font_size: Pixels,
|
||||
line_height: Pixels,
|
||||
) -> Result<Pixels> {
|
||||
let ascent = self.ascent(font_id, font_size)?;
|
||||
let descent = self.descent(font_id, font_size)?;
|
||||
) -> Pixels {
|
||||
let ascent = self.ascent(font_id, font_size);
|
||||
let descent = self.descent(font_id, font_size);
|
||||
let padding_top = (line_height - ascent - descent) / 2.;
|
||||
Ok(padding_top + ascent)
|
||||
padding_top + ascent
|
||||
}
|
||||
|
||||
fn read_metrics<T>(&self, font_id: FontId, read: impl FnOnce(&FontMetrics) -> T) -> Result<T> {
|
||||
fn read_metrics<T>(&self, font_id: FontId, read: impl FnOnce(&FontMetrics) -> T) -> T {
|
||||
let lock = self.font_metrics.upgradable_read();
|
||||
|
||||
if let Some(metrics) = lock.get(&font_id) {
|
||||
Ok(read(metrics))
|
||||
read(metrics)
|
||||
} else {
|
||||
let mut lock = RwLockUpgradableReadGuard::upgrade(lock);
|
||||
let metrics = lock
|
||||
.entry(font_id)
|
||||
.or_insert_with(|| self.platform_text_system.font_metrics(font_id));
|
||||
Ok(read(metrics))
|
||||
read(metrics)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -101,9 +101,7 @@ fn paint_line(
|
||||
let mut glyph_origin = origin;
|
||||
let mut prev_glyph_position = Point::default();
|
||||
for (run_ix, run) in layout.runs.iter().enumerate() {
|
||||
let max_glyph_size = text_system
|
||||
.bounding_box(run.font_id, layout.font_size)?
|
||||
.size;
|
||||
let max_glyph_size = text_system.bounding_box(run.font_id, layout.font_size).size;
|
||||
|
||||
for (glyph_ix, glyph) in run.glyphs.iter().enumerate() {
|
||||
glyph_origin.x += glyph.position.x - prev_glyph_position.x;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use gpui::{
|
||||
px, AnyElement, ClickEvent, Div, ImageSource, MouseButton, MouseDownEvent, Pixels, Stateful,
|
||||
px, AnyElement, AnyView, ClickEvent, Div, ImageSource, MouseButton, MouseDownEvent, Pixels,
|
||||
Stateful,
|
||||
};
|
||||
use smallvec::SmallVec;
|
||||
|
||||
@@ -21,6 +22,7 @@ pub struct ListItem {
|
||||
inset: bool,
|
||||
on_click: Option<Rc<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,
|
||||
on_toggle: Option<Rc<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,
|
||||
tooltip: Option<Box<dyn Fn(&mut WindowContext) -> AnyView + 'static>>,
|
||||
on_secondary_mouse_down: Option<Rc<dyn Fn(&MouseDownEvent, &mut WindowContext) + 'static>>,
|
||||
children: SmallVec<[AnyElement; 2]>,
|
||||
}
|
||||
@@ -38,6 +40,7 @@ impl ListItem {
|
||||
on_click: None,
|
||||
on_secondary_mouse_down: None,
|
||||
on_toggle: None,
|
||||
tooltip: None,
|
||||
children: SmallVec::new(),
|
||||
}
|
||||
}
|
||||
@@ -55,6 +58,11 @@ impl ListItem {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn tooltip(mut self, tooltip: impl Fn(&mut WindowContext) -> AnyView + 'static) -> Self {
|
||||
self.tooltip = Some(Box::new(tooltip));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn inset(mut self, inset: bool) -> Self {
|
||||
self.inset = inset;
|
||||
self
|
||||
@@ -149,6 +157,7 @@ impl RenderOnce for ListItem {
|
||||
(on_mouse_down)(event, cx)
|
||||
})
|
||||
})
|
||||
.when_some(self.tooltip, |this, tooltip| this.tooltip(tooltip))
|
||||
.child(
|
||||
div()
|
||||
.when(self.inset, |this| this.px_2())
|
||||
|
||||
@@ -4314,101 +4314,102 @@ pub fn create_and_open_local_file(
|
||||
})
|
||||
}
|
||||
|
||||
// pub fn join_remote_project(
|
||||
// project_id: u64,
|
||||
// follow_user_id: u64,
|
||||
// app_state: Arc<AppState>,
|
||||
// cx: &mut AppContext,
|
||||
// ) -> Task<Result<()>> {
|
||||
// cx.spawn(|mut cx| async move {
|
||||
// let windows = cx.windows();
|
||||
// let existing_workspace = windows.into_iter().find_map(|window| {
|
||||
// window.downcast::<Workspace>().and_then(|window| {
|
||||
// window
|
||||
// .read_root_with(&cx, |workspace, cx| {
|
||||
// if workspace.project().read(cx).remote_id() == Some(project_id) {
|
||||
// Some(cx.handle().downgrade())
|
||||
// } else {
|
||||
// None
|
||||
// }
|
||||
// })
|
||||
// .unwrap_or(None)
|
||||
// })
|
||||
// });
|
||||
pub fn join_remote_project(
|
||||
project_id: u64,
|
||||
follow_user_id: u64,
|
||||
app_state: Arc<AppState>,
|
||||
cx: &mut AppContext,
|
||||
) -> Task<Result<()>> {
|
||||
todo!()
|
||||
// let windows = cx.windows();
|
||||
// cx.spawn(|mut cx| async move {
|
||||
// let existing_workspace = windows.into_iter().find_map(|window| {
|
||||
// window.downcast::<Workspace>().and_then(|window| {
|
||||
// window
|
||||
// .update(&mut cx, |workspace, cx| {
|
||||
// if workspace.project().read(cx).remote_id() == Some(project_id) {
|
||||
// Some(cx.view().downgrade())
|
||||
// } else {
|
||||
// None
|
||||
// }
|
||||
// })
|
||||
// .unwrap_or(None)
|
||||
// })
|
||||
// });
|
||||
|
||||
// let workspace = if let Some(existing_workspace) = existing_workspace {
|
||||
// existing_workspace
|
||||
// } else {
|
||||
// let active_call = cx.read(ActiveCall::global);
|
||||
// let room = active_call
|
||||
// .read_with(&cx, |call, _| call.room().cloned())
|
||||
// .ok_or_else(|| anyhow!("not in a call"))?;
|
||||
// let project = room
|
||||
// .update(&mut cx, |room, cx| {
|
||||
// room.join_project(
|
||||
// project_id,
|
||||
// app_state.languages.clone(),
|
||||
// app_state.fs.clone(),
|
||||
// cx,
|
||||
// )
|
||||
// })
|
||||
// .await?;
|
||||
// let workspace = if let Some(existing_workspace) = existing_workspace {
|
||||
// existing_workspace
|
||||
// } else {
|
||||
// let active_call = cx.update(ActiveCall::global);
|
||||
// let room = active_call
|
||||
// .read_with(&cx, |call, _| call.room().cloned())
|
||||
// .ok_or_else(|| anyhow!("not in a call"))?;
|
||||
// let project = room
|
||||
// .update(&mut cx, |room, cx| {
|
||||
// room.join_project(
|
||||
// project_id,
|
||||
// app_state.languages.clone(),
|
||||
// app_state.fs.clone(),
|
||||
// cx,
|
||||
// )
|
||||
// })
|
||||
// .await?;
|
||||
|
||||
// let window_bounds_override = window_bounds_env_override(&cx);
|
||||
// let window = cx.add_window(
|
||||
// (app_state.build_window_options)(
|
||||
// window_bounds_override,
|
||||
// None,
|
||||
// cx.platform().as_ref(),
|
||||
// ),
|
||||
// |cx| Workspace::new(0, project, app_state.clone(), cx),
|
||||
// );
|
||||
// let workspace = window.root(&cx).unwrap();
|
||||
// (app_state.initialize_workspace)(
|
||||
// workspace.downgrade(),
|
||||
// false,
|
||||
// app_state.clone(),
|
||||
// cx.clone(),
|
||||
// )
|
||||
// .await
|
||||
// .log_err();
|
||||
// let window_bounds_override = window_bounds_env_override(&cx);
|
||||
// let window = cx.add_window(
|
||||
// (app_state.build_window_options)(
|
||||
// window_bounds_override,
|
||||
// None,
|
||||
// cx.platform().as_ref(),
|
||||
// ),
|
||||
// |cx| Workspace::new(0, project, app_state.clone(), cx),
|
||||
// );
|
||||
// let workspace = window.root(&cx).unwrap();
|
||||
// (app_state.initialize_workspace)(
|
||||
// workspace.downgrade(),
|
||||
// false,
|
||||
// app_state.clone(),
|
||||
// cx.clone(),
|
||||
// )
|
||||
// .await
|
||||
// .log_err();
|
||||
|
||||
// workspace.downgrade()
|
||||
// };
|
||||
// workspace.downgrade()
|
||||
// };
|
||||
|
||||
// workspace.window().activate(&mut cx);
|
||||
// cx.platform().activate(true);
|
||||
// workspace.window().activate(&mut cx);
|
||||
// cx.platform().activate(true);
|
||||
|
||||
// workspace.update(&mut cx, |workspace, cx| {
|
||||
// if let Some(room) = ActiveCall::global(cx).read(cx).room().cloned() {
|
||||
// let follow_peer_id = room
|
||||
// .read(cx)
|
||||
// .remote_participants()
|
||||
// .iter()
|
||||
// .find(|(_, participant)| participant.user.id == follow_user_id)
|
||||
// .map(|(_, p)| p.peer_id)
|
||||
// .or_else(|| {
|
||||
// // If we couldn't follow the given user, follow the host instead.
|
||||
// let collaborator = workspace
|
||||
// .project()
|
||||
// .read(cx)
|
||||
// .collaborators()
|
||||
// .values()
|
||||
// .find(|collaborator| collaborator.replica_id == 0)?;
|
||||
// Some(collaborator.peer_id)
|
||||
// });
|
||||
// workspace.update(&mut cx, |workspace, cx| {
|
||||
// if let Some(room) = ActiveCall::global(cx).read(cx).room().cloned() {
|
||||
// let follow_peer_id = room
|
||||
// .read(cx)
|
||||
// .remote_participants()
|
||||
// .iter()
|
||||
// .find(|(_, participant)| participant.user.id == follow_user_id)
|
||||
// .map(|(_, p)| p.peer_id)
|
||||
// .or_else(|| {
|
||||
// // If we couldn't follow the given user, follow the host instead.
|
||||
// let collaborator = workspace
|
||||
// .project()
|
||||
// .read(cx)
|
||||
// .collaborators()
|
||||
// .values()
|
||||
// .find(|collaborator| collaborator.replica_id == 0)?;
|
||||
// Some(collaborator.peer_id)
|
||||
// });
|
||||
|
||||
// if let Some(follow_peer_id) = follow_peer_id {
|
||||
// workspace
|
||||
// .follow(follow_peer_id, cx)
|
||||
// .map(|follow| follow.detach_and_log_err(cx));
|
||||
// }
|
||||
// }
|
||||
// })?;
|
||||
// if let Some(follow_peer_id) = follow_peer_id {
|
||||
// workspace
|
||||
// .follow(follow_peer_id, cx)
|
||||
// .map(|follow| follow.detach_and_log_err(cx));
|
||||
// }
|
||||
// }
|
||||
// })?;
|
||||
|
||||
// anyhow::Ok(())
|
||||
// })
|
||||
// }
|
||||
// anyhow::Ok(())
|
||||
// })
|
||||
}
|
||||
|
||||
pub fn restart(_: &Restart, cx: &mut AppContext) {
|
||||
let should_confirm = WorkspaceSettings::get_global(cx).confirm_quit;
|
||||
|
||||
Reference in New Issue
Block a user