rust_kanban/ui/rendering/popup/
card_priority_selector.rs1use crate::{
2 app::{kanban::CardPriority, state::Focus, App},
3 constants::LIST_SELECTED_SYMBOL,
4 ui::{
5 rendering::{
6 common::{render_blank_styled_canvas, render_close_button},
7 popup::CardPrioritySelector,
8 utils::{
9 calculate_mouse_list_select_index, centered_rect_with_percentage,
10 check_if_active_and_get_style, check_if_mouse_is_in_area,
11 },
12 },
13 Renderable,
14 },
15};
16use ratatui::{
17 text::Line,
18 widgets::{Block, BorderType, Borders, List, ListItem},
19 Frame,
20};
21
22impl Renderable for CardPrioritySelector {
23 fn render(rect: &mut Frame, app: &mut App, is_active: bool) {
24 let general_style = check_if_active_and_get_style(
25 is_active,
26 app.current_theme.inactive_text_style,
27 app.current_theme.general_style,
28 );
29 let list_select_style = check_if_active_and_get_style(
30 is_active,
31 app.current_theme.inactive_text_style,
32 app.current_theme.list_select_style,
33 );
34 let mut card_name = String::new();
35 let mut board_name = String::new();
36 let boards = if app.filtered_boards.is_empty() {
37 app.boards.clone()
38 } else {
39 app.filtered_boards.clone()
40 };
41 if let Some(current_board_id) = app.state.current_board_id {
42 if let Some(current_board) = boards.get_board_with_id(current_board_id) {
43 if let Some(current_card_id) = app.state.current_card_id {
44 if let Some(current_card) =
45 current_board.cards.get_card_with_id(current_card_id)
46 {
47 card_name.clone_from(¤t_card.name);
48 board_name.clone_from(¤t_board.name);
49 }
50 }
51 }
52 }
53 let all_priorities = CardPriority::all()
54 .iter()
55 .map(|p| ListItem::new(vec![Line::from(p.to_string())]))
56 .collect::<Vec<ListItem>>();
57 let percent_height =
58 (((all_priorities.len() + 3) as f32 / rect.area().height as f32) * 100.0) as u16;
59 let popup_area = centered_rect_with_percentage(50, percent_height, rect.area());
60 if check_if_mouse_is_in_area(&app.state.current_mouse_coordinates, &popup_area) {
61 app.state.mouse_focus = Some(Focus::ChangeCardPriorityPopup);
62 app.state.set_focus(Focus::ChangeCardPriorityPopup);
63 calculate_mouse_list_select_index(
64 app.state.current_mouse_coordinates.1,
65 &all_priorities,
66 popup_area,
67 &mut app.state.app_list_states.card_priority_selector,
68 );
69 }
70 let priorities = List::new(all_priorities)
71 .block(
72 Block::default()
73 .title(format!(
74 "Changing Priority of \"{}\" in \"{}\"",
75 card_name, board_name
76 ))
77 .style(general_style)
78 .borders(Borders::ALL)
79 .border_type(BorderType::Rounded),
80 )
81 .highlight_style(list_select_style)
82 .highlight_symbol(LIST_SELECTED_SYMBOL);
83
84 render_blank_styled_canvas(rect, &app.current_theme, popup_area, is_active);
85 rect.render_stateful_widget(
86 priorities,
87 popup_area,
88 &mut app.state.app_list_states.card_priority_selector,
89 );
90 if app.config.enable_mouse_support {
91 render_close_button(rect, app, is_active);
92 }
93 }
94}