rust_kanban/ui/rendering/popup/
confirm_discard_card_changes.rs

1use crate::{
2    app::{state::Focus, App},
3    ui::{
4        rendering::{
5            common::{render_blank_styled_canvas, render_close_button},
6            popup::ConfirmDiscardCardChanges,
7            utils::{
8                centered_rect_with_length, check_if_active_and_get_style,
9                get_mouse_focusable_field_style,
10            },
11        },
12        Renderable,
13    },
14};
15use ratatui::{
16    layout::{Alignment, Constraint, Direction, Layout},
17    widgets::{Block, BorderType, Borders, Paragraph},
18    Frame,
19};
20
21impl Renderable for ConfirmDiscardCardChanges {
22    fn render(rect: &mut Frame, app: &mut App, is_active: bool) {
23        let popup_area = centered_rect_with_length(30, 7, rect.area());
24
25        let chunks = Layout::default()
26            .direction(Direction::Horizontal)
27            .constraints([Constraint::Fill(1), Constraint::Fill(1)].as_ref())
28            .margin(2)
29            .split(popup_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
37        let save_card_button_style =
38            get_mouse_focusable_field_style(app, Focus::SubmitButton, &chunks[0], is_active, false);
39        let dont_save_card_button_style =
40            get_mouse_focusable_field_style(app, Focus::ExtraFocus, &chunks[1], is_active, false);
41        let save_theme_button = Paragraph::new("Yes")
42            .style(save_card_button_style)
43            .block(
44                Block::default()
45                    .borders(Borders::ALL)
46                    .border_style(save_card_button_style)
47                    .border_type(BorderType::Rounded),
48            )
49            .alignment(Alignment::Center);
50        let dont_save_theme_button = Paragraph::new("No")
51            .style(dont_save_card_button_style)
52            .block(
53                Block::default()
54                    .borders(Borders::ALL)
55                    .border_style(dont_save_card_button_style)
56                    .border_type(BorderType::Rounded),
57            )
58            .alignment(Alignment::Center);
59        let border_block = Block::default()
60            .title("Save Changes to Card?")
61            .borders(Borders::ALL)
62            .border_type(BorderType::Rounded)
63            .border_style(general_style);
64
65        render_blank_styled_canvas(rect, &app.current_theme, popup_area, is_active);
66        rect.render_widget(save_theme_button, chunks[0]);
67        rect.render_widget(dont_save_theme_button, chunks[1]);
68        rect.render_widget(border_block, popup_area);
69        if app.config.enable_mouse_support {
70            render_close_button(rect, app, is_active)
71        }
72    }
73}