1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use crate::prelude::styles::DialogStyle;
use buffer_graphics_lib::prelude::*;
use std::fmt::Debug;

pub mod load_file_dialog;
pub mod save_file_dialog;

pub const MIN_FILE_DIALOG_SIZE: (usize, usize) = (196, 168);

pub trait FileDialogResults<SR: Clone + Debug + PartialEq> {
    fn save_file_result(path: String) -> SR;
    fn load_file_result(path: String) -> SR;
}

pub fn dialog_background(width: usize, height: usize, style: &DialogStyle) -> ShapeCollection {
    let mut background = ShapeCollection::new();
    if let Some(color) = style.shade {
        InsertShape::insert_above(
            &mut background,
            Rect::new((0, 0), (width, height)),
            fill(color),
        );
    }
    if let Some(color) = style.background {
        InsertShape::insert_above(&mut background, style.bounds.clone(), fill(color));
    }
    if let Some(color) = style.shadow {
        InsertShape::insert_above(
            &mut background,
            style.bounds.translate_by((1, 1)),
            stroke(color),
        );
    }
    if let Some(color) = style.border {
        InsertShape::insert_above(&mut background, style.bounds.clone(), stroke(color));
    }
    background
}