Add ScrollArea to notes container

This commit is contained in:
Sofía Aritz 2023-02-27 17:16:04 +01:00
parent b599f628de
commit e839770c9a

View file

@ -122,19 +122,21 @@ impl eframe::App for App {
}); });
ui.separator(); ui.separator();
for note in &mut self.notes { egui::ScrollArea::vertical().show(ui, |ui| {
let render_result = note.render(ui, password, |id| { for note in &mut self.notes {
let _ = &self.saving.delete_note(&id).unwrap(); let render_result = note.render(ui, password, |id| {
info!("note with id {} was successfully deleted", id); let _ = &self.saving.delete_note(&id).unwrap();
info!("note with id {} was successfully deleted", id);
self.update_notes_next = true; self.update_notes_next = true;
}); });
if let Some(new_note) = render_result { if let Some(new_note) = render_result {
*note = new_note; *note = new_note;
}
ui.add_space(10.0);
} }
ui.add_space(10.0); });
}
}); });
} }
CurrentMode::Compose => { CurrentMode::Compose => {
@ -153,39 +155,41 @@ impl eframe::App for App {
}); });
ui.separator(); ui.separator();
ui.label("title:"); egui::ScrollArea::vertical().show(ui, |ui| {
ui.text_edit_singleline(&mut self.title_buffer); ui.label("title:");
ui.text_edit_singleline(&mut self.title_buffer);
ui.label("text:"); ui.label("text:");
ui.text_edit_multiline(&mut self.text_buffer); ui.text_edit_multiline(&mut self.text_buffer);
ui.add_space(10.0); ui.add_space(10.0);
if ui.button("add note").clicked() { if ui.button("add note").clicked() {
let note = Note::Decrypted { let note = Note::Decrypted {
id: SystemTime::now() id: SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH) .duration_since(SystemTime::UNIX_EPOCH)
.unwrap() .unwrap()
.as_millis() .as_millis()
.to_string(), .to_string(),
title: self.title_buffer.clone(), title: self.title_buffer.clone(),
metadata: NoteMetadata { metadata: NoteMetadata {
date: SystemTime::now(), date: SystemTime::now(),
arbitrary: None, arbitrary: None,
}, },
text: self.text_buffer.clone(), text: self.text_buffer.clone(),
}; };
self.saving.save_note(note.clone(), password.to_string()).unwrap(); self.saving.save_note(note.clone(), password.to_string()).unwrap();
let mut vec_deque = VecDeque::from(self.notes.clone()); let mut vec_deque = VecDeque::from(self.notes.clone());
vec_deque.push_front(note); vec_deque.push_front(note);
self.notes = Vec::from(vec_deque); self.notes = Vec::from(vec_deque);
self.title_buffer = String::new(); self.title_buffer = String::new();
self.text_buffer = String::new(); self.text_buffer = String::new();
self.mode = CurrentMode::View; self.mode = CurrentMode::View;
} }
});
}); });
} }
CurrentMode::PasswordInput => { CurrentMode::PasswordInput => {