From 1453a136803c5df79cc97fa6c685d4aa67e805ed Mon Sep 17 00:00:00 2001 From: alanpoon Date: Fri, 27 Sep 2024 19:07:16 +0800 Subject: [PATCH 01/62] emoji --- src/home/emoji.rs | 97 +++++++++++++++++++++++++++++++++++++++++ src/home/mod.rs | 2 + src/home/room_screen.rs | 25 ++++++----- 3 files changed, 113 insertions(+), 11 deletions(-) create mode 100644 src/home/emoji.rs diff --git a/src/home/emoji.rs b/src/home/emoji.rs new file mode 100644 index 0000000..246ec7e --- /dev/null +++ b/src/home/emoji.rs @@ -0,0 +1,97 @@ +use makepad_widgets::*; +use crate::shared::avatar::{Avatar}; +live_design!{ + import makepad_draw::shader::std::*; + EmojiSequencer = {{EmojiSequencer}} { + button: { + width: 15.0, + height: 15.0, + text_view = { text = { draw_text: { + text_style: { font_size: 6.0 } + }}} + } + margin: {top: 3, right: 10, bottom: 3, left: 10} + width: Fit, + height: Fit + } +} + +#[derive(Clone, Debug, Default, Eq, Hash, Copy, PartialEq, FromLiveId)] +pub struct ButtonId(pub LiveId); + +#[derive(Live, Widget)] +pub struct EmojiSequencer { + #[redraw] #[live] draw_text: DrawText, + #[rust] area: Area, + #[walk] walk: Walk, + #[live] button: Option, + #[live(false)] hover_actions_enabled: bool, + #[rust] buttons: ComponentMap, + #[rust] list: Vec +} + +impl LiveHook for EmojiSequencer { +fn after_apply(&mut self, cx: &mut Cx, apply: &mut Apply, index: usize, nodes: &[LiveNode]) { + for button in self.buttons.values_mut() { + if let Some(index) = nodes.child_by_name(index, live_id!(button).as_field()) { + button.apply(cx, apply, index, nodes); + } + } + self.area.redraw(cx); + } +} + +#[derive(Clone, Debug, DefaultNone)] +pub enum EmojiSequencerAction { + None +} +impl Widget for EmojiSequencer { + + fn handle_event(&mut self, cx: &mut Cx, event: &Event, scope: &mut Scope) { + let uid = self.widget_uid(); + for button in self.buttons.values_mut() { + + } + + } + + fn draw_walk(&mut self, cx: &mut Cx2d, scope: &mut Scope, walk: Walk) -> DrawStep { + cx.begin_turtle(walk, Layout::default()); + let button = self.button; + for (i,name) in vec![String::from("g"),String::from("k")].iter().enumerate(){ + + let btn_id = LiveId(i as u64).into(); + let btn = self.buttons.get_or_insert(cx, btn_id, | cx | { + Avatar::new_from_ptr(cx, button) + }); + btn.set_text(name); + btn.draw(cx, scope).unwrap(); + } + + cx.end_turtle_with_area(&mut self.area); + self.buttons.retain_visible(); + DrawStep::done() + } + + fn widget_to_data(&self, cx: &mut Cx, actions: &Actions, nodes: &mut LiveNodeVec, path: &[LiveId]) -> bool { + false + } + + fn data_to_widget(&mut self, cx: &mut Cx, nodes:&[LiveNode], path: &[LiveId]){ + } +} + +impl EmojiSequencerRef { + pub fn get_list(&self)->Vec{ + if let Some(inner) = self.borrow() { + return inner.list.clone(); + } + return vec![]; + } + pub fn set_list(&mut self,read_user_id:Vec){ + if let Some(mut inner) = self.borrow_mut() { + inner.list = read_user_id.iter().map(|f|f.to_string()).collect(); + } + } + +} diff --git a/src/home/mod.rs b/src/home/mod.rs index f4e0a25..911f6b4 100644 --- a/src/home/mod.rs +++ b/src/home/mod.rs @@ -8,6 +8,7 @@ pub mod rooms_list; pub mod rooms_sidebar; pub mod spaces_dock; pub mod welcome_screen; +pub mod emoji; pub fn live_design(cx: &mut Cx) { home_screen::live_design(cx); @@ -18,4 +19,5 @@ pub fn live_design(cx: &mut Cx) { main_content::live_design(cx); spaces_dock::live_design(cx); welcome_screen::live_design(cx); + emoji::live_design(cx); } diff --git a/src/home/room_screen.rs b/src/home/room_screen.rs index 43aee6c..9ad7fa0 100644 --- a/src/home/room_screen.rs +++ b/src/home/room_screen.rs @@ -17,21 +17,16 @@ use matrix_sdk_ui::timeline::{ }; use crate::{ - avatar_cache::{self, AvatarCacheEntry}, - event_preview::{text_preview_of_member_profile_change, text_preview_of_other_state, text_preview_of_redacted_message, text_preview_of_room_membership_change, text_preview_of_timeline_item}, - media_cache::{MediaCache, MediaCacheEntry}, - profile::{ + avatar_cache::{self, AvatarCacheEntry}, event_preview::{text_preview_of_member_profile_change, text_preview_of_other_state, text_preview_of_redacted_message, text_preview_of_room_membership_change, text_preview_of_timeline_item}, home::emoji::EmojiSequencerWidgetRefExt, media_cache::{MediaCache, MediaCacheEntry}, profile::{ user_profile::{AvatarState, ShowUserProfileAction, UserProfile, UserProfileAndRoomId, UserProfilePaneInfo, UserProfileSlidingPaneRef, UserProfileSlidingPaneWidgetExt}, user_profile_cache, - }, - shared::{ + }, shared::{ avatar::{AvatarRef, AvatarWidgetRefExt}, html_or_plaintext::{HtmlOrPlaintextRef, HtmlOrPlaintextWidgetRefExt}, text_or_image::{TextOrImageRef, TextOrImageWidgetRefExt}, - }, - sliding_sync::{get_client, submit_async_request, take_timeline_update_receiver, MatrixRequest}, - utils::{self, unix_time_millis_to_datetime, MediaFormatConst}, + }, sliding_sync::{get_client, submit_async_request, take_timeline_update_receiver, MatrixRequest}, utils::{self, unix_time_millis_to_datetime, MediaFormatConst} }; +use crate::home::emoji::*; use rangemap::RangeSet; live_design! { @@ -46,6 +41,7 @@ live_design! { import crate::shared::text_or_image::TextOrImage; import crate::shared::html_or_plaintext::*; import crate::profile::user_profile::UserProfileSlidingPane; + import crate::home::emoji::*; IMG_DEFAULT_AVATAR = dep("crate://self/resources/img/default_avatar.png") ICO_FAV = dep("crate://self/resources/icon_favorite.svg") @@ -289,6 +285,7 @@ live_design! { draw_fixed: { color: (REACTION_TEXT_COLOR) }, body: "" } + } // An empty view that takes up no space in the portal list. @@ -411,12 +408,13 @@ live_design! { text: "" } message = { } - + // { // margin: {top: 13.0, bottom: 5.0} // } message_annotations = {} + emoji_sequencer = {width: 200, height: 100, margin: {top: (12.0)}} } message_menu = {} @@ -1996,6 +1994,7 @@ fn populate_message_view( if existed && item_drawn_status.content_drawn { (item, true) } else { + println!("content.message {:?}",text); populate_text_message_content( &item.html_or_plaintext(id!(content.message)), text, @@ -2315,8 +2314,10 @@ fn draw_reactions( .set_visible(true); let mut label_text = String::new(); + let mut text_to_display_vec = vec![]; for (reaction_raw, reaction_senders) in reactions.iter() { // Just take the first char of the emoji, which ignores any variant selectors. + println!("reaction_raw {:?}",reaction_raw); let reaction_first_char = reaction_raw.chars().next().map(|c| c.to_string()); let reaction_str = reaction_first_char.as_deref().unwrap_or(reaction_raw); let text_to_display = emojis::get(reaction_str) @@ -2325,8 +2326,9 @@ fn draw_reactions( let count = reaction_senders.len(); // log!("Found reaction {:?} with count {}", text_to_display, count); label_text = format!("{label_text}:{}: {} ", text_to_display, count); + text_to_display_vec.push(text_to_display.to_string()); } - + message_item.emoji_sequencer(id!(content.emoji_sequencer)).set_list( text_to_display_vec); // Debugging: draw the item ID as a reaction if DRAW_ITEM_ID_REACTION { label_text = format!("{label_text}ID: {}", id); @@ -2334,6 +2336,7 @@ fn draw_reactions( let html_reaction_view = message_item.html(id!(message_annotations.html_content)); html_reaction_view.set_text(&label_text); + } From 5d13dfc684da9f281b438dc6a365c2ae529b6d1b Mon Sep 17 00:00:00 2001 From: alanpoon Date: Sun, 29 Sep 2024 19:33:37 +0800 Subject: [PATCH 02/62] emo --- src/home/emoji.rs | 23 +++++++-------- src/home/mod.rs | 2 ++ src/home/room_reaction_list.rs | 52 ++++++++++++++++++++++++++++++++++ src/home/room_screen.rs | 9 +++++- 4 files changed, 73 insertions(+), 13 deletions(-) create mode 100644 src/home/room_reaction_list.rs diff --git a/src/home/emoji.rs b/src/home/emoji.rs index 246ec7e..31ac34e 100644 --- a/src/home/emoji.rs +++ b/src/home/emoji.rs @@ -1,16 +1,16 @@ use makepad_widgets::*; use crate::shared::avatar::{Avatar}; live_design!{ - import makepad_draw::shader::std::*; + import makepad_draw::shader::std::*; + import crate::shared::avatar::Avatar; EmojiSequencer = {{EmojiSequencer}} { - button: { - width: 15.0, - height: 15.0, - text_view = { text = { draw_text: { - text_style: { font_size: 6.0 } - }}} + button: