|
| 1 | +use std::fmt::Debug; |
| 2 | + |
1 | 3 | use chrono::{DateTime, Utc}; |
2 | | -use gpui::Element; |
| 4 | +use gpui::{IntoElement, Render, View, WindowContext}; |
3 | 5 |
|
4 | 6 | use crate::async_list::AsyncListItem; |
5 | 7 |
|
6 | 8 | pub trait Message: Clone + AsyncListItem + Send { |
7 | | - fn get_author(&self) -> &impl MessageAuthor; |
8 | | - fn get_content(&self) -> impl Element; |
9 | | - fn get_identifier(&self) -> String; |
10 | | - fn get_nonce(&self) -> Option<&String>; |
| 9 | + type Identifier: Sized + Copy + Clone + Debug + Eq + PartialEq; |
| 10 | + type Author: MessageAuthor<Identifier = <Self as Message>::Identifier>; |
| 11 | + type Content: Render; |
| 12 | + |
| 13 | + fn get_author(&self) -> Self::Author; |
| 14 | + fn get_content(&self, cx: &mut WindowContext) -> View<Self::Content>; |
| 15 | + fn get_identifier(&self) -> Option<<Self as Message>::Identifier>; |
| 16 | + fn get_nonce(&self) -> impl PartialEq; |
11 | 17 | fn should_group(&self, previous: &Self) -> bool; |
12 | 18 | fn get_timestamp(&self) -> Option<DateTime<Utc>>; |
13 | 19 | } |
14 | 20 |
|
| 21 | +#[derive(Debug, Clone, Copy)] |
| 22 | +pub struct IconRenderConfig { |
| 23 | + size: usize, |
| 24 | +} |
| 25 | + |
| 26 | +impl Default for IconRenderConfig { |
| 27 | + fn default() -> Self { |
| 28 | + IconRenderConfig { size: 1024 } |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +impl IconRenderConfig { |
| 33 | + pub fn small() -> Self { |
| 34 | + IconRenderConfig { size: 32 } |
| 35 | + } |
| 36 | + |
| 37 | + pub fn with_size(mut self, size: usize) -> IconRenderConfig { |
| 38 | + self.size = size; |
| 39 | + self |
| 40 | + } |
| 41 | + |
| 42 | + pub fn size(&self) -> usize { |
| 43 | + self.size |
| 44 | + } |
| 45 | +} |
| 46 | + |
15 | 47 | pub trait MessageAuthor: PartialEq + Eq { |
16 | | - fn get_display_name(&self) -> impl Element; |
17 | | - fn get_icon(&self) -> String; |
18 | | - fn get_small_icon(&self) -> String; |
19 | | - fn get_id(&self) -> String; |
| 48 | + type Identifier: Sized + Copy + Clone + Debug + Eq + PartialEq; |
| 49 | + type DisplayName: IntoElement + Clone; |
| 50 | + type Icon: IntoElement + Clone; |
| 51 | + |
| 52 | + fn get_display_name(&self) -> Self::DisplayName; |
| 53 | + fn get_icon(&self, config: IconRenderConfig) -> Self::Icon; |
| 54 | + fn get_identifier(&self) -> Self::Identifier; |
20 | 55 | } |
0 commit comments