From b587c09f5701ecb50d4a5a566d1fd192dba37cf7 Mon Sep 17 00:00:00 2001 From: Kevin Boos Date: Wed, 10 Apr 2024 15:16:32 -0700 Subject: [PATCH] Use local timezone. Fix inline code formatting. Improve other message formatting, such as block quotes and code. --- Cargo.lock | 60 ++++++++++++++++----------------- src/home/room_screen.rs | 4 +-- src/home/rooms_list.rs | 2 +- src/shared/html_or_plaintext.rs | 7 ++-- src/shared/styles.rs | 2 +- src/utils.rs | 6 ++-- 6 files changed, 42 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b0c44b07..7f6bc7cf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1651,7 +1651,7 @@ checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" [[package]] name = "jni-sys" version = "0.4.0" -source = "git+https://github.com/makepad/makepad?branch=rik#4fcffef1ebef737baee7dee885e8f349dde34669" +source = "git+https://github.com/makepad/makepad?branch=rik#ab3a96628bff906ee67ace672f5df95ea2d78476" [[package]] name = "js-sys" @@ -1833,7 +1833,7 @@ dependencies = [ [[package]] name = "makepad-derive-live" version = "0.4.0" -source = "git+https://github.com/makepad/makepad?branch=rik#4fcffef1ebef737baee7dee885e8f349dde34669" +source = "git+https://github.com/makepad/makepad?branch=rik#ab3a96628bff906ee67ace672f5df95ea2d78476" dependencies = [ "makepad-live-id", "makepad-micro-proc-macro", @@ -1842,7 +1842,7 @@ dependencies = [ [[package]] name = "makepad-derive-wasm-bridge" version = "0.4.0" -source = "git+https://github.com/makepad/makepad?branch=rik#4fcffef1ebef737baee7dee885e8f349dde34669" +source = "git+https://github.com/makepad/makepad?branch=rik#ab3a96628bff906ee67ace672f5df95ea2d78476" dependencies = [ "makepad-micro-proc-macro", ] @@ -1850,7 +1850,7 @@ dependencies = [ [[package]] name = "makepad-derive-widget" version = "0.4.0" -source = "git+https://github.com/makepad/makepad?branch=rik#4fcffef1ebef737baee7dee885e8f349dde34669" +source = "git+https://github.com/makepad/makepad?branch=rik#ab3a96628bff906ee67ace672f5df95ea2d78476" dependencies = [ "makepad-live-id", "makepad-micro-proc-macro", @@ -1859,7 +1859,7 @@ dependencies = [ [[package]] name = "makepad-draw" version = "0.6.0" -source = "git+https://github.com/makepad/makepad?branch=rik#4fcffef1ebef737baee7dee885e8f349dde34669" +source = "git+https://github.com/makepad/makepad?branch=rik#ab3a96628bff906ee67ace672f5df95ea2d78476" dependencies = [ "ab_glyph_rasterizer", "makepad-html", @@ -1873,17 +1873,17 @@ dependencies = [ [[package]] name = "makepad-futures" version = "0.4.0" -source = "git+https://github.com/makepad/makepad?branch=rik#4fcffef1ebef737baee7dee885e8f349dde34669" +source = "git+https://github.com/makepad/makepad?branch=rik#ab3a96628bff906ee67ace672f5df95ea2d78476" [[package]] name = "makepad-futures-legacy" version = "0.7.0" -source = "git+https://github.com/makepad/makepad?branch=rik#4fcffef1ebef737baee7dee885e8f349dde34669" +source = "git+https://github.com/makepad/makepad?branch=rik#ab3a96628bff906ee67ace672f5df95ea2d78476" [[package]] name = "makepad-html" version = "0.4.0" -source = "git+https://github.com/makepad/makepad?branch=rik#4fcffef1ebef737baee7dee885e8f349dde34669" +source = "git+https://github.com/makepad/makepad?branch=rik#ab3a96628bff906ee67ace672f5df95ea2d78476" dependencies = [ "makepad-live-id", ] @@ -1891,12 +1891,12 @@ dependencies = [ [[package]] name = "makepad-http" version = "0.4.0" -source = "git+https://github.com/makepad/makepad?branch=rik#4fcffef1ebef737baee7dee885e8f349dde34669" +source = "git+https://github.com/makepad/makepad?branch=rik#ab3a96628bff906ee67ace672f5df95ea2d78476" [[package]] name = "makepad-live-compiler" version = "0.5.0" -source = "git+https://github.com/makepad/makepad?branch=rik#4fcffef1ebef737baee7dee885e8f349dde34669" +source = "git+https://github.com/makepad/makepad?branch=rik#ab3a96628bff906ee67ace672f5df95ea2d78476" dependencies = [ "makepad-derive-live", "makepad-live-tokenizer", @@ -1906,7 +1906,7 @@ dependencies = [ [[package]] name = "makepad-live-id" version = "0.4.0" -source = "git+https://github.com/makepad/makepad?branch=rik#4fcffef1ebef737baee7dee885e8f349dde34669" +source = "git+https://github.com/makepad/makepad?branch=rik#ab3a96628bff906ee67ace672f5df95ea2d78476" dependencies = [ "makepad-live-id-macros", ] @@ -1914,7 +1914,7 @@ dependencies = [ [[package]] name = "makepad-live-id-macros" version = "0.4.0" -source = "git+https://github.com/makepad/makepad?branch=rik#4fcffef1ebef737baee7dee885e8f349dde34669" +source = "git+https://github.com/makepad/makepad?branch=rik#ab3a96628bff906ee67ace672f5df95ea2d78476" dependencies = [ "makepad-micro-proc-macro", ] @@ -1922,7 +1922,7 @@ dependencies = [ [[package]] name = "makepad-live-tokenizer" version = "0.4.0" -source = "git+https://github.com/makepad/makepad?branch=rik#4fcffef1ebef737baee7dee885e8f349dde34669" +source = "git+https://github.com/makepad/makepad?branch=rik#ab3a96628bff906ee67ace672f5df95ea2d78476" dependencies = [ "makepad-live-id", "makepad-math", @@ -1932,7 +1932,7 @@ dependencies = [ [[package]] name = "makepad-markdown" version = "0.4.0" -source = "git+https://github.com/makepad/makepad?branch=rik#4fcffef1ebef737baee7dee885e8f349dde34669" +source = "git+https://github.com/makepad/makepad?branch=rik#ab3a96628bff906ee67ace672f5df95ea2d78476" dependencies = [ "makepad-live-id", ] @@ -1940,17 +1940,17 @@ dependencies = [ [[package]] name = "makepad-math" version = "0.4.0" -source = "git+https://github.com/makepad/makepad?branch=rik#4fcffef1ebef737baee7dee885e8f349dde34669" +source = "git+https://github.com/makepad/makepad?branch=rik#ab3a96628bff906ee67ace672f5df95ea2d78476" [[package]] name = "makepad-micro-proc-macro" version = "0.4.0" -source = "git+https://github.com/makepad/makepad?branch=rik#4fcffef1ebef737baee7dee885e8f349dde34669" +source = "git+https://github.com/makepad/makepad?branch=rik#ab3a96628bff906ee67ace672f5df95ea2d78476" [[package]] name = "makepad-micro-serde" version = "0.4.0" -source = "git+https://github.com/makepad/makepad?branch=rik#4fcffef1ebef737baee7dee885e8f349dde34669" +source = "git+https://github.com/makepad/makepad?branch=rik#ab3a96628bff906ee67ace672f5df95ea2d78476" dependencies = [ "makepad-micro-serde-derive", ] @@ -1958,7 +1958,7 @@ dependencies = [ [[package]] name = "makepad-micro-serde-derive" version = "0.4.0" -source = "git+https://github.com/makepad/makepad?branch=rik#4fcffef1ebef737baee7dee885e8f349dde34669" +source = "git+https://github.com/makepad/makepad?branch=rik#ab3a96628bff906ee67ace672f5df95ea2d78476" dependencies = [ "makepad-micro-proc-macro", ] @@ -1966,12 +1966,12 @@ dependencies = [ [[package]] name = "makepad-objc-sys" version = "0.4.0" -source = "git+https://github.com/makepad/makepad?branch=rik#4fcffef1ebef737baee7dee885e8f349dde34669" +source = "git+https://github.com/makepad/makepad?branch=rik#ab3a96628bff906ee67ace672f5df95ea2d78476" [[package]] name = "makepad-platform" version = "0.6.0" -source = "git+https://github.com/makepad/makepad?branch=rik#4fcffef1ebef737baee7dee885e8f349dde34669" +source = "git+https://github.com/makepad/makepad?branch=rik#ab3a96628bff906ee67ace672f5df95ea2d78476" dependencies = [ "jni-sys", "makepad-futures", @@ -1987,7 +1987,7 @@ dependencies = [ [[package]] name = "makepad-shader-compiler" version = "0.5.0" -source = "git+https://github.com/makepad/makepad?branch=rik#4fcffef1ebef737baee7dee885e8f349dde34669" +source = "git+https://github.com/makepad/makepad?branch=rik#ab3a96628bff906ee67ace672f5df95ea2d78476" dependencies = [ "makepad-live-compiler", ] @@ -1995,7 +1995,7 @@ dependencies = [ [[package]] name = "makepad-vector" version = "0.4.0" -source = "git+https://github.com/makepad/makepad?branch=rik#4fcffef1ebef737baee7dee885e8f349dde34669" +source = "git+https://github.com/makepad/makepad?branch=rik#ab3a96628bff906ee67ace672f5df95ea2d78476" dependencies = [ "ttf-parser", ] @@ -2003,7 +2003,7 @@ dependencies = [ [[package]] name = "makepad-wasm-bridge" version = "0.4.0" -source = "git+https://github.com/makepad/makepad?branch=rik#4fcffef1ebef737baee7dee885e8f349dde34669" +source = "git+https://github.com/makepad/makepad?branch=rik#ab3a96628bff906ee67ace672f5df95ea2d78476" dependencies = [ "makepad-derive-wasm-bridge", "makepad-live-id", @@ -2012,7 +2012,7 @@ dependencies = [ [[package]] name = "makepad-widgets" version = "0.6.0" -source = "git+https://github.com/makepad/makepad?branch=rik#4fcffef1ebef737baee7dee885e8f349dde34669" +source = "git+https://github.com/makepad/makepad?branch=rik#ab3a96628bff906ee67ace672f5df95ea2d78476" dependencies = [ "makepad-derive-widget", "makepad-draw", @@ -2025,7 +2025,7 @@ dependencies = [ [[package]] name = "makepad-windows" version = "0.51.1" -source = "git+https://github.com/makepad/makepad?branch=rik#4fcffef1ebef737baee7dee885e8f349dde34669" +source = "git+https://github.com/makepad/makepad?branch=rik#ab3a96628bff906ee67ace672f5df95ea2d78476" dependencies = [ "windows-core 0.51.1 (git+https://github.com/makepad/makepad?branch=rik)", "windows-targets", @@ -2034,7 +2034,7 @@ dependencies = [ [[package]] name = "makepad-zune-core" version = "0.2.14" -source = "git+https://github.com/makepad/makepad?branch=rik#4fcffef1ebef737baee7dee885e8f349dde34669" +source = "git+https://github.com/makepad/makepad?branch=rik#ab3a96628bff906ee67ace672f5df95ea2d78476" dependencies = [ "bitflags 2.4.1", ] @@ -2042,7 +2042,7 @@ dependencies = [ [[package]] name = "makepad-zune-inflate" version = "0.2.54" -source = "git+https://github.com/makepad/makepad?branch=rik#4fcffef1ebef737baee7dee885e8f349dde34669" +source = "git+https://github.com/makepad/makepad?branch=rik#ab3a96628bff906ee67ace672f5df95ea2d78476" dependencies = [ "simd-adler32", ] @@ -2050,7 +2050,7 @@ dependencies = [ [[package]] name = "makepad-zune-jpeg" version = "0.3.17" -source = "git+https://github.com/makepad/makepad?branch=rik#4fcffef1ebef737baee7dee885e8f349dde34669" +source = "git+https://github.com/makepad/makepad?branch=rik#ab3a96628bff906ee67ace672f5df95ea2d78476" dependencies = [ "makepad-zune-core", ] @@ -2058,7 +2058,7 @@ dependencies = [ [[package]] name = "makepad-zune-png" version = "0.2.1" -source = "git+https://github.com/makepad/makepad?branch=rik#4fcffef1ebef737baee7dee885e8f349dde34669" +source = "git+https://github.com/makepad/makepad?branch=rik#ab3a96628bff906ee67ace672f5df95ea2d78476" dependencies = [ "makepad-zune-core", "makepad-zune-inflate", @@ -4756,7 +4756,7 @@ dependencies = [ [[package]] name = "windows-core" version = "0.51.1" -source = "git+https://github.com/makepad/makepad?branch=rik#4fcffef1ebef737baee7dee885e8f349dde34669" +source = "git+https://github.com/makepad/makepad?branch=rik#ab3a96628bff906ee67ace672f5df95ea2d78476" dependencies = [ "windows-targets", ] diff --git a/src/home/room_screen.rs b/src/home/room_screen.rs index 06172e3a..87c91bbb 100644 --- a/src/home/room_screen.rs +++ b/src/home/room_screen.rs @@ -980,7 +980,7 @@ impl Widget for Timeline { let item = list.item(cx, item_id, live_id!(DayDivider)).unwrap(); let text = unix_time_millis_to_datetime(millis) // format the time as a shortened date (Sat, Sept 5, 2021) - .map(|dt| format!("{}", dt.date().format("%a %b %-d, %Y"))) + .map(|dt| format!("{}", dt.date_naive().format("%a %b %-d, %Y"))) .unwrap_or_else(|| format!("{:?}", millis)); item.label(id!(date)).set_text(&text); (item, ItemDrawnStatus::both_drawn()) @@ -1184,7 +1184,7 @@ fn populate_message_view( &format!("{}", dt.time().format("%l:%M %P")) ); item.label(id!(profile.datestamp)).set_text( - &format!("{}", dt.date()) + &format!("{}", dt.date_naive()) ); } else { item.label(id!(profile.timestamp)).set_text( diff --git a/src/home/rooms_list.rs b/src/home/rooms_list.rs index cabe43f6..1d7b3af0 100644 --- a/src/home/rooms_list.rs +++ b/src/home/rooms_list.rs @@ -338,7 +338,7 @@ impl Widget for RoomsList { } if let Some((ts, msg)) = room_info.latest.as_ref() { if let Some(dt) = unix_time_millis_to_datetime(ts) { - let text = format!("{} {}", dt.date(), dt.time().format("%l:%M %P")); + let text = format!("{} {}", dt.date_naive(), dt.time().format("%l:%M %P")); item.label(id!(timestamp)).set_text(&text); } item.label(id!(preview.latest_message)).set_text(msg); diff --git a/src/shared/html_or_plaintext.rs b/src/shared/html_or_plaintext.rs index b2495f53..da60149a 100644 --- a/src/shared/html_or_plaintext.rs +++ b/src/shared/html_or_plaintext.rs @@ -13,6 +13,7 @@ live_design! { // For some reason, they're not the same. That's TBD. HTML_LINE_SPACING = 8.0 HTML_TEXT_HEIGHT_FACTOR = 1.3 + HTML_BLOCK_LINE_SPACING = 5.0 // This is an HTML subwidget used to handle `` and `` tags, @@ -42,7 +43,7 @@ live_design! { draw_bold: { color: (MESSAGE_TEXT_COLOR), text_style: { height_factor: (HTML_TEXT_HEIGHT_FACTOR), line_spacing: (HTML_LINE_SPACING) } } draw_bold_italic: { color: (MESSAGE_TEXT_COLOR), text_style: { height_factor: (HTML_TEXT_HEIGHT_FACTOR), line_spacing: (HTML_LINE_SPACING) } } draw_fixed: { color: (MESSAGE_TEXT_COLOR), text_style: { height_factor: (HTML_TEXT_HEIGHT_FACTOR), line_spacing: (HTML_LINE_SPACING) } } - draw_block:{ + draw_block: { line_color: (MESSAGE_TEXT_COLOR) sep_color: (MESSAGE_TEXT_COLOR) quote_bg_color: (#EDEDED) @@ -50,7 +51,9 @@ live_design! { block_color: (#EDEDED) code_color: (#EDEDED) } - list_item_layout: { line_spacing: 5.0, padding: {top: 1.0, bottom: 1.0}, } + list_item_layout: { line_spacing: (HTML_BLOCK_LINE_SPACING), padding: {left: 5.0, top: 1.0, bottom: 1.0}, } + code_layout: { line_spacing: (HTML_BLOCK_LINE_SPACING), padding: {top: 4.0, bottom: 4.0}, } + quote_layout: { line_spacing: (HTML_BLOCK_LINE_SPACING), padding: {top: 0.0, bottom: 8.0}, } font = { } span = { } diff --git a/src/shared/styles.rs b/src/shared/styles.rs index 4a45d7e7..80e66fe5 100644 --- a/src/shared/styles.rs +++ b/src/shared/styles.rs @@ -27,7 +27,7 @@ live_design! { MESSAGE_FONT_SIZE = 12.0 - MESSAGE_TEXT_COLOR = #x777 + MESSAGE_TEXT_COLOR = #x555 MESSAGE_TEXT_LINE_SPACING = 1.35 MESSAGE_TEXT_HEIGHT_FACTOR = 1.5 // This font should only be used for plaintext labels. Don't use this for Html content, diff --git a/src/utils.rs b/src/utils.rs index e2458846..171c53b1 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,6 +1,6 @@ use std::time::SystemTime; -use chrono::NaiveDateTime; +use chrono::{DateTime, Local, TimeZone}; use makepad_widgets::{error, image_cache::ImageError, Cx, ImageRef}; use matrix_sdk::{ruma::{MilliSecondsSinceUnixEpoch, api::client::media::get_content_thumbnail::v3::Method}, media::{MediaThumbnailSize, MediaFormat}}; @@ -52,9 +52,9 @@ pub fn load_png_or_jpg(img: &ImageRef, cx: &mut Cx, data: &[u8]) -> Result<(), I } -pub fn unix_time_millis_to_datetime(millis: &MilliSecondsSinceUnixEpoch) -> Option { +pub fn unix_time_millis_to_datetime(millis: &MilliSecondsSinceUnixEpoch) -> Option> { let millis: i64 = millis.get().into(); - NaiveDateTime::from_timestamp_millis(millis) + Local.timestamp_millis_opt(millis).single() }