mecomp_tui/ui/components/content_view/views/
traits.rs1use super::ViewData;
2use mecomp_storage::db::schemas::Thing;
3use ratatui::{
4 layout::{Constraint, Direction, Layout, Rect},
5 widgets::Widget,
6};
7use tokio::sync::mpsc::UnboundedSender;
8
9use crate::{
10 state::action::Action,
11 ui::widgets::tree::{item::CheckTreeItem, state::CheckTreeState},
12};
13
14pub trait ItemViewProps {
16 fn id(&self) -> &Thing;
18
19 fn retrieve(view_data: &ViewData) -> Option<Self>
21 where
22 Self: Sized;
23
24 fn title() -> &'static str
26 where
27 Self: Sized;
28
29 fn none_checked_string() -> &'static str
31 where
32 Self: Sized;
33
34 fn name() -> &'static str
35 where
36 Self: Sized;
37
38 #[must_use]
39 fn split_area(area: Rect) -> [Rect; 2] {
40 let [info_area, content_area] = *Layout::default()
41 .direction(Direction::Vertical)
42 .constraints([Constraint::Length(3), Constraint::Min(4)])
43 .split(area)
44 else {
45 panic!("Failed to split album view area")
46 };
47
48 [info_area, content_area]
49 }
50
51 fn info_widget(&self) -> impl Widget;
52
53 fn tree_items(&self) -> Result<Vec<CheckTreeItem<String>>, std::io::Error>;
59}
60
61pub trait SortableView {
62 fn next_sort(&mut self);
63
64 fn prev_sort(&mut self);
65
66 fn sort_songs(&mut self);
67
68 #[must_use]
69 fn footer() -> &'static str
70 where
71 Self: Sized,
72 {
73 "s/S: change sort"
74 }
75
76 fn handle_extra_key_event(
77 &mut self,
78 key: crossterm::event::KeyEvent,
79 action_tx: UnboundedSender<Action>,
80 tree_state: &mut CheckTreeState<String>,
81 );
82}
83
84pub trait SortMode<T> {
85 #[must_use]
86 fn next(&self) -> Self;
87 #[must_use]
88 fn prev(&self) -> Self;
89
90 fn sort_items(&self, items: &mut [T]);
91}