diff --git a/Cargo.lock b/Cargo.lock index d2b8c652..f523afa7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1659,7 +1659,7 @@ dependencies = [ [[package]] name = "makepad-derive-live" version = "0.4.0" -source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c3075a9cbc4a7362966e396ac2ab274ef9d51936" +source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c01523452879b19ab485f68fd1cbf90e657b1dfc" dependencies = [ "makepad-live-id", "makepad-micro-proc-macro", @@ -1668,7 +1668,7 @@ dependencies = [ [[package]] name = "makepad-derive-wasm-bridge" version = "0.4.0" -source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c3075a9cbc4a7362966e396ac2ab274ef9d51936" +source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c01523452879b19ab485f68fd1cbf90e657b1dfc" dependencies = [ "makepad-micro-proc-macro", ] @@ -1676,7 +1676,7 @@ dependencies = [ [[package]] name = "makepad-derive-widget" version = "0.4.0" -source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c3075a9cbc4a7362966e396ac2ab274ef9d51936" +source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c01523452879b19ab485f68fd1cbf90e657b1dfc" dependencies = [ "makepad-live-id", "makepad-micro-proc-macro", @@ -1685,7 +1685,7 @@ dependencies = [ [[package]] name = "makepad-draw" version = "0.6.0" -source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c3075a9cbc4a7362966e396ac2ab274ef9d51936" +source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c01523452879b19ab485f68fd1cbf90e657b1dfc" dependencies = [ "ab_glyph_rasterizer", "fxhash", @@ -1700,17 +1700,17 @@ dependencies = [ [[package]] name = "makepad-futures" version = "0.4.0" -source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c3075a9cbc4a7362966e396ac2ab274ef9d51936" +source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c01523452879b19ab485f68fd1cbf90e657b1dfc" [[package]] name = "makepad-futures-legacy" version = "0.7.0" -source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c3075a9cbc4a7362966e396ac2ab274ef9d51936" +source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c01523452879b19ab485f68fd1cbf90e657b1dfc" [[package]] name = "makepad-html" version = "0.4.0" -source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c3075a9cbc4a7362966e396ac2ab274ef9d51936" +source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c01523452879b19ab485f68fd1cbf90e657b1dfc" dependencies = [ "makepad-live-id", ] @@ -1718,7 +1718,7 @@ dependencies = [ [[package]] name = "makepad-http" version = "0.4.0" -source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c3075a9cbc4a7362966e396ac2ab274ef9d51936" +source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c01523452879b19ab485f68fd1cbf90e657b1dfc" [[package]] name = "makepad-jni-sys" @@ -1729,7 +1729,7 @@ checksum = "9775cbec5fa0647500c3e5de7c850280a88335d1d2d770e5aa2332b801ba7064" [[package]] name = "makepad-live-compiler" version = "0.5.0" -source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c3075a9cbc4a7362966e396ac2ab274ef9d51936" +source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c01523452879b19ab485f68fd1cbf90e657b1dfc" dependencies = [ "makepad-derive-live", "makepad-live-tokenizer", @@ -1739,7 +1739,7 @@ dependencies = [ [[package]] name = "makepad-live-id" version = "0.4.0" -source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c3075a9cbc4a7362966e396ac2ab274ef9d51936" +source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c01523452879b19ab485f68fd1cbf90e657b1dfc" dependencies = [ "makepad-live-id-macros", ] @@ -1747,7 +1747,7 @@ dependencies = [ [[package]] name = "makepad-live-id-macros" version = "0.4.0" -source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c3075a9cbc4a7362966e396ac2ab274ef9d51936" +source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c01523452879b19ab485f68fd1cbf90e657b1dfc" dependencies = [ "makepad-micro-proc-macro", ] @@ -1755,7 +1755,7 @@ dependencies = [ [[package]] name = "makepad-live-tokenizer" version = "0.4.0" -source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c3075a9cbc4a7362966e396ac2ab274ef9d51936" +source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c01523452879b19ab485f68fd1cbf90e657b1dfc" dependencies = [ "makepad-live-id", "makepad-math", @@ -1765,7 +1765,7 @@ dependencies = [ [[package]] name = "makepad-markdown" version = "0.4.0" -source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c3075a9cbc4a7362966e396ac2ab274ef9d51936" +source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c01523452879b19ab485f68fd1cbf90e657b1dfc" dependencies = [ "makepad-live-id", ] @@ -1773,17 +1773,17 @@ dependencies = [ [[package]] name = "makepad-math" version = "0.4.0" -source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c3075a9cbc4a7362966e396ac2ab274ef9d51936" +source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c01523452879b19ab485f68fd1cbf90e657b1dfc" [[package]] name = "makepad-micro-proc-macro" version = "0.4.0" -source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c3075a9cbc4a7362966e396ac2ab274ef9d51936" +source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c01523452879b19ab485f68fd1cbf90e657b1dfc" [[package]] name = "makepad-micro-serde" version = "0.4.0" -source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c3075a9cbc4a7362966e396ac2ab274ef9d51936" +source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c01523452879b19ab485f68fd1cbf90e657b1dfc" dependencies = [ "makepad-micro-serde-derive", ] @@ -1791,7 +1791,7 @@ dependencies = [ [[package]] name = "makepad-micro-serde-derive" version = "0.4.0" -source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c3075a9cbc4a7362966e396ac2ab274ef9d51936" +source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c01523452879b19ab485f68fd1cbf90e657b1dfc" dependencies = [ "makepad-micro-proc-macro", ] @@ -1799,12 +1799,12 @@ dependencies = [ [[package]] name = "makepad-objc-sys" version = "0.4.0" -source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c3075a9cbc4a7362966e396ac2ab274ef9d51936" +source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c01523452879b19ab485f68fd1cbf90e657b1dfc" [[package]] name = "makepad-platform" version = "0.6.0" -source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c3075a9cbc4a7362966e396ac2ab274ef9d51936" +source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c01523452879b19ab485f68fd1cbf90e657b1dfc" dependencies = [ "makepad-android-state", "makepad-futures", @@ -1822,7 +1822,7 @@ dependencies = [ [[package]] name = "makepad-rustybuzz" version = "0.8.0" -source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c3075a9cbc4a7362966e396ac2ab274ef9d51936" +source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c01523452879b19ab485f68fd1cbf90e657b1dfc" dependencies = [ "bitflags 1.3.2", "bytemuck", @@ -1837,7 +1837,7 @@ dependencies = [ [[package]] name = "makepad-shader-compiler" version = "0.5.0" -source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c3075a9cbc4a7362966e396ac2ab274ef9d51936" +source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c01523452879b19ab485f68fd1cbf90e657b1dfc" dependencies = [ "makepad-live-compiler", ] @@ -1845,7 +1845,7 @@ dependencies = [ [[package]] name = "makepad-vector" version = "0.4.0" -source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c3075a9cbc4a7362966e396ac2ab274ef9d51936" +source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c01523452879b19ab485f68fd1cbf90e657b1dfc" dependencies = [ "ttf-parser", ] @@ -1853,7 +1853,7 @@ dependencies = [ [[package]] name = "makepad-wasm-bridge" version = "0.4.0" -source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c3075a9cbc4a7362966e396ac2ab274ef9d51936" +source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c01523452879b19ab485f68fd1cbf90e657b1dfc" dependencies = [ "makepad-derive-wasm-bridge", "makepad-live-id", @@ -1862,7 +1862,7 @@ dependencies = [ [[package]] name = "makepad-widgets" version = "0.6.0" -source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c3075a9cbc4a7362966e396ac2ab274ef9d51936" +source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c01523452879b19ab485f68fd1cbf90e657b1dfc" dependencies = [ "makepad-derive-widget", "makepad-draw", @@ -1875,7 +1875,7 @@ dependencies = [ [[package]] name = "makepad-windows" version = "0.51.1" -source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c3075a9cbc4a7362966e396ac2ab274ef9d51936" +source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c01523452879b19ab485f68fd1cbf90e657b1dfc" dependencies = [ "windows-core 0.51.1 (git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack)", "windows-targets 0.48.5", @@ -1884,7 +1884,7 @@ dependencies = [ [[package]] name = "makepad-zune-core" version = "0.2.14" -source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c3075a9cbc4a7362966e396ac2ab274ef9d51936" +source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c01523452879b19ab485f68fd1cbf90e657b1dfc" dependencies = [ "bitflags 2.4.1", ] @@ -1892,7 +1892,7 @@ dependencies = [ [[package]] name = "makepad-zune-inflate" version = "0.2.54" -source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c3075a9cbc4a7362966e396ac2ab274ef9d51936" +source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c01523452879b19ab485f68fd1cbf90e657b1dfc" dependencies = [ "simd-adler32", ] @@ -1900,7 +1900,7 @@ dependencies = [ [[package]] name = "makepad-zune-jpeg" version = "0.3.17" -source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c3075a9cbc4a7362966e396ac2ab274ef9d51936" +source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c01523452879b19ab485f68fd1cbf90e657b1dfc" dependencies = [ "makepad-zune-core", ] @@ -1908,7 +1908,7 @@ dependencies = [ [[package]] name = "makepad-zune-png" version = "0.2.1" -source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c3075a9cbc4a7362966e396ac2ab274ef9d51936" +source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c01523452879b19ab485f68fd1cbf90e657b1dfc" dependencies = [ "makepad-zune-core", "makepad-zune-inflate", @@ -3692,7 +3692,7 @@ checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" [[package]] name = "ttf-parser" version = "0.19.0" -source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c3075a9cbc4a7362966e396ac2ab274ef9d51936" +source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c01523452879b19ab485f68fd1cbf90e657b1dfc" [[package]] name = "typenum" @@ -3780,9 +3780,9 @@ checksum = "7d817255e1bed6dfd4ca47258685d14d2bdcfbc64fdc9e3819bd5848057b8ecc" [[package]] name = "unicode-segmentation" -version = "1.10.1" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" +checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" [[package]] name = "universal-hash" @@ -4071,7 +4071,7 @@ dependencies = [ [[package]] name = "windows-core" version = "0.51.1" -source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c3075a9cbc4a7362966e396ac2ab274ef9d51936" +source = "git+https://github.com/kevinaboos/makepad?branch=rik_with_old_font_stack#c01523452879b19ab485f68fd1cbf90e657b1dfc" dependencies = [ "windows-targets 0.48.5", ] diff --git a/src/home/room_screen.rs b/src/home/room_screen.rs index 429b02f8..5507e56b 100644 --- a/src/home/room_screen.rs +++ b/src/home/room_screen.rs @@ -804,11 +804,49 @@ struct TimelineUiState { /// Currently this excludes avatars, as those are shared across multiple rooms. media_cache: MediaCache, + /// The index and scroll position of the first three events that have been drawn + /// in the most recent draw pass of this timeline's PortalList. + /// + /// We save three events because one of 3 adjacent timeline items is (practically) + /// guaranteed to be a standard real event that has a true unique ID. + /// (For example, not day dividers, not read markers, etc.) + /// + /// If any of the `event_ids` are `Some`, this indicates that the timeline was + /// fully cleared and is in the process of being restored via pagination, + /// but it has not yet been paginated enough to the point where one of events + /// in this list are visible. + /// Once the timeline has been sufficiently paginated to display + /// one of the events in this list, all `event_ids` should be set to `None`.` + first_three_events: FirstDrawnEvents<3>, + /// The states relevant to the UI display of this timeline that are saved upon /// a `Hide` action and restored upon a `Show` action. saved_state: SavedState, } +/// The item index, scroll position, and optional unique IDs of the first `N` events +/// that have been drawn in the most recent draw pass of a timeline's PortalList. +#[derive(Debug)] +struct FirstDrawnEvents { + index_and_scroll: [ItemIndexScroll; N], + event_ids: [Option; N], +} +impl Default for FirstDrawnEvents { + fn default() -> Self { + Self { + index_and_scroll: std::array::from_fn(|_| ItemIndexScroll::default()), + event_ids: std::array::from_fn(|_| None), + } + } +} + +/// +#[derive(Clone, Copy, Debug, Default)] +struct ItemIndexScroll { + index: usize, + scroll: f64, +} + /// States that are necessary to save in order to maintain a consistent UI display for a timeline. /// /// These are saved when navigating away from a timeline (upon `Hide`) @@ -854,6 +892,7 @@ impl Timeline { content_drawn_since_last_update: RangeSet::new(), profile_drawn_since_last_update: RangeSet::new(), update_receiver, + first_three_events: Default::default(), media_cache: MediaCache::new(MediaFormatConst::File, Some(update_sender)), saved_state: SavedState::default(), }; @@ -1026,11 +1065,26 @@ impl Widget for Timeline { if items.is_empty() { log!("Timeline::handle_event(): timeline was cleared for room {}", tl.room_id); - // TODO: Save the current first event ID before it gets removed + // If the bottom of the timeline (the last event) is visible, then we should + // set the timeline to live mode. + // If the bottom of the timelien is *not* visible, then we should + // set the timeline to Focused mode. + + // TODO: Save the event IDs of the top 3 items before we apply this update, + // which indicates this timeline is in the process of being restored, // such that we can jump back to that position later after applying this update. // TODO: here we need to re-build the timeline via TimelineBuilder // and set the TimelineFocus to one of the above-saved event IDs. + + // TODO: the docs for `TimelineBuilder::with_focus()` claim that the timeline's focus mode + // can be changed after creation, but I do not see any methods to actually do that. + // + // + // As such, we probably need to create a new async request enum variant + // that tells the background async task to build a new timeline + // (either in live mode or focused mode around one or more events) + // and then replaces the existing timeline in ALL_ROOMS_INFO with the new one. } // Maybe todo?: we can often avoid the following loops that iterate over the `items` list @@ -1126,8 +1180,10 @@ impl Widget for Timeline { list.set_item_range(cx, 0, last_item_id); - while let Some(item_id) = list.next_visible_item(cx) { - // log!("Drawing item {}", item_id); + let mut item_index_and_scroll_iter = tl_state.first_three_events.index_and_scroll.iter_mut(); + + while let Some((item_id, scroll)) = list.next_visible_item_with_scroll(cx) { + // log!("Drawing item {} at scroll: {}", item_id, scroll_offset); let item = if item_id == 0 { list.item(cx, item_id, live_id!(TopSpace)).unwrap() } else { @@ -1139,6 +1195,14 @@ impl Widget for Timeline { continue; }; + if let Some(index_and_scroll) = item_index_and_scroll_iter.next() { + // log!("########### Saving item ID {} and scroll {} for room {}, at_end? {}", + // item_id, scroll, room_id, + // if list.is_at_end() { "Y" } else { "N" }, + // ); + *index_and_scroll = ItemIndexScroll { index: item_id, scroll }; + } + // Determine whether this item's content and profile have been drawn since the last update. // Pass this state to each of the `populate_*` functions so they can attempt to re-use // an item in the timeline's portallist that was previously populated, if one exists. diff --git a/src/sliding_sync.rs b/src/sliding_sync.rs index e58f532e..6a80aa38 100644 --- a/src/sliding_sync.rs +++ b/src/sliding_sync.rs @@ -454,7 +454,6 @@ async fn async_worker(mut receiver: UnboundedReceiver) -> Result< log!("BUG: room info not found for send message request {room_id}"); continue; }; - room_info.timeline.clone() };