feat: show facepill on tabpanel
This commit is contained in:
@@ -8,7 +8,6 @@ use gpui::{
|
||||
AnyElement, AnyView, AppContext, EventEmitter, FocusHandle, FocusableView, Global, Hsla,
|
||||
IntoElement, SharedString, View, WeakView, WindowContext,
|
||||
};
|
||||
use nostr_sdk::prelude::Metadata;
|
||||
use std::{collections::HashMap, sync::Arc};
|
||||
|
||||
pub enum PanelEvent {
|
||||
@@ -38,8 +37,8 @@ pub trait Panel: EventEmitter<PanelEvent> + FocusableView {
|
||||
/// Once you have defined a panel id, this must not be changed.
|
||||
fn panel_id(&self) -> SharedString;
|
||||
|
||||
/// The optional metadata of the panel
|
||||
fn panel_metadata(&self) -> Option<Metadata> {
|
||||
/// The optional facepile of the panel
|
||||
fn panel_facepile(&self, _cx: &WindowContext) -> Option<Vec<String>> {
|
||||
None
|
||||
}
|
||||
|
||||
@@ -76,7 +75,7 @@ pub trait Panel: EventEmitter<PanelEvent> + FocusableView {
|
||||
|
||||
pub trait PanelView: 'static + Send + Sync {
|
||||
fn panel_id(&self, cx: &WindowContext) -> SharedString;
|
||||
fn panel_metadata(&self, cx: &WindowContext) -> Option<Metadata>;
|
||||
fn panel_facepile(&self, cx: &WindowContext) -> Option<Vec<String>>;
|
||||
fn title(&self, _cx: &WindowContext) -> AnyElement;
|
||||
fn closeable(&self, cx: &WindowContext) -> bool;
|
||||
fn zoomable(&self, cx: &WindowContext) -> bool;
|
||||
@@ -92,8 +91,8 @@ impl<T: Panel> PanelView for View<T> {
|
||||
self.read(cx).panel_id()
|
||||
}
|
||||
|
||||
fn panel_metadata(&self, cx: &WindowContext) -> Option<Metadata> {
|
||||
self.read(cx).panel_metadata()
|
||||
fn panel_facepile(&self, cx: &WindowContext) -> Option<Vec<String>> {
|
||||
self.read(cx).panel_facepile(cx)
|
||||
}
|
||||
|
||||
fn title(&self, cx: &WindowContext) -> AnyElement {
|
||||
|
||||
@@ -516,26 +516,25 @@ impl TabPanel {
|
||||
.gap_1()
|
||||
.text_ellipsis()
|
||||
.text_xs()
|
||||
.child(div().when_some(
|
||||
panel.panel_metadata(cx),
|
||||
|this, metadata| {
|
||||
if let Some(picture) = metadata.picture {
|
||||
this.flex_shrink_0().child(
|
||||
img(format!(
|
||||
"https://wsrv.nl/?url={}&w=100&h=100&n=-1",
|
||||
picture
|
||||
))
|
||||
.size_4()
|
||||
.rounded_full()
|
||||
.object_fit(ObjectFit::Cover),
|
||||
)
|
||||
} else {
|
||||
this.flex_shrink_0().child(
|
||||
img("brand/avatar.png").size_4().rounded_full(),
|
||||
)
|
||||
}
|
||||
},
|
||||
))
|
||||
.when_some(panel.panel_facepile(cx), |this, facepill| {
|
||||
this.child(
|
||||
div()
|
||||
.flex()
|
||||
.flex_row_reverse()
|
||||
.items_center()
|
||||
.justify_start()
|
||||
.children(facepill.into_iter().enumerate().rev().map(
|
||||
|(ix, face)| {
|
||||
div().when(ix > 0, |div| div.ml_neg_1()).child(
|
||||
img(face)
|
||||
.size_4()
|
||||
.rounded_full()
|
||||
.object_fit(ObjectFit::Cover),
|
||||
)
|
||||
},
|
||||
)),
|
||||
)
|
||||
})
|
||||
.child(panel.title(cx)),
|
||||
)
|
||||
.when(state.draggable, |this| {
|
||||
@@ -595,7 +594,7 @@ impl TabPanel {
|
||||
active = false;
|
||||
}
|
||||
|
||||
Tab::new(("tab", ix), panel.title(cx), panel.panel_metadata(cx))
|
||||
Tab::new(("tab", ix), panel.title(cx), panel.panel_facepile(cx))
|
||||
.py_2()
|
||||
.selected(active)
|
||||
.disabled(disabled)
|
||||
|
||||
Reference in New Issue
Block a user