[fractal] Allow adding elements to room history by index
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal] Allow adding elements to room history by index
- Date: Mon, 9 Nov 2020 09:32:24 +0000 (UTC)
commit 92cbe5aa8f1b52fa8b8793a1e6e291e213352ce9
Author: Kai A. Hiller <V02460 gmail com>
Date: Tue Oct 27 10:16:01 2020 +0100
Allow adding elements to room history by index
fractal-gtk/src/widgets/room_history.rs | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
---
diff --git a/fractal-gtk/src/widgets/room_history.rs b/fractal-gtk/src/widgets/room_history.rs
index 74edcc59..2c097f0c 100644
--- a/fractal-gtk/src/widgets/room_history.rs
+++ b/fractal-gtk/src/widgets/room_history.rs
@@ -53,22 +53,32 @@ impl List {
}
}
+ /// Adds the element at the given position to the history.
+ ///
+ /// An index of 0 points to the uppermost element.
+ ///
+ /// ### Panics
+ /// Panics if `index > len`.
+ pub fn add_item(&mut self, index: usize, element: Element) {
+ /* Spinner is at position 0, so increment index by 1 */
+ self.listbox
+ .insert(element.get_listbox_row(), (index + 1) as i32);
+ self.list.insert(self.list.len() - index, element);
+ }
+
pub fn add_top(&mut self, element: Element) {
self.view.set_balance_top();
- /* insert position is 1 because at position 0 is the spinner */
- self.listbox.insert(element.get_listbox_row(), 1);
- self.list.push_back(element);
+ self.add_item(0, element);
self.view.set_kinetic_scrolling(true);
/* TODO: update the previous message:
* we need to update the previous row because it could be that we have to remove the header */
}
pub fn add_bottom(&mut self, element: Element) {
- self.listbox.insert(element.get_listbox_row(), -1);
if let Some(index) = self.new_divider_index {
self.new_divider_index = Some(index + 1);
}
- self.list.push_front(element);
+ self.add_item(self.list.len(), element);
}
fn remove_item(&mut self, index: usize, row: >k::ListBoxRow) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]