Struct WindowBuilder

Source
pub struct WindowBuilder<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> WindowBuilder<'a>

Source

pub fn flags(self, flags: WindowFlags) -> WindowBuilder<'a>

Examples found in repository?
examples/basic.rs (line 51)
46        fn build_ui(mut data: BasicApp) -> Result<BasicAppUi, nwg::NwgError> {
47            use nwg::Event as E;
48            
49            // Controls
50            nwg::Window::builder()
51                .flags(nwg::WindowFlags::WINDOW | nwg::WindowFlags::VISIBLE)
52                .size((300, 135))
53                .position((300, 300))
54                .title("Basic example")
55                .build(&mut data.window)?;
56
57            nwg::TextInput::builder()
58                .size((280, 35))
59                .position((10, 10))
60                .text("Heisenberg")
61                .parent(&data.window)
62                .focus(true)
63                .build(&mut data.name_edit)?;
64
65            nwg::Button::builder()
66                .size((280, 70))
67                .position((10, 50))
68                .text("Say my name")
69                .parent(&data.window)
70                .build(&mut data.hello_button)?;
71
72            // Wrap-up
73            let ui = BasicAppUi {
74                inner: Rc::new(data),
75                default_handler: Default::default(),
76            };
77
78            // Events
79            let evt_ui = Rc::downgrade(&ui.inner);
80            let handle_events = move |evt, _evt_data, handle| {
81                if let Some(ui) = evt_ui.upgrade() {
82                    match evt {
83                        E::OnButtonClick => 
84                            if &handle == &ui.hello_button {
85                                BasicApp::say_hello(&ui);
86                            },
87                        E::OnWindowClose => 
88                            if &handle == &ui.window {
89                                BasicApp::say_goodbye(&ui);
90                            },
91                        _ => {}
92                    }
93                }
94            };
95
96           *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(&ui.window.handle, handle_events));
97
98            return Ok(ui);
99        }
More examples
Hide additional examples
examples/basic_layout.rs (line 52)
47        fn build_ui(mut data: BasicApp) -> Result<BasicAppUi, nwg::NwgError> {
48            use nwg::Event as E;
49            
50            // Controls
51            nwg::Window::builder()
52                .flags(nwg::WindowFlags::WINDOW | nwg::WindowFlags::VISIBLE)
53                .size((300, 115))
54                .position((300, 300))
55                .title("Basic example")
56                .build(&mut data.window)?;
57
58            nwg::TextInput::builder()
59                .text("Heisenberg")
60                .parent(&data.window)
61                .focus(true)
62                .build(&mut data.name_edit)?;
63
64            nwg::Button::builder()
65                .text("Say my name")
66                .parent(&data.window)
67                .build(&mut data.hello_button)?;
68
69            // Wrap-up
70            let ui = BasicAppUi {
71                inner: Rc::new(data),
72                default_handler: Default::default(),
73            };
74
75            // Events
76            let evt_ui = Rc::downgrade(&ui.inner);
77            let handle_events = move |evt, _evt_data, handle| {
78                if let Some(evt_ui) = evt_ui.upgrade() {
79                    match evt {
80                        E::OnButtonClick => 
81                            if &handle == &evt_ui.hello_button {
82                                BasicApp::say_hello(&evt_ui);
83                            },
84                        E::OnWindowClose => 
85                            if &handle == &evt_ui.window {
86                                BasicApp::say_goodbye(&evt_ui);
87                            },
88                        _ => {}
89                    }
90                }
91            };
92
93           *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(&ui.window.handle, handle_events));
94
95           // Layouts
96           nwg::GridLayout::builder()
97            .parent(&ui.window)
98            .spacing(1)
99            .child(0, 0, &ui.name_edit)
100            .child_item(nwg::GridLayoutItem::new(&ui.hello_button, 0, 1, 1, 2))
101            .build(&ui.layout)?;
102
103            return Ok(ui);
104        }
examples/message_bank.rs (line 93)
88        fn build_ui(mut data: MessageBank) -> Result<MessageBankUi, nwg::NwgError> {
89            use nwg::Event as E;
90            
91            // Controls
92            nwg::Window::builder()
93                .flags(nwg::WindowFlags::MAIN_WINDOW | nwg::WindowFlags::VISIBLE)
94                .size((400, 300))
95                .position((800, 300))
96                .title("My message bank")
97                .build(&mut data.window)?;
98
99            nwg::TextInput::builder()
100                .text("Hello World!")
101                .focus(true)
102                .parent(&data.window)
103                .build(&mut data.message_content)?;
104
105            nwg::Button::builder()
106                .text("Save")
107                .parent(&data.window)
108                .build(&mut data.add_message_btn)?;
109
110            nwg::TextInput::builder()
111                .text("Title")
112                .parent(&data.window)
113                .build(&mut data.message_title)?;
114
115            // Wrap-up
116            let ui = MessageBankUi {
117                inner: Rc::new(data),
118                default_handler: Default::default(),
119            };
120
121            // Events
122            let window_handles = [&ui.window.handle];
123
124            for handle in window_handles.iter() {
125                let evt_ui = Rc::downgrade(&ui.inner);
126                let handle_events = move |evt, _evt_data, handle| {
127                    if let Some(evt_ui) = evt_ui.upgrade() {
128                        match evt {
129                            E::OnButtonClick => {
130                                if &handle == &evt_ui.add_message_btn { MessageBank::add_message(&evt_ui); }
131                            },
132                            E::OnWindowClose => {
133                                if &handle == &evt_ui.window { MessageBank::exit(&evt_ui); }
134                            },
135                            _ => {}
136                        }
137                    }
138                };
139
140                ui.default_handler.borrow_mut().push(
141                    nwg::full_bind_event_handler(handle, handle_events)
142                );
143            }
144
145            // Layout
146            nwg::GridLayout::builder()
147              .parent(&ui.window)
148              .max_row(Some(6))
149              .child(0, 0, &ui.add_message_btn)
150              .child_item(nwg::GridLayoutItem::new(&ui.message_title, 1, 0, 2, 1))
151              .child_item(nwg::GridLayoutItem::new(&ui.message_content, 3, 0, 3, 1))
152              .build(&ui.layout)?;
153            
154            return Ok(ui);
155        }
Source

pub fn ex_flags(self, flags: u32) -> WindowBuilder<'a>

Source

pub fn title(self, text: &'a str) -> WindowBuilder<'a>

Examples found in repository?
examples/partial_simple.rs (line 30)
26    fn build_ui(mut data: MainUi) -> Result<MainUiWrapper, nwg::NwgError> {
27        nwg::Window::builder()
28            .size((500, 200))
29            .position((500, 300))
30            .title("My Form")
31            .build(&mut data.window)?;
32
33        // !!! Partials controls setup !!!
34        SubmitForm::build_partial(&mut data.form, Some(&data.window))?;
35
36        let ui = MainUiWrapper {
37            inner: Rc::new(data),
38            default_handler: Default::default(),
39        };
40
41        // !!! Partials Event Binding !!!
42        let mut window_handles = vec![&ui.window.handle];
43        window_handles.append(&mut ui.form.handles());
44
45        for handle in window_handles.iter() {
46            let evt_ui = Rc::downgrade(&ui.inner);
47            let handle_events = move |evt, evt_data, handle| {
48                use nwg::Event as E;
49
50                if let Some(ui) = evt_ui.upgrade() {
51
52                    // !!! Partials Event Dispatch !!!
53                    ui.form.process_event(evt, &evt_data, handle);
54
55                    match evt {
56                        E::OnButtonClick => 
57                            if &handle == &ui.form.sumbit_button {
58                                println!("SAVING!");
59                            },
60                        E::OnWindowClose => 
61                            if &handle == &ui.window {
62                                nwg::stop_thread_dispatch();
63                            },
64                        _ => {}
65                    }
66                }
67            };
68
69            ui.default_handler.borrow_mut().push(
70                nwg::full_bind_event_handler(handle, handle_events)
71            );
72        }
73
74        return Ok(ui);
75    }
More examples
Hide additional examples
examples/basic_barebone.rs (line 24)
12fn main() {
13    nwg::init().expect("Failed to init Native Windows GUI");
14    nwg::Font::set_global_family("Segoe UI").expect("Failed to set default font");
15
16    let mut window = Default::default();
17    let mut name_edit = Default::default();
18    let mut hello_button = Default::default();
19    let layout = Default::default();
20
21    nwg::Window::builder()
22        .size((300, 115))
23        .position((300, 300))
24        .title("Basic example")
25        .build(&mut window)
26        .unwrap();
27
28    nwg::TextInput::builder()
29        .text("Heisenberg")
30        .focus(true)
31        .parent(&window)
32        .build(&mut name_edit)
33        .unwrap();
34
35    nwg::Button::builder()
36        .text("Say my name")
37        .parent(&window)
38        .build(&mut hello_button)
39        .unwrap();
40
41    nwg::GridLayout::builder()
42        .parent(&window)
43        .spacing(1)
44        .child(0, 0, &name_edit)
45        .child_item(nwg::GridLayoutItem::new(&hello_button, 0, 1, 1, 2))
46        .build(&layout)
47        .unwrap();
48
49    let window = Rc::new(window);
50    let events_window = window.clone();
51
52    let handler = nwg::full_bind_event_handler(&window.handle, move |evt, _evt_data, handle| {
53        use nwg::Event as E;
54
55        match evt {
56            E::OnWindowClose => 
57                if &handle == &events_window as &nwg::Window {
58                    nwg::modal_info_message(&events_window.handle, "Goodbye", &format!("Goodbye {}", name_edit.text()));
59                    nwg::stop_thread_dispatch();
60                },
61            E::OnButtonClick => 
62                if &handle == &hello_button {
63                    nwg::modal_info_message(&events_window.handle, "Hello", &format!("Hello {}", name_edit.text()));
64                },
65            _ => {}
66        }
67    });
68
69    nwg::dispatch_thread_events();
70    nwg::unbind_event_handler(&handler);
71}
examples/basic.rs (line 54)
46        fn build_ui(mut data: BasicApp) -> Result<BasicAppUi, nwg::NwgError> {
47            use nwg::Event as E;
48            
49            // Controls
50            nwg::Window::builder()
51                .flags(nwg::WindowFlags::WINDOW | nwg::WindowFlags::VISIBLE)
52                .size((300, 135))
53                .position((300, 300))
54                .title("Basic example")
55                .build(&mut data.window)?;
56
57            nwg::TextInput::builder()
58                .size((280, 35))
59                .position((10, 10))
60                .text("Heisenberg")
61                .parent(&data.window)
62                .focus(true)
63                .build(&mut data.name_edit)?;
64
65            nwg::Button::builder()
66                .size((280, 70))
67                .position((10, 50))
68                .text("Say my name")
69                .parent(&data.window)
70                .build(&mut data.hello_button)?;
71
72            // Wrap-up
73            let ui = BasicAppUi {
74                inner: Rc::new(data),
75                default_handler: Default::default(),
76            };
77
78            // Events
79            let evt_ui = Rc::downgrade(&ui.inner);
80            let handle_events = move |evt, _evt_data, handle| {
81                if let Some(ui) = evt_ui.upgrade() {
82                    match evt {
83                        E::OnButtonClick => 
84                            if &handle == &ui.hello_button {
85                                BasicApp::say_hello(&ui);
86                            },
87                        E::OnWindowClose => 
88                            if &handle == &ui.window {
89                                BasicApp::say_goodbye(&ui);
90                            },
91                        _ => {}
92                    }
93                }
94            };
95
96           *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(&ui.window.handle, handle_events));
97
98            return Ok(ui);
99        }
examples/basic_layout.rs (line 55)
47        fn build_ui(mut data: BasicApp) -> Result<BasicAppUi, nwg::NwgError> {
48            use nwg::Event as E;
49            
50            // Controls
51            nwg::Window::builder()
52                .flags(nwg::WindowFlags::WINDOW | nwg::WindowFlags::VISIBLE)
53                .size((300, 115))
54                .position((300, 300))
55                .title("Basic example")
56                .build(&mut data.window)?;
57
58            nwg::TextInput::builder()
59                .text("Heisenberg")
60                .parent(&data.window)
61                .focus(true)
62                .build(&mut data.name_edit)?;
63
64            nwg::Button::builder()
65                .text("Say my name")
66                .parent(&data.window)
67                .build(&mut data.hello_button)?;
68
69            // Wrap-up
70            let ui = BasicAppUi {
71                inner: Rc::new(data),
72                default_handler: Default::default(),
73            };
74
75            // Events
76            let evt_ui = Rc::downgrade(&ui.inner);
77            let handle_events = move |evt, _evt_data, handle| {
78                if let Some(evt_ui) = evt_ui.upgrade() {
79                    match evt {
80                        E::OnButtonClick => 
81                            if &handle == &evt_ui.hello_button {
82                                BasicApp::say_hello(&evt_ui);
83                            },
84                        E::OnWindowClose => 
85                            if &handle == &evt_ui.window {
86                                BasicApp::say_goodbye(&evt_ui);
87                            },
88                        _ => {}
89                    }
90                }
91            };
92
93           *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(&ui.window.handle, handle_events));
94
95           // Layouts
96           nwg::GridLayout::builder()
97            .parent(&ui.window)
98            .spacing(1)
99            .child(0, 0, &ui.name_edit)
100            .child_item(nwg::GridLayoutItem::new(&ui.hello_button, 0, 1, 1, 2))
101            .build(&ui.layout)?;
102
103            return Ok(ui);
104        }
examples/message_bank.rs (line 96)
88        fn build_ui(mut data: MessageBank) -> Result<MessageBankUi, nwg::NwgError> {
89            use nwg::Event as E;
90            
91            // Controls
92            nwg::Window::builder()
93                .flags(nwg::WindowFlags::MAIN_WINDOW | nwg::WindowFlags::VISIBLE)
94                .size((400, 300))
95                .position((800, 300))
96                .title("My message bank")
97                .build(&mut data.window)?;
98
99            nwg::TextInput::builder()
100                .text("Hello World!")
101                .focus(true)
102                .parent(&data.window)
103                .build(&mut data.message_content)?;
104
105            nwg::Button::builder()
106                .text("Save")
107                .parent(&data.window)
108                .build(&mut data.add_message_btn)?;
109
110            nwg::TextInput::builder()
111                .text("Title")
112                .parent(&data.window)
113                .build(&mut data.message_title)?;
114
115            // Wrap-up
116            let ui = MessageBankUi {
117                inner: Rc::new(data),
118                default_handler: Default::default(),
119            };
120
121            // Events
122            let window_handles = [&ui.window.handle];
123
124            for handle in window_handles.iter() {
125                let evt_ui = Rc::downgrade(&ui.inner);
126                let handle_events = move |evt, _evt_data, handle| {
127                    if let Some(evt_ui) = evt_ui.upgrade() {
128                        match evt {
129                            E::OnButtonClick => {
130                                if &handle == &evt_ui.add_message_btn { MessageBank::add_message(&evt_ui); }
131                            },
132                            E::OnWindowClose => {
133                                if &handle == &evt_ui.window { MessageBank::exit(&evt_ui); }
134                            },
135                            _ => {}
136                        }
137                    }
138                };
139
140                ui.default_handler.borrow_mut().push(
141                    nwg::full_bind_event_handler(handle, handle_events)
142                );
143            }
144
145            // Layout
146            nwg::GridLayout::builder()
147              .parent(&ui.window)
148              .max_row(Some(6))
149              .child(0, 0, &ui.add_message_btn)
150              .child_item(nwg::GridLayoutItem::new(&ui.message_title, 1, 0, 2, 1))
151              .child_item(nwg::GridLayoutItem::new(&ui.message_content, 3, 0, 3, 1))
152              .build(&ui.layout)?;
153            
154            return Ok(ui);
155        }
examples/flexbox_sub_layout.rs (line 52)
45        fn build_ui(mut data: FlexBoxApp) -> Result<FlexBoxAppUi, nwg::NwgError> {
46            use nwg::Event as E;
47            
48            // Controls
49            nwg::Window::builder()
50                .size((500, 500))
51                .position((300, 300))
52                .title("Flexbox example")
53                .build(&mut data.window)?;
54
55            nwg::Button::builder()
56                .text("Btn 1")
57                .parent(&data.window)
58                .focus(true)
59                .build(&mut data.button1)?;
60
61            nwg::Button::builder()
62                .text("Btn 2")
63                .parent(&data.window)
64                .focus(true)
65                .build(&mut data.button2)?;
66
67            nwg::Button::builder()
68                .text("Btn 3")
69                .parent(&data.window)
70                .focus(true)
71                .build(&mut data.button3)?;
72
73            // Wrap-up
74            let ui = FlexBoxAppUi {
75                inner:  Rc::new(data),
76                default_handler: Default::default(),
77            };
78
79            // Events
80            let evt_ui = Rc::downgrade(&ui.inner);
81            let handle_events = move |evt, _evt_data, handle| {
82                if let Some(evt_ui) = evt_ui.upgrade() {
83                    match evt {
84                        E::OnWindowClose => 
85                            if &handle == &evt_ui.window {
86                                FlexBoxApp::exit(&evt_ui);
87                            },
88                        _ => {}
89                    }
90                }
91            };
92
93           *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(&ui.window.handle, handle_events));
94
95
96            // Layout
97            use nwg::stretch::{geometry::Size, style::{Dimension as D, FlexDirection}};
98
99            nwg::FlexboxLayout::builder()
100                .parent(&ui.window)
101                .flex_direction(FlexDirection::Column)
102                .child(&ui.button2)
103                    .child_size(Size { width: D::Auto, height: D::Points(200.0) })
104                .child(&ui.button3)
105                    .child_flex_grow(2.0)
106                    .child_size(Size { width: D::Auto, height: D::Auto })
107                .build_partial(&ui.layout2)?;
108                
109            nwg::FlexboxLayout::builder()
110                .parent(&ui.window)
111                .flex_direction(FlexDirection::Row)
112                .child(&ui.button1)
113                    .child_flex_grow(2.0)
114                    .child_size(Size { width: D::Auto, height: D::Auto })
115                .child_layout(&ui.layout2)
116                    .child_size(Size { width: D::Points(300.0), height: D::Auto })
117                .build(&ui.layout)?;
118
119            
120            return Ok(ui);
121        }
Source

pub fn size(self, size: (i32, i32)) -> WindowBuilder<'a>

Examples found in repository?
examples/partial_simple.rs (line 28)
26    fn build_ui(mut data: MainUi) -> Result<MainUiWrapper, nwg::NwgError> {
27        nwg::Window::builder()
28            .size((500, 200))
29            .position((500, 300))
30            .title("My Form")
31            .build(&mut data.window)?;
32
33        // !!! Partials controls setup !!!
34        SubmitForm::build_partial(&mut data.form, Some(&data.window))?;
35
36        let ui = MainUiWrapper {
37            inner: Rc::new(data),
38            default_handler: Default::default(),
39        };
40
41        // !!! Partials Event Binding !!!
42        let mut window_handles = vec![&ui.window.handle];
43        window_handles.append(&mut ui.form.handles());
44
45        for handle in window_handles.iter() {
46            let evt_ui = Rc::downgrade(&ui.inner);
47            let handle_events = move |evt, evt_data, handle| {
48                use nwg::Event as E;
49
50                if let Some(ui) = evt_ui.upgrade() {
51
52                    // !!! Partials Event Dispatch !!!
53                    ui.form.process_event(evt, &evt_data, handle);
54
55                    match evt {
56                        E::OnButtonClick => 
57                            if &handle == &ui.form.sumbit_button {
58                                println!("SAVING!");
59                            },
60                        E::OnWindowClose => 
61                            if &handle == &ui.window {
62                                nwg::stop_thread_dispatch();
63                            },
64                        _ => {}
65                    }
66                }
67            };
68
69            ui.default_handler.borrow_mut().push(
70                nwg::full_bind_event_handler(handle, handle_events)
71            );
72        }
73
74        return Ok(ui);
75    }
More examples
Hide additional examples
examples/basic_barebone.rs (line 22)
12fn main() {
13    nwg::init().expect("Failed to init Native Windows GUI");
14    nwg::Font::set_global_family("Segoe UI").expect("Failed to set default font");
15
16    let mut window = Default::default();
17    let mut name_edit = Default::default();
18    let mut hello_button = Default::default();
19    let layout = Default::default();
20
21    nwg::Window::builder()
22        .size((300, 115))
23        .position((300, 300))
24        .title("Basic example")
25        .build(&mut window)
26        .unwrap();
27
28    nwg::TextInput::builder()
29        .text("Heisenberg")
30        .focus(true)
31        .parent(&window)
32        .build(&mut name_edit)
33        .unwrap();
34
35    nwg::Button::builder()
36        .text("Say my name")
37        .parent(&window)
38        .build(&mut hello_button)
39        .unwrap();
40
41    nwg::GridLayout::builder()
42        .parent(&window)
43        .spacing(1)
44        .child(0, 0, &name_edit)
45        .child_item(nwg::GridLayoutItem::new(&hello_button, 0, 1, 1, 2))
46        .build(&layout)
47        .unwrap();
48
49    let window = Rc::new(window);
50    let events_window = window.clone();
51
52    let handler = nwg::full_bind_event_handler(&window.handle, move |evt, _evt_data, handle| {
53        use nwg::Event as E;
54
55        match evt {
56            E::OnWindowClose => 
57                if &handle == &events_window as &nwg::Window {
58                    nwg::modal_info_message(&events_window.handle, "Goodbye", &format!("Goodbye {}", name_edit.text()));
59                    nwg::stop_thread_dispatch();
60                },
61            E::OnButtonClick => 
62                if &handle == &hello_button {
63                    nwg::modal_info_message(&events_window.handle, "Hello", &format!("Hello {}", name_edit.text()));
64                },
65            _ => {}
66        }
67    });
68
69    nwg::dispatch_thread_events();
70    nwg::unbind_event_handler(&handler);
71}
examples/basic.rs (line 52)
46        fn build_ui(mut data: BasicApp) -> Result<BasicAppUi, nwg::NwgError> {
47            use nwg::Event as E;
48            
49            // Controls
50            nwg::Window::builder()
51                .flags(nwg::WindowFlags::WINDOW | nwg::WindowFlags::VISIBLE)
52                .size((300, 135))
53                .position((300, 300))
54                .title("Basic example")
55                .build(&mut data.window)?;
56
57            nwg::TextInput::builder()
58                .size((280, 35))
59                .position((10, 10))
60                .text("Heisenberg")
61                .parent(&data.window)
62                .focus(true)
63                .build(&mut data.name_edit)?;
64
65            nwg::Button::builder()
66                .size((280, 70))
67                .position((10, 50))
68                .text("Say my name")
69                .parent(&data.window)
70                .build(&mut data.hello_button)?;
71
72            // Wrap-up
73            let ui = BasicAppUi {
74                inner: Rc::new(data),
75                default_handler: Default::default(),
76            };
77
78            // Events
79            let evt_ui = Rc::downgrade(&ui.inner);
80            let handle_events = move |evt, _evt_data, handle| {
81                if let Some(ui) = evt_ui.upgrade() {
82                    match evt {
83                        E::OnButtonClick => 
84                            if &handle == &ui.hello_button {
85                                BasicApp::say_hello(&ui);
86                            },
87                        E::OnWindowClose => 
88                            if &handle == &ui.window {
89                                BasicApp::say_goodbye(&ui);
90                            },
91                        _ => {}
92                    }
93                }
94            };
95
96           *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(&ui.window.handle, handle_events));
97
98            return Ok(ui);
99        }
examples/basic_layout.rs (line 53)
47        fn build_ui(mut data: BasicApp) -> Result<BasicAppUi, nwg::NwgError> {
48            use nwg::Event as E;
49            
50            // Controls
51            nwg::Window::builder()
52                .flags(nwg::WindowFlags::WINDOW | nwg::WindowFlags::VISIBLE)
53                .size((300, 115))
54                .position((300, 300))
55                .title("Basic example")
56                .build(&mut data.window)?;
57
58            nwg::TextInput::builder()
59                .text("Heisenberg")
60                .parent(&data.window)
61                .focus(true)
62                .build(&mut data.name_edit)?;
63
64            nwg::Button::builder()
65                .text("Say my name")
66                .parent(&data.window)
67                .build(&mut data.hello_button)?;
68
69            // Wrap-up
70            let ui = BasicAppUi {
71                inner: Rc::new(data),
72                default_handler: Default::default(),
73            };
74
75            // Events
76            let evt_ui = Rc::downgrade(&ui.inner);
77            let handle_events = move |evt, _evt_data, handle| {
78                if let Some(evt_ui) = evt_ui.upgrade() {
79                    match evt {
80                        E::OnButtonClick => 
81                            if &handle == &evt_ui.hello_button {
82                                BasicApp::say_hello(&evt_ui);
83                            },
84                        E::OnWindowClose => 
85                            if &handle == &evt_ui.window {
86                                BasicApp::say_goodbye(&evt_ui);
87                            },
88                        _ => {}
89                    }
90                }
91            };
92
93           *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(&ui.window.handle, handle_events));
94
95           // Layouts
96           nwg::GridLayout::builder()
97            .parent(&ui.window)
98            .spacing(1)
99            .child(0, 0, &ui.name_edit)
100            .child_item(nwg::GridLayoutItem::new(&ui.hello_button, 0, 1, 1, 2))
101            .build(&ui.layout)?;
102
103            return Ok(ui);
104        }
examples/message_bank.rs (line 94)
88        fn build_ui(mut data: MessageBank) -> Result<MessageBankUi, nwg::NwgError> {
89            use nwg::Event as E;
90            
91            // Controls
92            nwg::Window::builder()
93                .flags(nwg::WindowFlags::MAIN_WINDOW | nwg::WindowFlags::VISIBLE)
94                .size((400, 300))
95                .position((800, 300))
96                .title("My message bank")
97                .build(&mut data.window)?;
98
99            nwg::TextInput::builder()
100                .text("Hello World!")
101                .focus(true)
102                .parent(&data.window)
103                .build(&mut data.message_content)?;
104
105            nwg::Button::builder()
106                .text("Save")
107                .parent(&data.window)
108                .build(&mut data.add_message_btn)?;
109
110            nwg::TextInput::builder()
111                .text("Title")
112                .parent(&data.window)
113                .build(&mut data.message_title)?;
114
115            // Wrap-up
116            let ui = MessageBankUi {
117                inner: Rc::new(data),
118                default_handler: Default::default(),
119            };
120
121            // Events
122            let window_handles = [&ui.window.handle];
123
124            for handle in window_handles.iter() {
125                let evt_ui = Rc::downgrade(&ui.inner);
126                let handle_events = move |evt, _evt_data, handle| {
127                    if let Some(evt_ui) = evt_ui.upgrade() {
128                        match evt {
129                            E::OnButtonClick => {
130                                if &handle == &evt_ui.add_message_btn { MessageBank::add_message(&evt_ui); }
131                            },
132                            E::OnWindowClose => {
133                                if &handle == &evt_ui.window { MessageBank::exit(&evt_ui); }
134                            },
135                            _ => {}
136                        }
137                    }
138                };
139
140                ui.default_handler.borrow_mut().push(
141                    nwg::full_bind_event_handler(handle, handle_events)
142                );
143            }
144
145            // Layout
146            nwg::GridLayout::builder()
147              .parent(&ui.window)
148              .max_row(Some(6))
149              .child(0, 0, &ui.add_message_btn)
150              .child_item(nwg::GridLayoutItem::new(&ui.message_title, 1, 0, 2, 1))
151              .child_item(nwg::GridLayoutItem::new(&ui.message_content, 3, 0, 3, 1))
152              .build(&ui.layout)?;
153            
154            return Ok(ui);
155        }
examples/flexbox_sub_layout.rs (line 50)
45        fn build_ui(mut data: FlexBoxApp) -> Result<FlexBoxAppUi, nwg::NwgError> {
46            use nwg::Event as E;
47            
48            // Controls
49            nwg::Window::builder()
50                .size((500, 500))
51                .position((300, 300))
52                .title("Flexbox example")
53                .build(&mut data.window)?;
54
55            nwg::Button::builder()
56                .text("Btn 1")
57                .parent(&data.window)
58                .focus(true)
59                .build(&mut data.button1)?;
60
61            nwg::Button::builder()
62                .text("Btn 2")
63                .parent(&data.window)
64                .focus(true)
65                .build(&mut data.button2)?;
66
67            nwg::Button::builder()
68                .text("Btn 3")
69                .parent(&data.window)
70                .focus(true)
71                .build(&mut data.button3)?;
72
73            // Wrap-up
74            let ui = FlexBoxAppUi {
75                inner:  Rc::new(data),
76                default_handler: Default::default(),
77            };
78
79            // Events
80            let evt_ui = Rc::downgrade(&ui.inner);
81            let handle_events = move |evt, _evt_data, handle| {
82                if let Some(evt_ui) = evt_ui.upgrade() {
83                    match evt {
84                        E::OnWindowClose => 
85                            if &handle == &evt_ui.window {
86                                FlexBoxApp::exit(&evt_ui);
87                            },
88                        _ => {}
89                    }
90                }
91            };
92
93           *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(&ui.window.handle, handle_events));
94
95
96            // Layout
97            use nwg::stretch::{geometry::Size, style::{Dimension as D, FlexDirection}};
98
99            nwg::FlexboxLayout::builder()
100                .parent(&ui.window)
101                .flex_direction(FlexDirection::Column)
102                .child(&ui.button2)
103                    .child_size(Size { width: D::Auto, height: D::Points(200.0) })
104                .child(&ui.button3)
105                    .child_flex_grow(2.0)
106                    .child_size(Size { width: D::Auto, height: D::Auto })
107                .build_partial(&ui.layout2)?;
108                
109            nwg::FlexboxLayout::builder()
110                .parent(&ui.window)
111                .flex_direction(FlexDirection::Row)
112                .child(&ui.button1)
113                    .child_flex_grow(2.0)
114                    .child_size(Size { width: D::Auto, height: D::Auto })
115                .child_layout(&ui.layout2)
116                    .child_size(Size { width: D::Points(300.0), height: D::Auto })
117                .build(&ui.layout)?;
118
119            
120            return Ok(ui);
121        }
Source

pub fn position(self, pos: (i32, i32)) -> WindowBuilder<'a>

Examples found in repository?
examples/partial_simple.rs (line 29)
26    fn build_ui(mut data: MainUi) -> Result<MainUiWrapper, nwg::NwgError> {
27        nwg::Window::builder()
28            .size((500, 200))
29            .position((500, 300))
30            .title("My Form")
31            .build(&mut data.window)?;
32
33        // !!! Partials controls setup !!!
34        SubmitForm::build_partial(&mut data.form, Some(&data.window))?;
35
36        let ui = MainUiWrapper {
37            inner: Rc::new(data),
38            default_handler: Default::default(),
39        };
40
41        // !!! Partials Event Binding !!!
42        let mut window_handles = vec![&ui.window.handle];
43        window_handles.append(&mut ui.form.handles());
44
45        for handle in window_handles.iter() {
46            let evt_ui = Rc::downgrade(&ui.inner);
47            let handle_events = move |evt, evt_data, handle| {
48                use nwg::Event as E;
49
50                if let Some(ui) = evt_ui.upgrade() {
51
52                    // !!! Partials Event Dispatch !!!
53                    ui.form.process_event(evt, &evt_data, handle);
54
55                    match evt {
56                        E::OnButtonClick => 
57                            if &handle == &ui.form.sumbit_button {
58                                println!("SAVING!");
59                            },
60                        E::OnWindowClose => 
61                            if &handle == &ui.window {
62                                nwg::stop_thread_dispatch();
63                            },
64                        _ => {}
65                    }
66                }
67            };
68
69            ui.default_handler.borrow_mut().push(
70                nwg::full_bind_event_handler(handle, handle_events)
71            );
72        }
73
74        return Ok(ui);
75    }
More examples
Hide additional examples
examples/basic_barebone.rs (line 23)
12fn main() {
13    nwg::init().expect("Failed to init Native Windows GUI");
14    nwg::Font::set_global_family("Segoe UI").expect("Failed to set default font");
15
16    let mut window = Default::default();
17    let mut name_edit = Default::default();
18    let mut hello_button = Default::default();
19    let layout = Default::default();
20
21    nwg::Window::builder()
22        .size((300, 115))
23        .position((300, 300))
24        .title("Basic example")
25        .build(&mut window)
26        .unwrap();
27
28    nwg::TextInput::builder()
29        .text("Heisenberg")
30        .focus(true)
31        .parent(&window)
32        .build(&mut name_edit)
33        .unwrap();
34
35    nwg::Button::builder()
36        .text("Say my name")
37        .parent(&window)
38        .build(&mut hello_button)
39        .unwrap();
40
41    nwg::GridLayout::builder()
42        .parent(&window)
43        .spacing(1)
44        .child(0, 0, &name_edit)
45        .child_item(nwg::GridLayoutItem::new(&hello_button, 0, 1, 1, 2))
46        .build(&layout)
47        .unwrap();
48
49    let window = Rc::new(window);
50    let events_window = window.clone();
51
52    let handler = nwg::full_bind_event_handler(&window.handle, move |evt, _evt_data, handle| {
53        use nwg::Event as E;
54
55        match evt {
56            E::OnWindowClose => 
57                if &handle == &events_window as &nwg::Window {
58                    nwg::modal_info_message(&events_window.handle, "Goodbye", &format!("Goodbye {}", name_edit.text()));
59                    nwg::stop_thread_dispatch();
60                },
61            E::OnButtonClick => 
62                if &handle == &hello_button {
63                    nwg::modal_info_message(&events_window.handle, "Hello", &format!("Hello {}", name_edit.text()));
64                },
65            _ => {}
66        }
67    });
68
69    nwg::dispatch_thread_events();
70    nwg::unbind_event_handler(&handler);
71}
examples/basic.rs (line 53)
46        fn build_ui(mut data: BasicApp) -> Result<BasicAppUi, nwg::NwgError> {
47            use nwg::Event as E;
48            
49            // Controls
50            nwg::Window::builder()
51                .flags(nwg::WindowFlags::WINDOW | nwg::WindowFlags::VISIBLE)
52                .size((300, 135))
53                .position((300, 300))
54                .title("Basic example")
55                .build(&mut data.window)?;
56
57            nwg::TextInput::builder()
58                .size((280, 35))
59                .position((10, 10))
60                .text("Heisenberg")
61                .parent(&data.window)
62                .focus(true)
63                .build(&mut data.name_edit)?;
64
65            nwg::Button::builder()
66                .size((280, 70))
67                .position((10, 50))
68                .text("Say my name")
69                .parent(&data.window)
70                .build(&mut data.hello_button)?;
71
72            // Wrap-up
73            let ui = BasicAppUi {
74                inner: Rc::new(data),
75                default_handler: Default::default(),
76            };
77
78            // Events
79            let evt_ui = Rc::downgrade(&ui.inner);
80            let handle_events = move |evt, _evt_data, handle| {
81                if let Some(ui) = evt_ui.upgrade() {
82                    match evt {
83                        E::OnButtonClick => 
84                            if &handle == &ui.hello_button {
85                                BasicApp::say_hello(&ui);
86                            },
87                        E::OnWindowClose => 
88                            if &handle == &ui.window {
89                                BasicApp::say_goodbye(&ui);
90                            },
91                        _ => {}
92                    }
93                }
94            };
95
96           *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(&ui.window.handle, handle_events));
97
98            return Ok(ui);
99        }
examples/basic_layout.rs (line 54)
47        fn build_ui(mut data: BasicApp) -> Result<BasicAppUi, nwg::NwgError> {
48            use nwg::Event as E;
49            
50            // Controls
51            nwg::Window::builder()
52                .flags(nwg::WindowFlags::WINDOW | nwg::WindowFlags::VISIBLE)
53                .size((300, 115))
54                .position((300, 300))
55                .title("Basic example")
56                .build(&mut data.window)?;
57
58            nwg::TextInput::builder()
59                .text("Heisenberg")
60                .parent(&data.window)
61                .focus(true)
62                .build(&mut data.name_edit)?;
63
64            nwg::Button::builder()
65                .text("Say my name")
66                .parent(&data.window)
67                .build(&mut data.hello_button)?;
68
69            // Wrap-up
70            let ui = BasicAppUi {
71                inner: Rc::new(data),
72                default_handler: Default::default(),
73            };
74
75            // Events
76            let evt_ui = Rc::downgrade(&ui.inner);
77            let handle_events = move |evt, _evt_data, handle| {
78                if let Some(evt_ui) = evt_ui.upgrade() {
79                    match evt {
80                        E::OnButtonClick => 
81                            if &handle == &evt_ui.hello_button {
82                                BasicApp::say_hello(&evt_ui);
83                            },
84                        E::OnWindowClose => 
85                            if &handle == &evt_ui.window {
86                                BasicApp::say_goodbye(&evt_ui);
87                            },
88                        _ => {}
89                    }
90                }
91            };
92
93           *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(&ui.window.handle, handle_events));
94
95           // Layouts
96           nwg::GridLayout::builder()
97            .parent(&ui.window)
98            .spacing(1)
99            .child(0, 0, &ui.name_edit)
100            .child_item(nwg::GridLayoutItem::new(&ui.hello_button, 0, 1, 1, 2))
101            .build(&ui.layout)?;
102
103            return Ok(ui);
104        }
examples/message_bank.rs (line 95)
88        fn build_ui(mut data: MessageBank) -> Result<MessageBankUi, nwg::NwgError> {
89            use nwg::Event as E;
90            
91            // Controls
92            nwg::Window::builder()
93                .flags(nwg::WindowFlags::MAIN_WINDOW | nwg::WindowFlags::VISIBLE)
94                .size((400, 300))
95                .position((800, 300))
96                .title("My message bank")
97                .build(&mut data.window)?;
98
99            nwg::TextInput::builder()
100                .text("Hello World!")
101                .focus(true)
102                .parent(&data.window)
103                .build(&mut data.message_content)?;
104
105            nwg::Button::builder()
106                .text("Save")
107                .parent(&data.window)
108                .build(&mut data.add_message_btn)?;
109
110            nwg::TextInput::builder()
111                .text("Title")
112                .parent(&data.window)
113                .build(&mut data.message_title)?;
114
115            // Wrap-up
116            let ui = MessageBankUi {
117                inner: Rc::new(data),
118                default_handler: Default::default(),
119            };
120
121            // Events
122            let window_handles = [&ui.window.handle];
123
124            for handle in window_handles.iter() {
125                let evt_ui = Rc::downgrade(&ui.inner);
126                let handle_events = move |evt, _evt_data, handle| {
127                    if let Some(evt_ui) = evt_ui.upgrade() {
128                        match evt {
129                            E::OnButtonClick => {
130                                if &handle == &evt_ui.add_message_btn { MessageBank::add_message(&evt_ui); }
131                            },
132                            E::OnWindowClose => {
133                                if &handle == &evt_ui.window { MessageBank::exit(&evt_ui); }
134                            },
135                            _ => {}
136                        }
137                    }
138                };
139
140                ui.default_handler.borrow_mut().push(
141                    nwg::full_bind_event_handler(handle, handle_events)
142                );
143            }
144
145            // Layout
146            nwg::GridLayout::builder()
147              .parent(&ui.window)
148              .max_row(Some(6))
149              .child(0, 0, &ui.add_message_btn)
150              .child_item(nwg::GridLayoutItem::new(&ui.message_title, 1, 0, 2, 1))
151              .child_item(nwg::GridLayoutItem::new(&ui.message_content, 3, 0, 3, 1))
152              .build(&ui.layout)?;
153            
154            return Ok(ui);
155        }
examples/flexbox_sub_layout.rs (line 51)
45        fn build_ui(mut data: FlexBoxApp) -> Result<FlexBoxAppUi, nwg::NwgError> {
46            use nwg::Event as E;
47            
48            // Controls
49            nwg::Window::builder()
50                .size((500, 500))
51                .position((300, 300))
52                .title("Flexbox example")
53                .build(&mut data.window)?;
54
55            nwg::Button::builder()
56                .text("Btn 1")
57                .parent(&data.window)
58                .focus(true)
59                .build(&mut data.button1)?;
60
61            nwg::Button::builder()
62                .text("Btn 2")
63                .parent(&data.window)
64                .focus(true)
65                .build(&mut data.button2)?;
66
67            nwg::Button::builder()
68                .text("Btn 3")
69                .parent(&data.window)
70                .focus(true)
71                .build(&mut data.button3)?;
72
73            // Wrap-up
74            let ui = FlexBoxAppUi {
75                inner:  Rc::new(data),
76                default_handler: Default::default(),
77            };
78
79            // Events
80            let evt_ui = Rc::downgrade(&ui.inner);
81            let handle_events = move |evt, _evt_data, handle| {
82                if let Some(evt_ui) = evt_ui.upgrade() {
83                    match evt {
84                        E::OnWindowClose => 
85                            if &handle == &evt_ui.window {
86                                FlexBoxApp::exit(&evt_ui);
87                            },
88                        _ => {}
89                    }
90                }
91            };
92
93           *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(&ui.window.handle, handle_events));
94
95
96            // Layout
97            use nwg::stretch::{geometry::Size, style::{Dimension as D, FlexDirection}};
98
99            nwg::FlexboxLayout::builder()
100                .parent(&ui.window)
101                .flex_direction(FlexDirection::Column)
102                .child(&ui.button2)
103                    .child_size(Size { width: D::Auto, height: D::Points(200.0) })
104                .child(&ui.button3)
105                    .child_flex_grow(2.0)
106                    .child_size(Size { width: D::Auto, height: D::Auto })
107                .build_partial(&ui.layout2)?;
108                
109            nwg::FlexboxLayout::builder()
110                .parent(&ui.window)
111                .flex_direction(FlexDirection::Row)
112                .child(&ui.button1)
113                    .child_flex_grow(2.0)
114                    .child_size(Size { width: D::Auto, height: D::Auto })
115                .child_layout(&ui.layout2)
116                    .child_size(Size { width: D::Points(300.0), height: D::Auto })
117                .build(&ui.layout)?;
118
119            
120            return Ok(ui);
121        }
Source

pub fn icon(self, ico: Option<&'a Icon>) -> WindowBuilder<'a>

Source

pub fn accept_files(self, accept_files: bool) -> WindowBuilder<'a>

Source

pub fn topmost(self, topmost: bool) -> WindowBuilder<'a>

Source

pub fn center(self, center: bool) -> WindowBuilder<'a>

Source

pub fn maximized(self, maximized: bool) -> WindowBuilder<'a>

Source

pub fn minimized(self, minimized: bool) -> WindowBuilder<'a>

Source

pub fn parent<C: Into<ControlHandle>>(self, p: Option<C>) -> WindowBuilder<'a>

Source

pub fn build(self, out: &mut Window) -> Result<(), NwgError>

Examples found in repository?
examples/partial_simple.rs (line 31)
26    fn build_ui(mut data: MainUi) -> Result<MainUiWrapper, nwg::NwgError> {
27        nwg::Window::builder()
28            .size((500, 200))
29            .position((500, 300))
30            .title("My Form")
31            .build(&mut data.window)?;
32
33        // !!! Partials controls setup !!!
34        SubmitForm::build_partial(&mut data.form, Some(&data.window))?;
35
36        let ui = MainUiWrapper {
37            inner: Rc::new(data),
38            default_handler: Default::default(),
39        };
40
41        // !!! Partials Event Binding !!!
42        let mut window_handles = vec![&ui.window.handle];
43        window_handles.append(&mut ui.form.handles());
44
45        for handle in window_handles.iter() {
46            let evt_ui = Rc::downgrade(&ui.inner);
47            let handle_events = move |evt, evt_data, handle| {
48                use nwg::Event as E;
49
50                if let Some(ui) = evt_ui.upgrade() {
51
52                    // !!! Partials Event Dispatch !!!
53                    ui.form.process_event(evt, &evt_data, handle);
54
55                    match evt {
56                        E::OnButtonClick => 
57                            if &handle == &ui.form.sumbit_button {
58                                println!("SAVING!");
59                            },
60                        E::OnWindowClose => 
61                            if &handle == &ui.window {
62                                nwg::stop_thread_dispatch();
63                            },
64                        _ => {}
65                    }
66                }
67            };
68
69            ui.default_handler.borrow_mut().push(
70                nwg::full_bind_event_handler(handle, handle_events)
71            );
72        }
73
74        return Ok(ui);
75    }
More examples
Hide additional examples
examples/basic_barebone.rs (line 25)
12fn main() {
13    nwg::init().expect("Failed to init Native Windows GUI");
14    nwg::Font::set_global_family("Segoe UI").expect("Failed to set default font");
15
16    let mut window = Default::default();
17    let mut name_edit = Default::default();
18    let mut hello_button = Default::default();
19    let layout = Default::default();
20
21    nwg::Window::builder()
22        .size((300, 115))
23        .position((300, 300))
24        .title("Basic example")
25        .build(&mut window)
26        .unwrap();
27
28    nwg::TextInput::builder()
29        .text("Heisenberg")
30        .focus(true)
31        .parent(&window)
32        .build(&mut name_edit)
33        .unwrap();
34
35    nwg::Button::builder()
36        .text("Say my name")
37        .parent(&window)
38        .build(&mut hello_button)
39        .unwrap();
40
41    nwg::GridLayout::builder()
42        .parent(&window)
43        .spacing(1)
44        .child(0, 0, &name_edit)
45        .child_item(nwg::GridLayoutItem::new(&hello_button, 0, 1, 1, 2))
46        .build(&layout)
47        .unwrap();
48
49    let window = Rc::new(window);
50    let events_window = window.clone();
51
52    let handler = nwg::full_bind_event_handler(&window.handle, move |evt, _evt_data, handle| {
53        use nwg::Event as E;
54
55        match evt {
56            E::OnWindowClose => 
57                if &handle == &events_window as &nwg::Window {
58                    nwg::modal_info_message(&events_window.handle, "Goodbye", &format!("Goodbye {}", name_edit.text()));
59                    nwg::stop_thread_dispatch();
60                },
61            E::OnButtonClick => 
62                if &handle == &hello_button {
63                    nwg::modal_info_message(&events_window.handle, "Hello", &format!("Hello {}", name_edit.text()));
64                },
65            _ => {}
66        }
67    });
68
69    nwg::dispatch_thread_events();
70    nwg::unbind_event_handler(&handler);
71}
examples/basic.rs (line 55)
46        fn build_ui(mut data: BasicApp) -> Result<BasicAppUi, nwg::NwgError> {
47            use nwg::Event as E;
48            
49            // Controls
50            nwg::Window::builder()
51                .flags(nwg::WindowFlags::WINDOW | nwg::WindowFlags::VISIBLE)
52                .size((300, 135))
53                .position((300, 300))
54                .title("Basic example")
55                .build(&mut data.window)?;
56
57            nwg::TextInput::builder()
58                .size((280, 35))
59                .position((10, 10))
60                .text("Heisenberg")
61                .parent(&data.window)
62                .focus(true)
63                .build(&mut data.name_edit)?;
64
65            nwg::Button::builder()
66                .size((280, 70))
67                .position((10, 50))
68                .text("Say my name")
69                .parent(&data.window)
70                .build(&mut data.hello_button)?;
71
72            // Wrap-up
73            let ui = BasicAppUi {
74                inner: Rc::new(data),
75                default_handler: Default::default(),
76            };
77
78            // Events
79            let evt_ui = Rc::downgrade(&ui.inner);
80            let handle_events = move |evt, _evt_data, handle| {
81                if let Some(ui) = evt_ui.upgrade() {
82                    match evt {
83                        E::OnButtonClick => 
84                            if &handle == &ui.hello_button {
85                                BasicApp::say_hello(&ui);
86                            },
87                        E::OnWindowClose => 
88                            if &handle == &ui.window {
89                                BasicApp::say_goodbye(&ui);
90                            },
91                        _ => {}
92                    }
93                }
94            };
95
96           *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(&ui.window.handle, handle_events));
97
98            return Ok(ui);
99        }
examples/basic_layout.rs (line 56)
47        fn build_ui(mut data: BasicApp) -> Result<BasicAppUi, nwg::NwgError> {
48            use nwg::Event as E;
49            
50            // Controls
51            nwg::Window::builder()
52                .flags(nwg::WindowFlags::WINDOW | nwg::WindowFlags::VISIBLE)
53                .size((300, 115))
54                .position((300, 300))
55                .title("Basic example")
56                .build(&mut data.window)?;
57
58            nwg::TextInput::builder()
59                .text("Heisenberg")
60                .parent(&data.window)
61                .focus(true)
62                .build(&mut data.name_edit)?;
63
64            nwg::Button::builder()
65                .text("Say my name")
66                .parent(&data.window)
67                .build(&mut data.hello_button)?;
68
69            // Wrap-up
70            let ui = BasicAppUi {
71                inner: Rc::new(data),
72                default_handler: Default::default(),
73            };
74
75            // Events
76            let evt_ui = Rc::downgrade(&ui.inner);
77            let handle_events = move |evt, _evt_data, handle| {
78                if let Some(evt_ui) = evt_ui.upgrade() {
79                    match evt {
80                        E::OnButtonClick => 
81                            if &handle == &evt_ui.hello_button {
82                                BasicApp::say_hello(&evt_ui);
83                            },
84                        E::OnWindowClose => 
85                            if &handle == &evt_ui.window {
86                                BasicApp::say_goodbye(&evt_ui);
87                            },
88                        _ => {}
89                    }
90                }
91            };
92
93           *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(&ui.window.handle, handle_events));
94
95           // Layouts
96           nwg::GridLayout::builder()
97            .parent(&ui.window)
98            .spacing(1)
99            .child(0, 0, &ui.name_edit)
100            .child_item(nwg::GridLayoutItem::new(&ui.hello_button, 0, 1, 1, 2))
101            .build(&ui.layout)?;
102
103            return Ok(ui);
104        }
examples/message_bank.rs (line 97)
88        fn build_ui(mut data: MessageBank) -> Result<MessageBankUi, nwg::NwgError> {
89            use nwg::Event as E;
90            
91            // Controls
92            nwg::Window::builder()
93                .flags(nwg::WindowFlags::MAIN_WINDOW | nwg::WindowFlags::VISIBLE)
94                .size((400, 300))
95                .position((800, 300))
96                .title("My message bank")
97                .build(&mut data.window)?;
98
99            nwg::TextInput::builder()
100                .text("Hello World!")
101                .focus(true)
102                .parent(&data.window)
103                .build(&mut data.message_content)?;
104
105            nwg::Button::builder()
106                .text("Save")
107                .parent(&data.window)
108                .build(&mut data.add_message_btn)?;
109
110            nwg::TextInput::builder()
111                .text("Title")
112                .parent(&data.window)
113                .build(&mut data.message_title)?;
114
115            // Wrap-up
116            let ui = MessageBankUi {
117                inner: Rc::new(data),
118                default_handler: Default::default(),
119            };
120
121            // Events
122            let window_handles = [&ui.window.handle];
123
124            for handle in window_handles.iter() {
125                let evt_ui = Rc::downgrade(&ui.inner);
126                let handle_events = move |evt, _evt_data, handle| {
127                    if let Some(evt_ui) = evt_ui.upgrade() {
128                        match evt {
129                            E::OnButtonClick => {
130                                if &handle == &evt_ui.add_message_btn { MessageBank::add_message(&evt_ui); }
131                            },
132                            E::OnWindowClose => {
133                                if &handle == &evt_ui.window { MessageBank::exit(&evt_ui); }
134                            },
135                            _ => {}
136                        }
137                    }
138                };
139
140                ui.default_handler.borrow_mut().push(
141                    nwg::full_bind_event_handler(handle, handle_events)
142                );
143            }
144
145            // Layout
146            nwg::GridLayout::builder()
147              .parent(&ui.window)
148              .max_row(Some(6))
149              .child(0, 0, &ui.add_message_btn)
150              .child_item(nwg::GridLayoutItem::new(&ui.message_title, 1, 0, 2, 1))
151              .child_item(nwg::GridLayoutItem::new(&ui.message_content, 3, 0, 3, 1))
152              .build(&ui.layout)?;
153            
154            return Ok(ui);
155        }
examples/flexbox_sub_layout.rs (line 53)
45        fn build_ui(mut data: FlexBoxApp) -> Result<FlexBoxAppUi, nwg::NwgError> {
46            use nwg::Event as E;
47            
48            // Controls
49            nwg::Window::builder()
50                .size((500, 500))
51                .position((300, 300))
52                .title("Flexbox example")
53                .build(&mut data.window)?;
54
55            nwg::Button::builder()
56                .text("Btn 1")
57                .parent(&data.window)
58                .focus(true)
59                .build(&mut data.button1)?;
60
61            nwg::Button::builder()
62                .text("Btn 2")
63                .parent(&data.window)
64                .focus(true)
65                .build(&mut data.button2)?;
66
67            nwg::Button::builder()
68                .text("Btn 3")
69                .parent(&data.window)
70                .focus(true)
71                .build(&mut data.button3)?;
72
73            // Wrap-up
74            let ui = FlexBoxAppUi {
75                inner:  Rc::new(data),
76                default_handler: Default::default(),
77            };
78
79            // Events
80            let evt_ui = Rc::downgrade(&ui.inner);
81            let handle_events = move |evt, _evt_data, handle| {
82                if let Some(evt_ui) = evt_ui.upgrade() {
83                    match evt {
84                        E::OnWindowClose => 
85                            if &handle == &evt_ui.window {
86                                FlexBoxApp::exit(&evt_ui);
87                            },
88                        _ => {}
89                    }
90                }
91            };
92
93           *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(&ui.window.handle, handle_events));
94
95
96            // Layout
97            use nwg::stretch::{geometry::Size, style::{Dimension as D, FlexDirection}};
98
99            nwg::FlexboxLayout::builder()
100                .parent(&ui.window)
101                .flex_direction(FlexDirection::Column)
102                .child(&ui.button2)
103                    .child_size(Size { width: D::Auto, height: D::Points(200.0) })
104                .child(&ui.button3)
105                    .child_flex_grow(2.0)
106                    .child_size(Size { width: D::Auto, height: D::Auto })
107                .build_partial(&ui.layout2)?;
108                
109            nwg::FlexboxLayout::builder()
110                .parent(&ui.window)
111                .flex_direction(FlexDirection::Row)
112                .child(&ui.button1)
113                    .child_flex_grow(2.0)
114                    .child_size(Size { width: D::Auto, height: D::Auto })
115                .child_layout(&ui.layout2)
116                    .child_size(Size { width: D::Points(300.0), height: D::Auto })
117                .build(&ui.layout)?;
118
119            
120            return Ok(ui);
121        }

Auto Trait Implementations§

§

impl<'a> Freeze for WindowBuilder<'a>

§

impl<'a> RefUnwindSafe for WindowBuilder<'a>

§

impl<'a> !Send for WindowBuilder<'a>

§

impl<'a> !Sync for WindowBuilder<'a>

§

impl<'a> Unpin for WindowBuilder<'a>

§

impl<'a> UnwindSafe for WindowBuilder<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.