From 311862ce4836075dda944240f987dd02c8e05d15 Mon Sep 17 00:00:00 2001 From: Kevin Boos <1139460+kevinaboos@users.noreply.github.com> Date: Mon, 8 Apr 2024 11:03:21 -0700 Subject: [PATCH] Use rich HTML, fix avatar text, centralize style definitions (#62) The HTML widget in makepad is mostly complete, so we can now use it to display rich text formatting in messages. * HTML works for almost everything (underline/strikethrough not working) * avatars work properly now * images work but don't shrink to fit the window properly * caching of widget content works again * centralized styles for text in room timeline * Make avatar impl more canonical, and support `set_text()` * update to latest makepad that includes our changes --- Cargo.lock | 72 ++++++++++++-------- Cargo.toml | 1 - src/app.rs | 1 + src/discover/discover_screen.rs | 1 - src/home/room_screen.rs | 88 ++++++++++--------------- src/home/rooms_list.rs | 7 +- src/profile/profile_screen.rs | 1 - src/shared/avatar.rs | 70 +++++++++++++------- src/shared/clickable_view.rs | 1 - src/shared/header.rs | 1 - src/shared/html_or_plaintext.rs | 113 ++++++++++++++++++++++++++++++++ src/shared/mod.rs | 1 + src/shared/styles.rs | 40 ++++++++++- src/shared/text_or_image.rs | 108 +++++++++++++++++------------- src/utils.rs | 2 +- 15 files changed, 348 insertions(+), 159 deletions(-) create mode 100644 src/shared/html_or_plaintext.rs diff --git a/Cargo.lock b/Cargo.lock index 1b84b55c..efc72441 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1648,6 +1648,11 @@ version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" +[[package]] +name = "jni-sys" +version = "0.4.0" +source = "git+https://github.com/makepad/makepad?branch=rik#9dc3f2dbd0d2b97df08eea07e270a3a055c63fe8" + [[package]] name = "js-sys" version = "0.3.64" @@ -1828,7 +1833,7 @@ dependencies = [ [[package]] name = "makepad-derive-live" version = "0.4.0" -source = "git+https://github.com/makepad/makepad?branch=rik#7f04a544373ea401c43e46c1713120c1cfebf649" +source = "git+https://github.com/makepad/makepad?branch=rik#9dc3f2dbd0d2b97df08eea07e270a3a055c63fe8" dependencies = [ "makepad-live-id", "makepad-micro-proc-macro", @@ -1837,7 +1842,7 @@ dependencies = [ [[package]] name = "makepad-derive-wasm-bridge" version = "0.4.0" -source = "git+https://github.com/makepad/makepad?branch=rik#7f04a544373ea401c43e46c1713120c1cfebf649" +source = "git+https://github.com/makepad/makepad?branch=rik#9dc3f2dbd0d2b97df08eea07e270a3a055c63fe8" dependencies = [ "makepad-micro-proc-macro", ] @@ -1845,7 +1850,7 @@ dependencies = [ [[package]] name = "makepad-derive-widget" version = "0.4.0" -source = "git+https://github.com/makepad/makepad?branch=rik#7f04a544373ea401c43e46c1713120c1cfebf649" +source = "git+https://github.com/makepad/makepad?branch=rik#9dc3f2dbd0d2b97df08eea07e270a3a055c63fe8" dependencies = [ "makepad-live-id", "makepad-micro-proc-macro", @@ -1854,9 +1859,10 @@ dependencies = [ [[package]] name = "makepad-draw" version = "0.6.0" -source = "git+https://github.com/makepad/makepad?branch=rik#7f04a544373ea401c43e46c1713120c1cfebf649" +source = "git+https://github.com/makepad/makepad?branch=rik#9dc3f2dbd0d2b97df08eea07e270a3a055c63fe8" dependencies = [ "ab_glyph_rasterizer", + "makepad-html", "makepad-platform", "makepad-vector", "rustybuzz", @@ -1867,17 +1873,17 @@ dependencies = [ [[package]] name = "makepad-futures" version = "0.4.0" -source = "git+https://github.com/makepad/makepad?branch=rik#7f04a544373ea401c43e46c1713120c1cfebf649" +source = "git+https://github.com/makepad/makepad?branch=rik#9dc3f2dbd0d2b97df08eea07e270a3a055c63fe8" [[package]] name = "makepad-futures-legacy" version = "0.7.0" -source = "git+https://github.com/makepad/makepad?branch=rik#7f04a544373ea401c43e46c1713120c1cfebf649" +source = "git+https://github.com/makepad/makepad?branch=rik#9dc3f2dbd0d2b97df08eea07e270a3a055c63fe8" [[package]] name = "makepad-html" version = "0.4.0" -source = "git+https://github.com/makepad/makepad?branch=rik#7f04a544373ea401c43e46c1713120c1cfebf649" +source = "git+https://github.com/makepad/makepad?branch=rik#9dc3f2dbd0d2b97df08eea07e270a3a055c63fe8" dependencies = [ "makepad-live-id", ] @@ -1885,12 +1891,12 @@ dependencies = [ [[package]] name = "makepad-http" version = "0.4.0" -source = "git+https://github.com/makepad/makepad?branch=rik#7f04a544373ea401c43e46c1713120c1cfebf649" +source = "git+https://github.com/makepad/makepad?branch=rik#9dc3f2dbd0d2b97df08eea07e270a3a055c63fe8" [[package]] name = "makepad-live-compiler" version = "0.5.0" -source = "git+https://github.com/makepad/makepad?branch=rik#7f04a544373ea401c43e46c1713120c1cfebf649" +source = "git+https://github.com/makepad/makepad?branch=rik#9dc3f2dbd0d2b97df08eea07e270a3a055c63fe8" dependencies = [ "makepad-derive-live", "makepad-live-tokenizer", @@ -1900,7 +1906,7 @@ dependencies = [ [[package]] name = "makepad-live-id" version = "0.4.0" -source = "git+https://github.com/makepad/makepad?branch=rik#7f04a544373ea401c43e46c1713120c1cfebf649" +source = "git+https://github.com/makepad/makepad?branch=rik#9dc3f2dbd0d2b97df08eea07e270a3a055c63fe8" dependencies = [ "makepad-live-id-macros", ] @@ -1908,7 +1914,7 @@ dependencies = [ [[package]] name = "makepad-live-id-macros" version = "0.4.0" -source = "git+https://github.com/makepad/makepad?branch=rik#7f04a544373ea401c43e46c1713120c1cfebf649" +source = "git+https://github.com/makepad/makepad?branch=rik#9dc3f2dbd0d2b97df08eea07e270a3a055c63fe8" dependencies = [ "makepad-micro-proc-macro", ] @@ -1916,27 +1922,35 @@ dependencies = [ [[package]] name = "makepad-live-tokenizer" version = "0.4.0" -source = "git+https://github.com/makepad/makepad?branch=rik#7f04a544373ea401c43e46c1713120c1cfebf649" +source = "git+https://github.com/makepad/makepad?branch=rik#9dc3f2dbd0d2b97df08eea07e270a3a055c63fe8" dependencies = [ "makepad-live-id", "makepad-math", "makepad-micro-serde", ] +[[package]] +name = "makepad-markdown" +version = "0.4.0" +source = "git+https://github.com/makepad/makepad?branch=rik#9dc3f2dbd0d2b97df08eea07e270a3a055c63fe8" +dependencies = [ + "makepad-live-id", +] + [[package]] name = "makepad-math" version = "0.4.0" -source = "git+https://github.com/makepad/makepad?branch=rik#7f04a544373ea401c43e46c1713120c1cfebf649" +source = "git+https://github.com/makepad/makepad?branch=rik#9dc3f2dbd0d2b97df08eea07e270a3a055c63fe8" [[package]] name = "makepad-micro-proc-macro" version = "0.4.0" -source = "git+https://github.com/makepad/makepad?branch=rik#7f04a544373ea401c43e46c1713120c1cfebf649" +source = "git+https://github.com/makepad/makepad?branch=rik#9dc3f2dbd0d2b97df08eea07e270a3a055c63fe8" [[package]] name = "makepad-micro-serde" version = "0.4.0" -source = "git+https://github.com/makepad/makepad?branch=rik#7f04a544373ea401c43e46c1713120c1cfebf649" +source = "git+https://github.com/makepad/makepad?branch=rik#9dc3f2dbd0d2b97df08eea07e270a3a055c63fe8" dependencies = [ "makepad-micro-serde-derive", ] @@ -1944,7 +1958,7 @@ dependencies = [ [[package]] name = "makepad-micro-serde-derive" version = "0.4.0" -source = "git+https://github.com/makepad/makepad?branch=rik#7f04a544373ea401c43e46c1713120c1cfebf649" +source = "git+https://github.com/makepad/makepad?branch=rik#9dc3f2dbd0d2b97df08eea07e270a3a055c63fe8" dependencies = [ "makepad-micro-proc-macro", ] @@ -1952,13 +1966,14 @@ dependencies = [ [[package]] name = "makepad-objc-sys" version = "0.4.0" -source = "git+https://github.com/makepad/makepad?branch=rik#7f04a544373ea401c43e46c1713120c1cfebf649" +source = "git+https://github.com/makepad/makepad?branch=rik#9dc3f2dbd0d2b97df08eea07e270a3a055c63fe8" [[package]] name = "makepad-platform" version = "0.6.0" -source = "git+https://github.com/makepad/makepad?branch=rik#7f04a544373ea401c43e46c1713120c1cfebf649" +source = "git+https://github.com/makepad/makepad?branch=rik#9dc3f2dbd0d2b97df08eea07e270a3a055c63fe8" dependencies = [ + "jni-sys", "makepad-futures", "makepad-futures-legacy", "makepad-http", @@ -1972,7 +1987,7 @@ dependencies = [ [[package]] name = "makepad-shader-compiler" version = "0.5.0" -source = "git+https://github.com/makepad/makepad?branch=rik#7f04a544373ea401c43e46c1713120c1cfebf649" +source = "git+https://github.com/makepad/makepad?branch=rik#9dc3f2dbd0d2b97df08eea07e270a3a055c63fe8" dependencies = [ "makepad-live-compiler", ] @@ -1980,7 +1995,7 @@ dependencies = [ [[package]] name = "makepad-vector" version = "0.4.0" -source = "git+https://github.com/makepad/makepad?branch=rik#7f04a544373ea401c43e46c1713120c1cfebf649" +source = "git+https://github.com/makepad/makepad?branch=rik#9dc3f2dbd0d2b97df08eea07e270a3a055c63fe8" dependencies = [ "ttf-parser", ] @@ -1988,7 +2003,7 @@ dependencies = [ [[package]] name = "makepad-wasm-bridge" version = "0.4.0" -source = "git+https://github.com/makepad/makepad?branch=rik#7f04a544373ea401c43e46c1713120c1cfebf649" +source = "git+https://github.com/makepad/makepad?branch=rik#9dc3f2dbd0d2b97df08eea07e270a3a055c63fe8" dependencies = [ "makepad-derive-wasm-bridge", "makepad-live-id", @@ -1997,11 +2012,12 @@ dependencies = [ [[package]] name = "makepad-widgets" version = "0.6.0" -source = "git+https://github.com/makepad/makepad?branch=rik#7f04a544373ea401c43e46c1713120c1cfebf649" +source = "git+https://github.com/makepad/makepad?branch=rik#9dc3f2dbd0d2b97df08eea07e270a3a055c63fe8" dependencies = [ "makepad-derive-widget", "makepad-draw", "makepad-html", + "makepad-markdown", "makepad-zune-jpeg", "makepad-zune-png", ] @@ -2009,7 +2025,7 @@ dependencies = [ [[package]] name = "makepad-windows" version = "0.51.1" -source = "git+https://github.com/makepad/makepad?branch=rik#7f04a544373ea401c43e46c1713120c1cfebf649" +source = "git+https://github.com/makepad/makepad?branch=rik#9dc3f2dbd0d2b97df08eea07e270a3a055c63fe8" dependencies = [ "windows-core 0.51.1 (git+https://github.com/makepad/makepad?branch=rik)", "windows-targets", @@ -2018,7 +2034,7 @@ dependencies = [ [[package]] name = "makepad-zune-core" version = "0.2.14" -source = "git+https://github.com/makepad/makepad?branch=rik#7f04a544373ea401c43e46c1713120c1cfebf649" +source = "git+https://github.com/makepad/makepad?branch=rik#9dc3f2dbd0d2b97df08eea07e270a3a055c63fe8" dependencies = [ "bitflags 2.4.1", ] @@ -2026,7 +2042,7 @@ dependencies = [ [[package]] name = "makepad-zune-inflate" version = "0.2.54" -source = "git+https://github.com/makepad/makepad?branch=rik#7f04a544373ea401c43e46c1713120c1cfebf649" +source = "git+https://github.com/makepad/makepad?branch=rik#9dc3f2dbd0d2b97df08eea07e270a3a055c63fe8" dependencies = [ "simd-adler32", ] @@ -2034,7 +2050,7 @@ dependencies = [ [[package]] name = "makepad-zune-jpeg" version = "0.3.17" -source = "git+https://github.com/makepad/makepad?branch=rik#7f04a544373ea401c43e46c1713120c1cfebf649" +source = "git+https://github.com/makepad/makepad?branch=rik#9dc3f2dbd0d2b97df08eea07e270a3a055c63fe8" dependencies = [ "makepad-zune-core", ] @@ -2042,7 +2058,7 @@ dependencies = [ [[package]] name = "makepad-zune-png" version = "0.2.1" -source = "git+https://github.com/makepad/makepad?branch=rik#7f04a544373ea401c43e46c1713120c1cfebf649" +source = "git+https://github.com/makepad/makepad?branch=rik#9dc3f2dbd0d2b97df08eea07e270a3a055c63fe8" dependencies = [ "makepad-zune-core", "makepad-zune-inflate", @@ -4740,7 +4756,7 @@ dependencies = [ [[package]] name = "windows-core" version = "0.51.1" -source = "git+https://github.com/makepad/makepad?branch=rik#7f04a544373ea401c43e46c1713120c1cfebf649" +source = "git+https://github.com/makepad/makepad?branch=rik#9dc3f2dbd0d2b97df08eea07e270a3a055c63fe8" dependencies = [ "windows-targets", ] diff --git a/Cargo.toml b/Cargo.toml index a50bea1b..3b0c8f89 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,6 @@ metadata.makepad-auto-version = "zqpv-Yj-K7WNVK2I8h5Okhho46Q=" [dependencies] makepad-widgets = { git = "https://github.com/makepad/makepad", branch = "rik" } - anyhow = "1.0" chrono = "0.4" clap = { version = "4.0.16", features = ["derive"] } diff --git a/src/app.rs b/src/app.rs index 63b4426f..436e6b93 100644 --- a/src/app.rs +++ b/src/app.rs @@ -235,6 +235,7 @@ impl LiveRegister for App { crate::shared::clickable_view::live_design(cx); crate::shared::avatar::live_design(cx); crate::shared::text_or_image::live_design(cx); + crate::shared::html_or_plaintext::live_design(cx); // home - chats crate::home::home_screen::live_design(cx); diff --git a/src/discover/discover_screen.rs b/src/discover/discover_screen.rs index 4eec6e9e..8a4dcc79 100644 --- a/src/discover/discover_screen.rs +++ b/src/discover/discover_screen.rs @@ -1,5 +1,4 @@ use crate::shared::clickable_view::*; -use makepad_widgets::widget::WidgetCache; use makepad_widgets::*; live_design! { diff --git a/src/home/room_screen.rs b/src/home/room_screen.rs index c718e69a..06172e3a 100644 --- a/src/home/room_screen.rs +++ b/src/home/room_screen.rs @@ -7,15 +7,11 @@ use imbl::Vector; use makepad_widgets::*; use matrix_sdk::ruma::{ events::{ - AnySyncTimelineEvent, - AnySyncMessageLikeEvent, - FullStateEventContent, room::{ guest_access::GuestAccess, history_visibility::HistoryVisibility, - join_rules::JoinRule, message::{MessageType, RoomMessageEventContent}, MediaSource, - }, - SyncMessageLikeEvent, + join_rules::JoinRule, message::{MessageFormat, MessageType, RoomMessageEventContent}, MediaSource, + }, AnySyncMessageLikeEvent, AnySyncTimelineEvent, FullStateEventContent, SyncMessageLikeEvent }, uint, MilliSecondsSinceUnixEpoch, OwnedRoomId, }; use matrix_sdk_ui::timeline::{ @@ -35,7 +31,7 @@ use rangemap::RangeSet; use unicode_segmentation::UnicodeSegmentation; use crate::{ media_cache::{MediaCache, MediaCacheEntry, AVATAR_CACHE}, - shared::{avatar::{AvatarRef, AvatarWidgetRefExt}, text_or_image::TextOrImageWidgetRefExt}, + shared::{avatar::{AvatarRef, AvatarWidgetRefExt}, html_or_plaintext::HtmlOrPlaintextWidgetRefExt, text_or_image::TextOrImageWidgetRefExt}, sliding_sync::{submit_async_request, take_timeline_update_receiver, MatrixRequest}, utils::{self, unix_time_millis_to_datetime, MediaFormatConst}, }; @@ -50,6 +46,7 @@ live_design! { import crate::shared::search_bar::SearchBar; import crate::shared::avatar::Avatar; import crate::shared::text_or_image::TextOrImage; + import crate::shared::html_or_plaintext::HtmlOrPlaintext; IMG_DEFAULT_AVATAR = dep("crate://self/resources/img/default_avatar.png") ICO_FAV = dep("crate://self/resources/icon_favorite.svg") @@ -60,16 +57,13 @@ live_design! { ICO_USER = dep("crate://self/resources/icon_user.svg") ICO_ADD = dep("crate://self/resources/icon_add.svg") - FONT_SIZE_SUB = 9.5 - FONT_SIZE_P = 12.5 - TEXT_SUB = { - font_size: (FONT_SIZE_SUB), + font_size: (10), font: {path: dep("crate://makepad-widgets/resources/GoNotoKurrent-Regular.ttf")} } TEXT_P = { - font_size: (FONT_SIZE_P), + font_size: (12), height_factor: 1.65, font: {path: dep("crate://makepad-widgets/resources/GoNotoKurrent-Regular.ttf")} } @@ -85,7 +79,6 @@ live_design! { COLOR_DIVIDER_DARK = #x00000044 COLOR_READ_MARKER = #xeb2733 COLOR_PROFILE_CIRCLE = #xfff8ee - COLOR_P = #x999 FillerY = {width: Fill} @@ -148,8 +141,8 @@ live_design! { Timestamp =