Tooltips for contacts

This commit is contained in:
Conrad Irwin 2023-10-03 12:54:39 -06:00
parent d8bfe77a3b
commit d696b394c4

View file

@ -621,7 +621,7 @@ impl CollabPanel {
contact, contact,
*calling, *calling,
&this.project, &this.project,
&theme.collab_panel, &theme,
is_selected, is_selected,
cx, cx,
), ),
@ -1658,15 +1658,19 @@ impl CollabPanel {
contact: &Contact, contact: &Contact,
calling: bool, calling: bool,
project: &ModelHandle<Project>, project: &ModelHandle<Project>,
theme: &theme::CollabPanel, theme: &theme::Theme,
is_selected: bool, is_selected: bool,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> AnyElement<Self> { ) -> AnyElement<Self> {
enum ContactTooltip {};
let collab_theme = &theme.collab_panel;
let online = contact.online; let online = contact.online;
let busy = contact.busy || calling; let busy = contact.busy || calling;
let user_id = contact.user.id; let user_id = contact.user.id;
let github_login = contact.user.github_login.clone(); let github_login = contact.user.github_login.clone();
let initial_project = project.clone(); let initial_project = project.clone();
let mut event_handler = let mut event_handler =
MouseEventHandler::new::<Contact, _>(contact.user.id as usize, cx, |state, cx| { MouseEventHandler::new::<Contact, _>(contact.user.id as usize, cx, |state, cx| {
Flex::row() Flex::row()
@ -1677,9 +1681,9 @@ impl CollabPanel {
.collapsed() .collapsed()
.contained() .contained()
.with_style(if busy { .with_style(if busy {
theme.contact_status_busy collab_theme.contact_status_busy
} else { } else {
theme.contact_status_free collab_theme.contact_status_free
}) })
.aligned(), .aligned(),
) )
@ -1689,7 +1693,7 @@ impl CollabPanel {
Stack::new() Stack::new()
.with_child( .with_child(
Image::from_data(avatar) Image::from_data(avatar)
.with_style(theme.contact_avatar) .with_style(collab_theme.contact_avatar)
.aligned() .aligned()
.left(), .left(),
) )
@ -1698,20 +1702,22 @@ impl CollabPanel {
.with_child( .with_child(
Label::new( Label::new(
contact.user.github_login.clone(), contact.user.github_login.clone(),
theme.contact_username.text.clone(), collab_theme.contact_username.text.clone(),
) )
.contained() .contained()
.with_style(theme.contact_username.container) .with_style(collab_theme.contact_username.container)
.aligned() .aligned()
.left() .left()
.flex(1., true), .flex(1., true),
) )
.with_child( .with_children(if state.hovered() {
Some(
MouseEventHandler::new::<Cancel, _>( MouseEventHandler::new::<Cancel, _>(
contact.user.id as usize, contact.user.id as usize,
cx, cx,
|mouse_state, _| { |mouse_state, _| {
let button_style = theme.contact_button.style_for(mouse_state); let button_style =
collab_theme.contact_button.style_for(mouse_state);
render_icon_button(button_style, "icons/x.svg") render_icon_button(button_style, "icons/x.svg")
.aligned() .aligned()
.flex_float() .flex_float()
@ -1724,32 +1730,66 @@ impl CollabPanel {
}) })
.flex_float(), .flex_float(),
) )
} else {
None
})
.with_children(if calling { .with_children(if calling {
Some( Some(
Label::new("Calling", theme.calling_indicator.text.clone()) Label::new("Calling", collab_theme.calling_indicator.text.clone())
.contained() .contained()
.with_style(theme.calling_indicator.container) .with_style(collab_theme.calling_indicator.container)
.aligned(), .aligned(),
) )
} else { } else {
None None
}) })
.constrained() .constrained()
.with_height(theme.row_height) .with_height(collab_theme.row_height)
.contained() .contained()
.with_style(*theme.contact_row.in_state(is_selected).style_for(state)) .with_style(
}) *collab_theme
.on_click(MouseButton::Left, move |_, this, cx| { .contact_row
if online && !busy { .in_state(is_selected)
this.call(user_id, Some(initial_project.clone()), cx); .style_for(state),
} )
}); });
if online { if online && !busy {
event_handler = event_handler.with_cursor_style(CursorStyle::PointingHand); let room = ActiveCall::global(cx).read(cx).room();
} let label = if room.is_some() {
format!("Invite {} to join call", contact.user.github_login)
} else {
format!("Call {}", contact.user.github_login)
};
event_handler.into_any() event_handler
.on_click(MouseButton::Left, move |_, this, cx| {
this.call(user_id, Some(initial_project.clone()), cx);
})
.with_cursor_style(CursorStyle::PointingHand)
.with_tooltip::<ContactTooltip>(
contact.user.id as usize,
label,
None,
theme.tooltip.clone(),
cx,
)
.into_any()
} else {
event_handler
.with_tooltip::<ContactTooltip>(
contact.user.id as usize,
format!(
"{} is {}",
contact.user.github_login,
if busy { "on a call" } else { "offline" }
),
None,
theme.tooltip.clone(),
cx,
)
.into_any()
}
} }
fn render_contact_placeholder( fn render_contact_placeholder(