Add basic call/user UI in top-right corner.
Allow ui::Avatar to take custom data instead of always relying on URI resolution
This commit is contained in:
parent
0b67983ddf
commit
c191943849
6 changed files with 113 additions and 36 deletions
|
@ -37,7 +37,7 @@ use gpui::{
|
||||||
};
|
};
|
||||||
use project::Project;
|
use project::Project;
|
||||||
use theme::ActiveTheme;
|
use theme::ActiveTheme;
|
||||||
use ui::{h_stack, Button, ButtonVariant, Color, KeyBinding, Label, Tooltip};
|
use ui::{h_stack, Button, ButtonVariant, Color, IconButton, KeyBinding, Tooltip};
|
||||||
use workspace::Workspace;
|
use workspace::Workspace;
|
||||||
|
|
||||||
// const MAX_PROJECT_NAME_LENGTH: usize = 40;
|
// const MAX_PROJECT_NAME_LENGTH: usize = 40;
|
||||||
|
@ -85,6 +85,13 @@ impl Render for CollabTitlebarItem {
|
||||||
type Element = Stateful<Div>;
|
type Element = Stateful<Div>;
|
||||||
|
|
||||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||||
|
let is_in_room = self
|
||||||
|
.workspace
|
||||||
|
.update(cx, |this, cx| this.call_state().is_in_room(cx))
|
||||||
|
.unwrap_or_default();
|
||||||
|
let is_shared = is_in_room && self.project.read(cx).is_shared();
|
||||||
|
let current_user = self.user_store.read(cx).current_user();
|
||||||
|
let client = self.client.clone();
|
||||||
h_stack()
|
h_stack()
|
||||||
.id("titlebar")
|
.id("titlebar")
|
||||||
.justify_between()
|
.justify_between()
|
||||||
|
@ -149,8 +156,40 @@ impl Render for CollabTitlebarItem {
|
||||||
.into()
|
.into()
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
) // self.titlebar_item
|
)
|
||||||
.child(h_stack().child(Label::new("Right side titlebar item")))
|
.map(|this| {
|
||||||
|
if let Some(user) = current_user {
|
||||||
|
this.when_some(user.avatar.clone(), |this, avatar| {
|
||||||
|
this.child(ui::Avatar::new(avatar))
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
this.child(Button::new("Sign in").on_click(move |_, cx| {
|
||||||
|
let client = client.clone();
|
||||||
|
cx.spawn(move |cx| async move {
|
||||||
|
client.authenticate_and_connect(true, &cx).await?;
|
||||||
|
Ok::<(), anyhow::Error>(())
|
||||||
|
})
|
||||||
|
.detach_and_log_err(cx);
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}) // that's obviously wrong as we should check for current call,not current user
|
||||||
|
.when(is_in_room, |this| {
|
||||||
|
this.child(
|
||||||
|
h_stack()
|
||||||
|
.child(
|
||||||
|
h_stack()
|
||||||
|
.child(Button::new(if is_shared { "Unshare" } else { "Share" }))
|
||||||
|
.child(IconButton::new("leave-call", ui::Icon::Exit)),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
h_stack()
|
||||||
|
.child(IconButton::new("mute-microphone", ui::Icon::Mic))
|
||||||
|
.child(IconButton::new("mute-sound", ui::Icon::AudioOn))
|
||||||
|
.child(IconButton::new("screen-share", ui::Icon::Screen))
|
||||||
|
.pl_2(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,30 +1,59 @@
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Bounds, Element, InteractiveElement, InteractiveElementState, Interactivity, LayoutId, Pixels,
|
Bounds, Element, ImageData, InteractiveElement, InteractiveElementState, Interactivity,
|
||||||
RenderOnce, SharedString, StyleRefinement, Styled, WindowContext,
|
LayoutId, Pixels, RenderOnce, SharedString, StyleRefinement, Styled, WindowContext,
|
||||||
};
|
};
|
||||||
use futures::FutureExt;
|
use futures::FutureExt;
|
||||||
use util::ResultExt;
|
use util::ResultExt;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub enum ImageSource {
|
||||||
|
/// Image content will be loaded from provided URI at render time.
|
||||||
|
Uri(SharedString),
|
||||||
|
Data(Arc<ImageData>),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<SharedString> for ImageSource {
|
||||||
|
fn from(value: SharedString) -> Self {
|
||||||
|
Self::Uri(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Arc<ImageData>> for ImageSource {
|
||||||
|
fn from(value: Arc<ImageData>) -> Self {
|
||||||
|
Self::Data(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Img {
|
pub struct Img {
|
||||||
interactivity: Interactivity,
|
interactivity: Interactivity,
|
||||||
uri: Option<SharedString>,
|
source: Option<ImageSource>,
|
||||||
grayscale: bool,
|
grayscale: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn img() -> Img {
|
pub fn img() -> Img {
|
||||||
Img {
|
Img {
|
||||||
interactivity: Interactivity::default(),
|
interactivity: Interactivity::default(),
|
||||||
uri: None,
|
source: None,
|
||||||
grayscale: false,
|
grayscale: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Img {
|
impl Img {
|
||||||
pub fn uri(mut self, uri: impl Into<SharedString>) -> Self {
|
pub fn uri(mut self, uri: impl Into<SharedString>) -> Self {
|
||||||
self.uri = Some(uri.into());
|
self.source = Some(ImageSource::from(uri.into()));
|
||||||
|
self
|
||||||
|
}
|
||||||
|
pub fn data(mut self, data: Arc<ImageData>) -> Self {
|
||||||
|
self.source = Some(ImageSource::from(data));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn source(mut self, source: impl Into<ImageSource>) -> Self {
|
||||||
|
self.source = Some(source.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
pub fn grayscale(mut self, grayscale: bool) -> Self {
|
pub fn grayscale(mut self, grayscale: bool) -> Self {
|
||||||
self.grayscale = grayscale;
|
self.grayscale = grayscale;
|
||||||
self
|
self
|
||||||
|
@ -58,28 +87,33 @@ impl Element for Img {
|
||||||
|style, _scroll_offset, cx| {
|
|style, _scroll_offset, cx| {
|
||||||
let corner_radii = style.corner_radii;
|
let corner_radii = style.corner_radii;
|
||||||
|
|
||||||
if let Some(uri) = self.uri.clone() {
|
if let Some(source) = self.source {
|
||||||
// eprintln!(">>> image_cache.get({uri}");
|
let image = match source {
|
||||||
let image_future = cx.image_cache.get(uri.clone());
|
ImageSource::Uri(uri) => {
|
||||||
// eprintln!("<<< image_cache.get({uri}");
|
let image_future = cx.image_cache.get(uri.clone());
|
||||||
if let Some(data) = image_future
|
if let Some(data) = image_future
|
||||||
.clone()
|
.clone()
|
||||||
.now_or_never()
|
.now_or_never()
|
||||||
.and_then(|result| result.ok())
|
.and_then(|result| result.ok())
|
||||||
{
|
{
|
||||||
let corner_radii = corner_radii.to_pixels(bounds.size, cx.rem_size());
|
data
|
||||||
cx.with_z_index(1, |cx| {
|
} else {
|
||||||
cx.paint_image(bounds, corner_radii, data, self.grayscale)
|
cx.spawn(|mut cx| async move {
|
||||||
.log_err()
|
if image_future.await.ok().is_some() {
|
||||||
});
|
cx.on_next_frame(|cx| cx.notify());
|
||||||
} else {
|
}
|
||||||
cx.spawn(|mut cx| async move {
|
})
|
||||||
if image_future.await.ok().is_some() {
|
.detach();
|
||||||
cx.on_next_frame(|cx| cx.notify());
|
return;
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
.detach()
|
ImageSource::Data(image) => image,
|
||||||
}
|
};
|
||||||
|
let corner_radii = corner_radii.to_pixels(bounds.size, cx.rem_size());
|
||||||
|
cx.with_z_index(1, |cx| {
|
||||||
|
cx.paint_image(bounds, corner_radii, image, self.grayscale)
|
||||||
|
.log_err()
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use gpui::{img, Img, RenderOnce};
|
use gpui::{img, ImageSource, Img, RenderOnce};
|
||||||
|
|
||||||
#[derive(Debug, Default, PartialEq, Clone)]
|
#[derive(Debug, Default, PartialEq, Clone)]
|
||||||
pub enum Shape {
|
pub enum Shape {
|
||||||
|
@ -10,7 +10,7 @@ pub enum Shape {
|
||||||
|
|
||||||
#[derive(RenderOnce)]
|
#[derive(RenderOnce)]
|
||||||
pub struct Avatar {
|
pub struct Avatar {
|
||||||
src: SharedString,
|
src: ImageSource,
|
||||||
shape: Shape,
|
shape: Shape,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ impl Component for Avatar {
|
||||||
img = img.rounded_md();
|
img = img.rounded_md();
|
||||||
}
|
}
|
||||||
|
|
||||||
img.uri(self.src.clone())
|
img.source(self.src.clone())
|
||||||
.size_4()
|
.size_4()
|
||||||
// todo!(Pull the avatar fallback background from the theme.)
|
// todo!(Pull the avatar fallback background from the theme.)
|
||||||
.bg(gpui::red())
|
.bg(gpui::red())
|
||||||
|
@ -34,7 +34,7 @@ impl Component for Avatar {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Avatar {
|
impl Avatar {
|
||||||
pub fn new(src: impl Into<SharedString>) -> Self {
|
pub fn new(src: impl Into<ImageSource>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
src: src.into(),
|
src: src.into(),
|
||||||
shape: Shape::Circle,
|
shape: Shape::Circle,
|
||||||
|
|
|
@ -14,10 +14,10 @@ impl Render for AvatarStory {
|
||||||
.child(Story::title_for::<Avatar>())
|
.child(Story::title_for::<Avatar>())
|
||||||
.child(Story::label("Default"))
|
.child(Story::label("Default"))
|
||||||
.child(Avatar::new(
|
.child(Avatar::new(
|
||||||
"https://avatars.githubusercontent.com/u/1714999?v=4",
|
"https://avatars.githubusercontent.com/u/1714999?v=4".into(),
|
||||||
))
|
))
|
||||||
.child(Avatar::new(
|
.child(Avatar::new(
|
||||||
"https://avatars.githubusercontent.com/u/326587?v=4",
|
"https://avatars.githubusercontent.com/u/326587?v=4".into(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ lazy_static! {
|
||||||
|
|
||||||
pub struct AppCommitSha(pub String);
|
pub struct AppCommitSha(pub String);
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, Default)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Default)]
|
||||||
pub enum ReleaseChannel {
|
pub enum ReleaseChannel {
|
||||||
#[default]
|
#[default]
|
||||||
Dev,
|
Dev,
|
||||||
|
|
|
@ -3408,6 +3408,10 @@ impl Workspace {
|
||||||
self.modal_layer
|
self.modal_layer
|
||||||
.update(cx, |modal_layer, cx| modal_layer.toggle_modal(cx, build))
|
.update(cx, |modal_layer, cx| modal_layer.toggle_modal(cx, build))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn call_state(&mut self) -> &mut dyn CallHandler {
|
||||||
|
&mut *self.call_handler
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn window_bounds_env_override(cx: &AsyncAppContext) -> Option<WindowBounds> {
|
fn window_bounds_env_override(cx: &AsyncAppContext) -> Option<WindowBounds> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue