rgui/
window_open_file.rs

1extern crate druid;
2use self::druid::{AppLauncher, WindowDesc, Widget, PlatformError, Data, 
3                  Lens, LocalizedString, UnitPoint, ImageBuf
4                  };
5                  
6use self::druid::widget::{Align, Image, Flex, Button, FillStrat};
7
8/// # WINDOW_TITLE
9///
10/// Title of the application.
11
12const WINDOW_TITLE: LocalizedString<HelloState> = LocalizedString::new("Open the file");
13
14/// # HelloState
15///
16/// State of the application.
17
18#[derive(Clone, Data, Lens)]
19pub struct HelloState {
20    name: String,
21}
22
23/// # build_flex_logo_and_about
24///
25/// Builds the flex with the rair log and the about button.
26
27fn build_flex_logo_and_about() -> Flex <HelloState> {
28    Flex::column()
29        .with_child(build_logo())
30        .with_child(Button::new("about"))
31}
32
33/// # build_logo
34///
35/// Builds the rair logo (currently the odcoder png)
36
37fn build_logo() -> impl Widget<HelloState> {
38    let logo_oddcoder = ImageBuf::from_data(include_bytes!("../data/oddcoder.png")).unwrap();
39    let img = Image::new(logo_oddcoder).fill_mode(FillStrat::Fill);
40    let centered = Align::horizontal(UnitPoint::TOP, img);
41    centered
42}
43
44/// # build_windows_to_open_binary
45///
46/// Builds a label with the text passed as argument.
47
48fn build_windows_to_open_binary() -> WindowDesc<HelloState> {
49    let main_window = WindowDesc::new(build_flex_logo_and_about)
50        .title(WINDOW_TITLE)
51        .window_size((600.0, 700.0));
52    main_window
53}
54
55/// # build_main_gui
56///
57/// Builds everything.
58
59pub fn build_main_gui() -> Result<(), PlatformError> {
60    // create the initial app state
61    let initial_state = HelloState {
62        name: "World".into(),
63    };
64    
65    let start_up_windows = build_windows_to_open_binary();
66    AppLauncher::with_window(start_up_windows).launch(initial_state)?;
67    Ok(())
68}
69
70#[cfg(test)]
71mod tests {
72    use super::*;
73
74    #[test]
75    fn build_startup_ui() {
76        let is_tart_up_windows_builded = build_main_gui();
77        assert!(is_tart_up_windows_builded.is_ok());
78    }
79}