Scroll to top on sheet listing changed (e.g. sorted)

This commit is contained in:
2024-05-25 22:01:42 +02:00
parent cfb3cc9835
commit 58901dae37
2 changed files with 31 additions and 15 deletions

View File

@@ -24,15 +24,16 @@ pub enum SheetListingInput {
}
#[derive(Debug)]
pub struct SheetModelSelected {
pub sheet: Sheet,
pub enum SheetListingOutput {
SheetModelSelected(Sheet),
ContentsChanged,
}
#[relm4::component(pub)]
impl SimpleComponent for SheetListingModel {
type Init = Vec<Sheet>;
type Input = SheetListingInput;
type Output = SheetModelSelected;
type Output = SheetListingOutput;
view! {
#[root]
@@ -74,18 +75,25 @@ impl SimpleComponent for SheetListingModel {
SheetListingInput::ListBoxRowClicked(index) => {
let sheet_model = self.sheets.get(index as usize).unwrap();
sender
.output(SheetModelSelected {
sheet: sheet_model.sheet.clone(),
})
.output(SheetListingOutput::SheetModelSelected(
sheet_model.sheet.clone(),
))
.unwrap();
}
SheetListingInput::Sort => sort_sheets(&mut self.sheets),
SheetListingInput::Shuffle => shuffle_sheets(&mut self.sheets),
SheetListingInput::Sort => {
sort_sheets(&mut self.sheets);
sender.output(SheetListingOutput::ContentsChanged);
}
SheetListingInput::Shuffle => {
shuffle_sheets(&mut self.sheets);
sender.output(SheetListingOutput::ContentsChanged);
}
SheetListingInput::ReloadSheets(sheets) => {
self.sheets.guard().clear();
for sheet_model_type in sheets {
self.sheets.guard().push_back(sheet_model_type);
}
sender.output(SheetListingOutput::ContentsChanged);
}
}
}