Move the view models into voelin-ui-vm; the Slint models take plain rows
vm/{avatar,tree,servers,streams,home,chat,social,studio} and the UI
settings (settings.rs: keys, UiSettings, LastVoice, ClientPlaybackMap,
the audio form) move into voelin-ui-vm with their tests (102 there now;
the 86 view-model tests of voelin-ui all survive, the old list::sync test
became the list::diff tests). They produce the plain bridge structs, with
Rgb for colours and ImageRef for pictures:
- a file picture is ImageSource::File { path, stamp }: the engine writes
a picture that arrives again into the same file, so the length and
write time are part of the reference and a changed file redraws its
row; size() reads the header once per stamp (no toolkit decoder);
- pictures held in memory (chat previews) are ImageSource::Memory;
- the line cache of the chat no longer keeps Slint models alive for
pointer equality: plain lines compare by value, so an unchanged
message makes the same line with or without the cache.
voelin-ui keeps every model as bind::rows::Rows<T>: the plain rows last
shown plus the VecModel, synced with list::diff, converting only the rows
that changed (bind/convert has the From impls). The controllers hand the
view-model rows to Rows::sync and convert forms at the bridge
(`.into()`); crate::vm is now `voelin_ui_vm as vm`, so paths stay.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8e6838a00f
commit
ce7ec3afb7
41 files changed
+1154
-780
No files matched your search
@@ -4,7 +4,7 @@
|
||||
//! `VecModel` (views redraw only the rows that changed: a client that
|
||||
//! starts talking is one `set_row_data`).
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::cell::{Ref, RefCell};
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -48,6 +48,31 @@ impl<T: Row> Rows<T> {
|
||||
ModelRc::from(self.model.clone())
|
||||
}
|
||||
|
||||
/// The rows now.
|
||||
pub fn rows(&self) -> Ref<'_, [T]> {
|
||||
Ref::map(self.rows.borrow(), Vec::as_slice)
|
||||
}
|
||||
|
||||
/// Row `i` now.
|
||||
pub fn get(&self, i: usize) -> Option<T> {
|
||||
self.rows.borrow().get(i).cloned()
|
||||
}
|
||||
|
||||
/// Change row `i` to `row` if it differs.
|
||||
pub fn set(&self, i: usize, row: T) {
|
||||
let mut rows = self.rows.borrow_mut();
|
||||
if rows.get(i).is_some_and(|old| *old != row) {
|
||||
self.model.set_row_data(i, row.show());
|
||||
rows[i] = row;
|
||||
}
|
||||
}
|
||||
|
||||
/// Append a row.
|
||||
pub fn push(&self, row: T) {
|
||||
self.model.push(row.show());
|
||||
self.rows.borrow_mut().push(row);
|
||||
}
|
||||
|
||||
/// Make the list `new`, with the fewest row operations.
|
||||
pub fn sync(&self, new: &[T]) -> Changes {
|
||||
let mut rows = self.rows.borrow_mut();
|
||||
|
||||
Reference in new issue
Block a user