rust_kanban/ui/rendering/popup/
change_view.rs1use crate::{
2 app::{state::Focus, App},
3 constants::LIST_SELECTED_SYMBOL,
4 ui::{
5 rendering::{
6 common::{render_blank_styled_canvas, render_close_button},
7 popup::ChangeView,
8 utils::{
9 calculate_mouse_list_select_index, centered_rect_with_length,
10 check_if_active_and_get_style, check_if_mouse_is_in_area,
11 },
12 },
13 Renderable, View,
14 },
15};
16use ratatui::{
17 text::Line,
18 widgets::{Block, BorderType, Borders, List, ListItem},
19 Frame,
20};
21
22impl Renderable for ChangeView {
23 fn render(rect: &mut Frame, app: &mut App, is_active: bool) {
24 let all_views = View::all_views_as_string()
25 .iter()
26 .map(|s| ListItem::new(vec![Line::from(s.as_str().to_string())]))
27 .collect::<Vec<ListItem>>();
28
29 let popup_area = centered_rect_with_length(40, 10, rect.area());
30
31 let general_style = check_if_active_and_get_style(
32 is_active,
33 app.current_theme.inactive_text_style,
34 app.current_theme.general_style,
35 );
36 let list_select_style = check_if_active_and_get_style(
37 is_active,
38 app.current_theme.inactive_text_style,
39 app.current_theme.list_select_style,
40 );
41
42 if check_if_mouse_is_in_area(&app.state.current_mouse_coordinates, &popup_area) {
43 app.state.mouse_focus = Some(Focus::ChangeViewPopup);
44 app.state.set_focus(Focus::ChangeViewPopup);
45 calculate_mouse_list_select_index(
46 app.state.current_mouse_coordinates.1,
47 &all_views,
48 popup_area,
49 &mut app.state.app_list_states.default_view,
50 );
51 }
52 let views = List::new(all_views)
53 .block(
54 Block::default()
55 .title("Change View")
56 .style(general_style)
57 .borders(Borders::ALL)
58 .border_type(BorderType::Rounded),
59 )
60 .highlight_style(list_select_style)
61 .highlight_symbol(LIST_SELECTED_SYMBOL);
62
63 render_blank_styled_canvas(rect, &app.current_theme, popup_area, is_active);
64 rect.render_stateful_widget(
65 views,
66 popup_area,
67 &mut app.state.app_list_states.default_view,
68 );
69 if app.config.enable_mouse_support {
70 render_close_button(rect, app, is_active);
71 }
72 }
73}