pub struct WindowBuilder<'a> { /* private fields */ }Implementations§
Source§impl<'a> WindowBuilder<'a>
impl<'a> WindowBuilder<'a>
Sourcepub fn flags(self, flags: WindowFlags) -> WindowBuilder<'a>
pub fn flags(self, flags: WindowFlags) -> WindowBuilder<'a>
Examples found in repository?
examples/basic.rs (line 56)
51 fn build_ui(mut data: BasicApp) -> Result<BasicAppUi, nwg::NwgError> {
52 use nwg::Event as E;
53
54 // Controls
55 nwg::Window::builder()
56 .flags(nwg::WindowFlags::WINDOW | nwg::WindowFlags::VISIBLE)
57 .size((300, 135))
58 .position((300, 300))
59 .title("Basic example")
60 .build(&mut data.window)?;
61
62 nwg::TextInput::builder()
63 .size((280, 35))
64 .position((10, 10))
65 .text("Heisenberg")
66 .parent(&data.window)
67 .focus(true)
68 .build(&mut data.name_edit)?;
69
70 nwg::Button::builder()
71 .size((280, 70))
72 .position((10, 50))
73 .text("Say my name")
74 .parent(&data.window)
75 .build(&mut data.hello_button)?;
76
77 // Wrap-up
78 let ui = BasicAppUi {
79 inner: Rc::new(data),
80 default_handler: Default::default(),
81 };
82
83 // Events
84 let evt_ui = Rc::downgrade(&ui.inner);
85 let handle_events = move |evt, _evt_data, handle| {
86 if let Some(ui) = evt_ui.upgrade() {
87 match evt {
88 E::OnButtonClick => {
89 if &handle == &ui.hello_button {
90 BasicApp::say_hello(&ui);
91 }
92 }
93 E::OnWindowClose => {
94 if &handle == &ui.window {
95 BasicApp::say_goodbye(&ui);
96 }
97 }
98 _ => {}
99 }
100 }
101 };
102
103 *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(
104 &ui.window.handle,
105 handle_events,
106 ));
107
108 return Ok(ui);
109 }More examples
examples/basic_layout.rs (line 57)
52 fn build_ui(mut data: BasicApp) -> Result<BasicAppUi, nwg::NwgError> {
53 use nwg::Event as E;
54
55 // Controls
56 nwg::Window::builder()
57 .flags(nwg::WindowFlags::WINDOW | nwg::WindowFlags::VISIBLE)
58 .size((300, 115))
59 .position((300, 300))
60 .title("Basic example")
61 .build(&mut data.window)?;
62
63 nwg::TextInput::builder()
64 .text("Heisenberg")
65 .parent(&data.window)
66 .focus(true)
67 .build(&mut data.name_edit)?;
68
69 nwg::Button::builder()
70 .text("Say my name")
71 .parent(&data.window)
72 .build(&mut data.hello_button)?;
73
74 // Wrap-up
75 let ui = BasicAppUi {
76 inner: Rc::new(data),
77 default_handler: Default::default(),
78 };
79
80 // Events
81 let evt_ui = Rc::downgrade(&ui.inner);
82 let handle_events = move |evt, _evt_data, handle| {
83 if let Some(evt_ui) = evt_ui.upgrade() {
84 match evt {
85 E::OnButtonClick => {
86 if &handle == &evt_ui.hello_button {
87 BasicApp::say_hello(&evt_ui);
88 }
89 }
90 E::OnWindowClose => {
91 if &handle == &evt_ui.window {
92 BasicApp::say_goodbye(&evt_ui);
93 }
94 }
95 _ => {}
96 }
97 }
98 };
99
100 *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(
101 &ui.window.handle,
102 handle_events,
103 ));
104
105 // Layouts
106 nwg::GridLayout::builder()
107 .parent(&ui.window)
108 .spacing(1)
109 .child(0, 0, &ui.name_edit)
110 .child_item(nwg::GridLayoutItem::new(&ui.hello_button, 0, 1, 1, 2))
111 .build(&ui.layout)?;
112
113 return Ok(ui);
114 }examples/message_bank.rs (line 92)
87 fn build_ui(mut data: MessageBank) -> Result<MessageBankUi, nwg::NwgError> {
88 use nwg::Event as E;
89
90 // Controls
91 nwg::Window::builder()
92 .flags(nwg::WindowFlags::MAIN_WINDOW | nwg::WindowFlags::VISIBLE)
93 .size((400, 300))
94 .position((800, 300))
95 .title("My message bank")
96 .build(&mut data.window)?;
97
98 nwg::TextInput::builder()
99 .text("Hello World!")
100 .focus(true)
101 .parent(&data.window)
102 .build(&mut data.message_content)?;
103
104 nwg::Button::builder()
105 .text("Save")
106 .parent(&data.window)
107 .build(&mut data.add_message_btn)?;
108
109 nwg::TextInput::builder()
110 .text("Title")
111 .parent(&data.window)
112 .build(&mut data.message_title)?;
113
114 // Wrap-up
115 let ui = MessageBankUi {
116 inner: Rc::new(data),
117 default_handler: Default::default(),
118 };
119
120 // Events
121 let window_handles = [&ui.window.handle];
122
123 for handle in window_handles.iter() {
124 let evt_ui = Rc::downgrade(&ui.inner);
125 let handle_events = move |evt, _evt_data, handle| {
126 if let Some(evt_ui) = evt_ui.upgrade() {
127 match evt {
128 E::OnButtonClick => {
129 if &handle == &evt_ui.add_message_btn {
130 MessageBank::add_message(&evt_ui);
131 }
132 }
133 E::OnWindowClose => {
134 if &handle == &evt_ui.window {
135 MessageBank::exit(&evt_ui);
136 }
137 }
138 _ => {}
139 }
140 }
141 };
142
143 ui.default_handler
144 .borrow_mut()
145 .push(nwg::full_bind_event_handler(handle, handle_events));
146 }
147
148 // Layout
149 nwg::GridLayout::builder()
150 .parent(&ui.window)
151 .max_row(Some(6))
152 .child(0, 0, &ui.add_message_btn)
153 .child_item(nwg::GridLayoutItem::new(&ui.message_title, 1, 0, 2, 1))
154 .child_item(nwg::GridLayoutItem::new(&ui.message_content, 3, 0, 3, 1))
155 .build(&ui.layout)?;
156
157 return Ok(ui);
158 }pub fn ex_flags(self, flags: u32) -> WindowBuilder<'a>
Sourcepub fn title(self, text: &'a str) -> WindowBuilder<'a>
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 // !!! Partials Event Dispatch !!!
52 ui.form.process_event(evt, &evt_data, handle);
53
54 match evt {
55 E::OnButtonClick => {
56 if &handle == &ui.form.sumbit_button {
57 println!("SAVING!");
58 }
59 }
60 E::OnWindowClose => {
61 if &handle == &ui.window {
62 nwg::stop_thread_dispatch();
63 }
64 }
65 _ => {}
66 }
67 }
68 };
69
70 ui.default_handler
71 .borrow_mut()
72 .push(nwg::full_bind_event_handler(handle, handle_events));
73 }
74
75 return Ok(ui);
76 }More examples
examples/basic.rs (line 59)
51 fn build_ui(mut data: BasicApp) -> Result<BasicAppUi, nwg::NwgError> {
52 use nwg::Event as E;
53
54 // Controls
55 nwg::Window::builder()
56 .flags(nwg::WindowFlags::WINDOW | nwg::WindowFlags::VISIBLE)
57 .size((300, 135))
58 .position((300, 300))
59 .title("Basic example")
60 .build(&mut data.window)?;
61
62 nwg::TextInput::builder()
63 .size((280, 35))
64 .position((10, 10))
65 .text("Heisenberg")
66 .parent(&data.window)
67 .focus(true)
68 .build(&mut data.name_edit)?;
69
70 nwg::Button::builder()
71 .size((280, 70))
72 .position((10, 50))
73 .text("Say my name")
74 .parent(&data.window)
75 .build(&mut data.hello_button)?;
76
77 // Wrap-up
78 let ui = BasicAppUi {
79 inner: Rc::new(data),
80 default_handler: Default::default(),
81 };
82
83 // Events
84 let evt_ui = Rc::downgrade(&ui.inner);
85 let handle_events = move |evt, _evt_data, handle| {
86 if let Some(ui) = evt_ui.upgrade() {
87 match evt {
88 E::OnButtonClick => {
89 if &handle == &ui.hello_button {
90 BasicApp::say_hello(&ui);
91 }
92 }
93 E::OnWindowClose => {
94 if &handle == &ui.window {
95 BasicApp::say_goodbye(&ui);
96 }
97 }
98 _ => {}
99 }
100 }
101 };
102
103 *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(
104 &ui.window.handle,
105 handle_events,
106 ));
107
108 return Ok(ui);
109 }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(
59 &events_window.handle,
60 "Goodbye",
61 &format!("Goodbye {}", name_edit.text()),
62 );
63 nwg::stop_thread_dispatch();
64 }
65 }
66 E::OnButtonClick => {
67 if &handle == &hello_button {
68 nwg::modal_info_message(
69 &events_window.handle,
70 "Hello",
71 &format!("Hello {}", name_edit.text()),
72 );
73 }
74 }
75 _ => {}
76 }
77 });
78
79 nwg::dispatch_thread_events();
80 nwg::unbind_event_handler(&handler);
81}examples/basic_layout.rs (line 60)
52 fn build_ui(mut data: BasicApp) -> Result<BasicAppUi, nwg::NwgError> {
53 use nwg::Event as E;
54
55 // Controls
56 nwg::Window::builder()
57 .flags(nwg::WindowFlags::WINDOW | nwg::WindowFlags::VISIBLE)
58 .size((300, 115))
59 .position((300, 300))
60 .title("Basic example")
61 .build(&mut data.window)?;
62
63 nwg::TextInput::builder()
64 .text("Heisenberg")
65 .parent(&data.window)
66 .focus(true)
67 .build(&mut data.name_edit)?;
68
69 nwg::Button::builder()
70 .text("Say my name")
71 .parent(&data.window)
72 .build(&mut data.hello_button)?;
73
74 // Wrap-up
75 let ui = BasicAppUi {
76 inner: Rc::new(data),
77 default_handler: Default::default(),
78 };
79
80 // Events
81 let evt_ui = Rc::downgrade(&ui.inner);
82 let handle_events = move |evt, _evt_data, handle| {
83 if let Some(evt_ui) = evt_ui.upgrade() {
84 match evt {
85 E::OnButtonClick => {
86 if &handle == &evt_ui.hello_button {
87 BasicApp::say_hello(&evt_ui);
88 }
89 }
90 E::OnWindowClose => {
91 if &handle == &evt_ui.window {
92 BasicApp::say_goodbye(&evt_ui);
93 }
94 }
95 _ => {}
96 }
97 }
98 };
99
100 *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(
101 &ui.window.handle,
102 handle_events,
103 ));
104
105 // Layouts
106 nwg::GridLayout::builder()
107 .parent(&ui.window)
108 .spacing(1)
109 .child(0, 0, &ui.name_edit)
110 .child_item(nwg::GridLayoutItem::new(&ui.hello_button, 0, 1, 1, 2))
111 .build(&ui.layout)?;
112
113 return Ok(ui);
114 }examples/message_bank.rs (line 95)
87 fn build_ui(mut data: MessageBank) -> Result<MessageBankUi, nwg::NwgError> {
88 use nwg::Event as E;
89
90 // Controls
91 nwg::Window::builder()
92 .flags(nwg::WindowFlags::MAIN_WINDOW | nwg::WindowFlags::VISIBLE)
93 .size((400, 300))
94 .position((800, 300))
95 .title("My message bank")
96 .build(&mut data.window)?;
97
98 nwg::TextInput::builder()
99 .text("Hello World!")
100 .focus(true)
101 .parent(&data.window)
102 .build(&mut data.message_content)?;
103
104 nwg::Button::builder()
105 .text("Save")
106 .parent(&data.window)
107 .build(&mut data.add_message_btn)?;
108
109 nwg::TextInput::builder()
110 .text("Title")
111 .parent(&data.window)
112 .build(&mut data.message_title)?;
113
114 // Wrap-up
115 let ui = MessageBankUi {
116 inner: Rc::new(data),
117 default_handler: Default::default(),
118 };
119
120 // Events
121 let window_handles = [&ui.window.handle];
122
123 for handle in window_handles.iter() {
124 let evt_ui = Rc::downgrade(&ui.inner);
125 let handle_events = move |evt, _evt_data, handle| {
126 if let Some(evt_ui) = evt_ui.upgrade() {
127 match evt {
128 E::OnButtonClick => {
129 if &handle == &evt_ui.add_message_btn {
130 MessageBank::add_message(&evt_ui);
131 }
132 }
133 E::OnWindowClose => {
134 if &handle == &evt_ui.window {
135 MessageBank::exit(&evt_ui);
136 }
137 }
138 _ => {}
139 }
140 }
141 };
142
143 ui.default_handler
144 .borrow_mut()
145 .push(nwg::full_bind_event_handler(handle, handle_events));
146 }
147
148 // Layout
149 nwg::GridLayout::builder()
150 .parent(&ui.window)
151 .max_row(Some(6))
152 .child(0, 0, &ui.add_message_btn)
153 .child_item(nwg::GridLayoutItem::new(&ui.message_title, 1, 0, 2, 1))
154 .child_item(nwg::GridLayoutItem::new(&ui.message_content, 3, 0, 3, 1))
155 .build(&ui.layout)?;
156
157 return Ok(ui);
158 }examples/flexbox_sub_layout.rs (line 49)
42 fn build_ui(mut data: FlexBoxApp) -> Result<FlexBoxAppUi, nwg::NwgError> {
43 use nwg::Event as E;
44
45 // Controls
46 nwg::Window::builder()
47 .size((500, 500))
48 .position((300, 300))
49 .title("Flexbox example")
50 .build(&mut data.window)?;
51
52 nwg::Button::builder()
53 .text("Btn 1")
54 .parent(&data.window)
55 .focus(true)
56 .build(&mut data.button1)?;
57
58 nwg::Button::builder()
59 .text("Btn 2")
60 .parent(&data.window)
61 .focus(true)
62 .build(&mut data.button2)?;
63
64 nwg::Button::builder()
65 .text("Btn 3")
66 .parent(&data.window)
67 .focus(true)
68 .build(&mut data.button3)?;
69
70 // Wrap-up
71 let ui = FlexBoxAppUi {
72 inner: Rc::new(data),
73 default_handler: Default::default(),
74 };
75
76 // Events
77 let evt_ui = Rc::downgrade(&ui.inner);
78 let handle_events = move |evt, _evt_data, handle| {
79 if let Some(evt_ui) = evt_ui.upgrade() {
80 match evt {
81 E::OnWindowClose => {
82 if &handle == &evt_ui.window {
83 FlexBoxApp::exit(&evt_ui);
84 }
85 }
86 _ => {}
87 }
88 }
89 };
90
91 *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(
92 &ui.window.handle,
93 handle_events,
94 ));
95
96 // Layout
97 use nwg::stretch::{
98 geometry::Size,
99 style::{Dimension as D, FlexDirection},
100 };
101
102 nwg::FlexboxLayout::builder()
103 .parent(&ui.window)
104 .flex_direction(FlexDirection::Column)
105 .child(&ui.button2)
106 .child_size(Size {
107 width: D::Auto,
108 height: D::Points(200.0),
109 })
110 .child(&ui.button3)
111 .child_flex_grow(2.0)
112 .child_size(Size {
113 width: D::Auto,
114 height: D::Auto,
115 })
116 .build_partial(&ui.layout2)?;
117
118 nwg::FlexboxLayout::builder()
119 .parent(&ui.window)
120 .flex_direction(FlexDirection::Row)
121 .child(&ui.button1)
122 .child_flex_grow(2.0)
123 .child_size(Size {
124 width: D::Auto,
125 height: D::Auto,
126 })
127 .child_layout(&ui.layout2)
128 .child_size(Size {
129 width: D::Points(300.0),
130 height: D::Auto,
131 })
132 .build(&ui.layout)?;
133
134 return Ok(ui);
135 }Additional examples can be found in:
Sourcepub fn size(self, size: (i32, i32)) -> WindowBuilder<'a>
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 // !!! Partials Event Dispatch !!!
52 ui.form.process_event(evt, &evt_data, handle);
53
54 match evt {
55 E::OnButtonClick => {
56 if &handle == &ui.form.sumbit_button {
57 println!("SAVING!");
58 }
59 }
60 E::OnWindowClose => {
61 if &handle == &ui.window {
62 nwg::stop_thread_dispatch();
63 }
64 }
65 _ => {}
66 }
67 }
68 };
69
70 ui.default_handler
71 .borrow_mut()
72 .push(nwg::full_bind_event_handler(handle, handle_events));
73 }
74
75 return Ok(ui);
76 }More examples
examples/basic.rs (line 57)
51 fn build_ui(mut data: BasicApp) -> Result<BasicAppUi, nwg::NwgError> {
52 use nwg::Event as E;
53
54 // Controls
55 nwg::Window::builder()
56 .flags(nwg::WindowFlags::WINDOW | nwg::WindowFlags::VISIBLE)
57 .size((300, 135))
58 .position((300, 300))
59 .title("Basic example")
60 .build(&mut data.window)?;
61
62 nwg::TextInput::builder()
63 .size((280, 35))
64 .position((10, 10))
65 .text("Heisenberg")
66 .parent(&data.window)
67 .focus(true)
68 .build(&mut data.name_edit)?;
69
70 nwg::Button::builder()
71 .size((280, 70))
72 .position((10, 50))
73 .text("Say my name")
74 .parent(&data.window)
75 .build(&mut data.hello_button)?;
76
77 // Wrap-up
78 let ui = BasicAppUi {
79 inner: Rc::new(data),
80 default_handler: Default::default(),
81 };
82
83 // Events
84 let evt_ui = Rc::downgrade(&ui.inner);
85 let handle_events = move |evt, _evt_data, handle| {
86 if let Some(ui) = evt_ui.upgrade() {
87 match evt {
88 E::OnButtonClick => {
89 if &handle == &ui.hello_button {
90 BasicApp::say_hello(&ui);
91 }
92 }
93 E::OnWindowClose => {
94 if &handle == &ui.window {
95 BasicApp::say_goodbye(&ui);
96 }
97 }
98 _ => {}
99 }
100 }
101 };
102
103 *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(
104 &ui.window.handle,
105 handle_events,
106 ));
107
108 return Ok(ui);
109 }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(
59 &events_window.handle,
60 "Goodbye",
61 &format!("Goodbye {}", name_edit.text()),
62 );
63 nwg::stop_thread_dispatch();
64 }
65 }
66 E::OnButtonClick => {
67 if &handle == &hello_button {
68 nwg::modal_info_message(
69 &events_window.handle,
70 "Hello",
71 &format!("Hello {}", name_edit.text()),
72 );
73 }
74 }
75 _ => {}
76 }
77 });
78
79 nwg::dispatch_thread_events();
80 nwg::unbind_event_handler(&handler);
81}examples/basic_layout.rs (line 58)
52 fn build_ui(mut data: BasicApp) -> Result<BasicAppUi, nwg::NwgError> {
53 use nwg::Event as E;
54
55 // Controls
56 nwg::Window::builder()
57 .flags(nwg::WindowFlags::WINDOW | nwg::WindowFlags::VISIBLE)
58 .size((300, 115))
59 .position((300, 300))
60 .title("Basic example")
61 .build(&mut data.window)?;
62
63 nwg::TextInput::builder()
64 .text("Heisenberg")
65 .parent(&data.window)
66 .focus(true)
67 .build(&mut data.name_edit)?;
68
69 nwg::Button::builder()
70 .text("Say my name")
71 .parent(&data.window)
72 .build(&mut data.hello_button)?;
73
74 // Wrap-up
75 let ui = BasicAppUi {
76 inner: Rc::new(data),
77 default_handler: Default::default(),
78 };
79
80 // Events
81 let evt_ui = Rc::downgrade(&ui.inner);
82 let handle_events = move |evt, _evt_data, handle| {
83 if let Some(evt_ui) = evt_ui.upgrade() {
84 match evt {
85 E::OnButtonClick => {
86 if &handle == &evt_ui.hello_button {
87 BasicApp::say_hello(&evt_ui);
88 }
89 }
90 E::OnWindowClose => {
91 if &handle == &evt_ui.window {
92 BasicApp::say_goodbye(&evt_ui);
93 }
94 }
95 _ => {}
96 }
97 }
98 };
99
100 *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(
101 &ui.window.handle,
102 handle_events,
103 ));
104
105 // Layouts
106 nwg::GridLayout::builder()
107 .parent(&ui.window)
108 .spacing(1)
109 .child(0, 0, &ui.name_edit)
110 .child_item(nwg::GridLayoutItem::new(&ui.hello_button, 0, 1, 1, 2))
111 .build(&ui.layout)?;
112
113 return Ok(ui);
114 }examples/message_bank.rs (line 93)
87 fn build_ui(mut data: MessageBank) -> Result<MessageBankUi, nwg::NwgError> {
88 use nwg::Event as E;
89
90 // Controls
91 nwg::Window::builder()
92 .flags(nwg::WindowFlags::MAIN_WINDOW | nwg::WindowFlags::VISIBLE)
93 .size((400, 300))
94 .position((800, 300))
95 .title("My message bank")
96 .build(&mut data.window)?;
97
98 nwg::TextInput::builder()
99 .text("Hello World!")
100 .focus(true)
101 .parent(&data.window)
102 .build(&mut data.message_content)?;
103
104 nwg::Button::builder()
105 .text("Save")
106 .parent(&data.window)
107 .build(&mut data.add_message_btn)?;
108
109 nwg::TextInput::builder()
110 .text("Title")
111 .parent(&data.window)
112 .build(&mut data.message_title)?;
113
114 // Wrap-up
115 let ui = MessageBankUi {
116 inner: Rc::new(data),
117 default_handler: Default::default(),
118 };
119
120 // Events
121 let window_handles = [&ui.window.handle];
122
123 for handle in window_handles.iter() {
124 let evt_ui = Rc::downgrade(&ui.inner);
125 let handle_events = move |evt, _evt_data, handle| {
126 if let Some(evt_ui) = evt_ui.upgrade() {
127 match evt {
128 E::OnButtonClick => {
129 if &handle == &evt_ui.add_message_btn {
130 MessageBank::add_message(&evt_ui);
131 }
132 }
133 E::OnWindowClose => {
134 if &handle == &evt_ui.window {
135 MessageBank::exit(&evt_ui);
136 }
137 }
138 _ => {}
139 }
140 }
141 };
142
143 ui.default_handler
144 .borrow_mut()
145 .push(nwg::full_bind_event_handler(handle, handle_events));
146 }
147
148 // Layout
149 nwg::GridLayout::builder()
150 .parent(&ui.window)
151 .max_row(Some(6))
152 .child(0, 0, &ui.add_message_btn)
153 .child_item(nwg::GridLayoutItem::new(&ui.message_title, 1, 0, 2, 1))
154 .child_item(nwg::GridLayoutItem::new(&ui.message_content, 3, 0, 3, 1))
155 .build(&ui.layout)?;
156
157 return Ok(ui);
158 }examples/flexbox_sub_layout.rs (line 47)
42 fn build_ui(mut data: FlexBoxApp) -> Result<FlexBoxAppUi, nwg::NwgError> {
43 use nwg::Event as E;
44
45 // Controls
46 nwg::Window::builder()
47 .size((500, 500))
48 .position((300, 300))
49 .title("Flexbox example")
50 .build(&mut data.window)?;
51
52 nwg::Button::builder()
53 .text("Btn 1")
54 .parent(&data.window)
55 .focus(true)
56 .build(&mut data.button1)?;
57
58 nwg::Button::builder()
59 .text("Btn 2")
60 .parent(&data.window)
61 .focus(true)
62 .build(&mut data.button2)?;
63
64 nwg::Button::builder()
65 .text("Btn 3")
66 .parent(&data.window)
67 .focus(true)
68 .build(&mut data.button3)?;
69
70 // Wrap-up
71 let ui = FlexBoxAppUi {
72 inner: Rc::new(data),
73 default_handler: Default::default(),
74 };
75
76 // Events
77 let evt_ui = Rc::downgrade(&ui.inner);
78 let handle_events = move |evt, _evt_data, handle| {
79 if let Some(evt_ui) = evt_ui.upgrade() {
80 match evt {
81 E::OnWindowClose => {
82 if &handle == &evt_ui.window {
83 FlexBoxApp::exit(&evt_ui);
84 }
85 }
86 _ => {}
87 }
88 }
89 };
90
91 *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(
92 &ui.window.handle,
93 handle_events,
94 ));
95
96 // Layout
97 use nwg::stretch::{
98 geometry::Size,
99 style::{Dimension as D, FlexDirection},
100 };
101
102 nwg::FlexboxLayout::builder()
103 .parent(&ui.window)
104 .flex_direction(FlexDirection::Column)
105 .child(&ui.button2)
106 .child_size(Size {
107 width: D::Auto,
108 height: D::Points(200.0),
109 })
110 .child(&ui.button3)
111 .child_flex_grow(2.0)
112 .child_size(Size {
113 width: D::Auto,
114 height: D::Auto,
115 })
116 .build_partial(&ui.layout2)?;
117
118 nwg::FlexboxLayout::builder()
119 .parent(&ui.window)
120 .flex_direction(FlexDirection::Row)
121 .child(&ui.button1)
122 .child_flex_grow(2.0)
123 .child_size(Size {
124 width: D::Auto,
125 height: D::Auto,
126 })
127 .child_layout(&ui.layout2)
128 .child_size(Size {
129 width: D::Points(300.0),
130 height: D::Auto,
131 })
132 .build(&ui.layout)?;
133
134 return Ok(ui);
135 }Additional examples can be found in:
Sourcepub fn position(self, pos: (i32, i32)) -> WindowBuilder<'a>
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 // !!! Partials Event Dispatch !!!
52 ui.form.process_event(evt, &evt_data, handle);
53
54 match evt {
55 E::OnButtonClick => {
56 if &handle == &ui.form.sumbit_button {
57 println!("SAVING!");
58 }
59 }
60 E::OnWindowClose => {
61 if &handle == &ui.window {
62 nwg::stop_thread_dispatch();
63 }
64 }
65 _ => {}
66 }
67 }
68 };
69
70 ui.default_handler
71 .borrow_mut()
72 .push(nwg::full_bind_event_handler(handle, handle_events));
73 }
74
75 return Ok(ui);
76 }More examples
examples/basic.rs (line 58)
51 fn build_ui(mut data: BasicApp) -> Result<BasicAppUi, nwg::NwgError> {
52 use nwg::Event as E;
53
54 // Controls
55 nwg::Window::builder()
56 .flags(nwg::WindowFlags::WINDOW | nwg::WindowFlags::VISIBLE)
57 .size((300, 135))
58 .position((300, 300))
59 .title("Basic example")
60 .build(&mut data.window)?;
61
62 nwg::TextInput::builder()
63 .size((280, 35))
64 .position((10, 10))
65 .text("Heisenberg")
66 .parent(&data.window)
67 .focus(true)
68 .build(&mut data.name_edit)?;
69
70 nwg::Button::builder()
71 .size((280, 70))
72 .position((10, 50))
73 .text("Say my name")
74 .parent(&data.window)
75 .build(&mut data.hello_button)?;
76
77 // Wrap-up
78 let ui = BasicAppUi {
79 inner: Rc::new(data),
80 default_handler: Default::default(),
81 };
82
83 // Events
84 let evt_ui = Rc::downgrade(&ui.inner);
85 let handle_events = move |evt, _evt_data, handle| {
86 if let Some(ui) = evt_ui.upgrade() {
87 match evt {
88 E::OnButtonClick => {
89 if &handle == &ui.hello_button {
90 BasicApp::say_hello(&ui);
91 }
92 }
93 E::OnWindowClose => {
94 if &handle == &ui.window {
95 BasicApp::say_goodbye(&ui);
96 }
97 }
98 _ => {}
99 }
100 }
101 };
102
103 *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(
104 &ui.window.handle,
105 handle_events,
106 ));
107
108 return Ok(ui);
109 }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(
59 &events_window.handle,
60 "Goodbye",
61 &format!("Goodbye {}", name_edit.text()),
62 );
63 nwg::stop_thread_dispatch();
64 }
65 }
66 E::OnButtonClick => {
67 if &handle == &hello_button {
68 nwg::modal_info_message(
69 &events_window.handle,
70 "Hello",
71 &format!("Hello {}", name_edit.text()),
72 );
73 }
74 }
75 _ => {}
76 }
77 });
78
79 nwg::dispatch_thread_events();
80 nwg::unbind_event_handler(&handler);
81}examples/basic_layout.rs (line 59)
52 fn build_ui(mut data: BasicApp) -> Result<BasicAppUi, nwg::NwgError> {
53 use nwg::Event as E;
54
55 // Controls
56 nwg::Window::builder()
57 .flags(nwg::WindowFlags::WINDOW | nwg::WindowFlags::VISIBLE)
58 .size((300, 115))
59 .position((300, 300))
60 .title("Basic example")
61 .build(&mut data.window)?;
62
63 nwg::TextInput::builder()
64 .text("Heisenberg")
65 .parent(&data.window)
66 .focus(true)
67 .build(&mut data.name_edit)?;
68
69 nwg::Button::builder()
70 .text("Say my name")
71 .parent(&data.window)
72 .build(&mut data.hello_button)?;
73
74 // Wrap-up
75 let ui = BasicAppUi {
76 inner: Rc::new(data),
77 default_handler: Default::default(),
78 };
79
80 // Events
81 let evt_ui = Rc::downgrade(&ui.inner);
82 let handle_events = move |evt, _evt_data, handle| {
83 if let Some(evt_ui) = evt_ui.upgrade() {
84 match evt {
85 E::OnButtonClick => {
86 if &handle == &evt_ui.hello_button {
87 BasicApp::say_hello(&evt_ui);
88 }
89 }
90 E::OnWindowClose => {
91 if &handle == &evt_ui.window {
92 BasicApp::say_goodbye(&evt_ui);
93 }
94 }
95 _ => {}
96 }
97 }
98 };
99
100 *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(
101 &ui.window.handle,
102 handle_events,
103 ));
104
105 // Layouts
106 nwg::GridLayout::builder()
107 .parent(&ui.window)
108 .spacing(1)
109 .child(0, 0, &ui.name_edit)
110 .child_item(nwg::GridLayoutItem::new(&ui.hello_button, 0, 1, 1, 2))
111 .build(&ui.layout)?;
112
113 return Ok(ui);
114 }examples/message_bank.rs (line 94)
87 fn build_ui(mut data: MessageBank) -> Result<MessageBankUi, nwg::NwgError> {
88 use nwg::Event as E;
89
90 // Controls
91 nwg::Window::builder()
92 .flags(nwg::WindowFlags::MAIN_WINDOW | nwg::WindowFlags::VISIBLE)
93 .size((400, 300))
94 .position((800, 300))
95 .title("My message bank")
96 .build(&mut data.window)?;
97
98 nwg::TextInput::builder()
99 .text("Hello World!")
100 .focus(true)
101 .parent(&data.window)
102 .build(&mut data.message_content)?;
103
104 nwg::Button::builder()
105 .text("Save")
106 .parent(&data.window)
107 .build(&mut data.add_message_btn)?;
108
109 nwg::TextInput::builder()
110 .text("Title")
111 .parent(&data.window)
112 .build(&mut data.message_title)?;
113
114 // Wrap-up
115 let ui = MessageBankUi {
116 inner: Rc::new(data),
117 default_handler: Default::default(),
118 };
119
120 // Events
121 let window_handles = [&ui.window.handle];
122
123 for handle in window_handles.iter() {
124 let evt_ui = Rc::downgrade(&ui.inner);
125 let handle_events = move |evt, _evt_data, handle| {
126 if let Some(evt_ui) = evt_ui.upgrade() {
127 match evt {
128 E::OnButtonClick => {
129 if &handle == &evt_ui.add_message_btn {
130 MessageBank::add_message(&evt_ui);
131 }
132 }
133 E::OnWindowClose => {
134 if &handle == &evt_ui.window {
135 MessageBank::exit(&evt_ui);
136 }
137 }
138 _ => {}
139 }
140 }
141 };
142
143 ui.default_handler
144 .borrow_mut()
145 .push(nwg::full_bind_event_handler(handle, handle_events));
146 }
147
148 // Layout
149 nwg::GridLayout::builder()
150 .parent(&ui.window)
151 .max_row(Some(6))
152 .child(0, 0, &ui.add_message_btn)
153 .child_item(nwg::GridLayoutItem::new(&ui.message_title, 1, 0, 2, 1))
154 .child_item(nwg::GridLayoutItem::new(&ui.message_content, 3, 0, 3, 1))
155 .build(&ui.layout)?;
156
157 return Ok(ui);
158 }examples/flexbox_sub_layout.rs (line 48)
42 fn build_ui(mut data: FlexBoxApp) -> Result<FlexBoxAppUi, nwg::NwgError> {
43 use nwg::Event as E;
44
45 // Controls
46 nwg::Window::builder()
47 .size((500, 500))
48 .position((300, 300))
49 .title("Flexbox example")
50 .build(&mut data.window)?;
51
52 nwg::Button::builder()
53 .text("Btn 1")
54 .parent(&data.window)
55 .focus(true)
56 .build(&mut data.button1)?;
57
58 nwg::Button::builder()
59 .text("Btn 2")
60 .parent(&data.window)
61 .focus(true)
62 .build(&mut data.button2)?;
63
64 nwg::Button::builder()
65 .text("Btn 3")
66 .parent(&data.window)
67 .focus(true)
68 .build(&mut data.button3)?;
69
70 // Wrap-up
71 let ui = FlexBoxAppUi {
72 inner: Rc::new(data),
73 default_handler: Default::default(),
74 };
75
76 // Events
77 let evt_ui = Rc::downgrade(&ui.inner);
78 let handle_events = move |evt, _evt_data, handle| {
79 if let Some(evt_ui) = evt_ui.upgrade() {
80 match evt {
81 E::OnWindowClose => {
82 if &handle == &evt_ui.window {
83 FlexBoxApp::exit(&evt_ui);
84 }
85 }
86 _ => {}
87 }
88 }
89 };
90
91 *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(
92 &ui.window.handle,
93 handle_events,
94 ));
95
96 // Layout
97 use nwg::stretch::{
98 geometry::Size,
99 style::{Dimension as D, FlexDirection},
100 };
101
102 nwg::FlexboxLayout::builder()
103 .parent(&ui.window)
104 .flex_direction(FlexDirection::Column)
105 .child(&ui.button2)
106 .child_size(Size {
107 width: D::Auto,
108 height: D::Points(200.0),
109 })
110 .child(&ui.button3)
111 .child_flex_grow(2.0)
112 .child_size(Size {
113 width: D::Auto,
114 height: D::Auto,
115 })
116 .build_partial(&ui.layout2)?;
117
118 nwg::FlexboxLayout::builder()
119 .parent(&ui.window)
120 .flex_direction(FlexDirection::Row)
121 .child(&ui.button1)
122 .child_flex_grow(2.0)
123 .child_size(Size {
124 width: D::Auto,
125 height: D::Auto,
126 })
127 .child_layout(&ui.layout2)
128 .child_size(Size {
129 width: D::Points(300.0),
130 height: D::Auto,
131 })
132 .build(&ui.layout)?;
133
134 return Ok(ui);
135 }Additional examples can be found in:
pub fn icon(self, ico: Option<&'a Icon>) -> WindowBuilder<'a>
pub fn accept_files(self, accept_files: bool) -> WindowBuilder<'a>
pub fn topmost(self, topmost: bool) -> WindowBuilder<'a>
pub fn center(self, center: bool) -> WindowBuilder<'a>
pub fn maximized(self, maximized: bool) -> WindowBuilder<'a>
pub fn minimized(self, minimized: bool) -> WindowBuilder<'a>
pub fn parent<C: Into<ControlHandle>>(self, p: Option<C>) -> WindowBuilder<'a>
Sourcepub fn build(self, out: &mut Window) -> Result<(), NwgError>
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 // !!! Partials Event Dispatch !!!
52 ui.form.process_event(evt, &evt_data, handle);
53
54 match evt {
55 E::OnButtonClick => {
56 if &handle == &ui.form.sumbit_button {
57 println!("SAVING!");
58 }
59 }
60 E::OnWindowClose => {
61 if &handle == &ui.window {
62 nwg::stop_thread_dispatch();
63 }
64 }
65 _ => {}
66 }
67 }
68 };
69
70 ui.default_handler
71 .borrow_mut()
72 .push(nwg::full_bind_event_handler(handle, handle_events));
73 }
74
75 return Ok(ui);
76 }More examples
examples/basic.rs (line 60)
51 fn build_ui(mut data: BasicApp) -> Result<BasicAppUi, nwg::NwgError> {
52 use nwg::Event as E;
53
54 // Controls
55 nwg::Window::builder()
56 .flags(nwg::WindowFlags::WINDOW | nwg::WindowFlags::VISIBLE)
57 .size((300, 135))
58 .position((300, 300))
59 .title("Basic example")
60 .build(&mut data.window)?;
61
62 nwg::TextInput::builder()
63 .size((280, 35))
64 .position((10, 10))
65 .text("Heisenberg")
66 .parent(&data.window)
67 .focus(true)
68 .build(&mut data.name_edit)?;
69
70 nwg::Button::builder()
71 .size((280, 70))
72 .position((10, 50))
73 .text("Say my name")
74 .parent(&data.window)
75 .build(&mut data.hello_button)?;
76
77 // Wrap-up
78 let ui = BasicAppUi {
79 inner: Rc::new(data),
80 default_handler: Default::default(),
81 };
82
83 // Events
84 let evt_ui = Rc::downgrade(&ui.inner);
85 let handle_events = move |evt, _evt_data, handle| {
86 if let Some(ui) = evt_ui.upgrade() {
87 match evt {
88 E::OnButtonClick => {
89 if &handle == &ui.hello_button {
90 BasicApp::say_hello(&ui);
91 }
92 }
93 E::OnWindowClose => {
94 if &handle == &ui.window {
95 BasicApp::say_goodbye(&ui);
96 }
97 }
98 _ => {}
99 }
100 }
101 };
102
103 *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(
104 &ui.window.handle,
105 handle_events,
106 ));
107
108 return Ok(ui);
109 }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(
59 &events_window.handle,
60 "Goodbye",
61 &format!("Goodbye {}", name_edit.text()),
62 );
63 nwg::stop_thread_dispatch();
64 }
65 }
66 E::OnButtonClick => {
67 if &handle == &hello_button {
68 nwg::modal_info_message(
69 &events_window.handle,
70 "Hello",
71 &format!("Hello {}", name_edit.text()),
72 );
73 }
74 }
75 _ => {}
76 }
77 });
78
79 nwg::dispatch_thread_events();
80 nwg::unbind_event_handler(&handler);
81}examples/basic_layout.rs (line 61)
52 fn build_ui(mut data: BasicApp) -> Result<BasicAppUi, nwg::NwgError> {
53 use nwg::Event as E;
54
55 // Controls
56 nwg::Window::builder()
57 .flags(nwg::WindowFlags::WINDOW | nwg::WindowFlags::VISIBLE)
58 .size((300, 115))
59 .position((300, 300))
60 .title("Basic example")
61 .build(&mut data.window)?;
62
63 nwg::TextInput::builder()
64 .text("Heisenberg")
65 .parent(&data.window)
66 .focus(true)
67 .build(&mut data.name_edit)?;
68
69 nwg::Button::builder()
70 .text("Say my name")
71 .parent(&data.window)
72 .build(&mut data.hello_button)?;
73
74 // Wrap-up
75 let ui = BasicAppUi {
76 inner: Rc::new(data),
77 default_handler: Default::default(),
78 };
79
80 // Events
81 let evt_ui = Rc::downgrade(&ui.inner);
82 let handle_events = move |evt, _evt_data, handle| {
83 if let Some(evt_ui) = evt_ui.upgrade() {
84 match evt {
85 E::OnButtonClick => {
86 if &handle == &evt_ui.hello_button {
87 BasicApp::say_hello(&evt_ui);
88 }
89 }
90 E::OnWindowClose => {
91 if &handle == &evt_ui.window {
92 BasicApp::say_goodbye(&evt_ui);
93 }
94 }
95 _ => {}
96 }
97 }
98 };
99
100 *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(
101 &ui.window.handle,
102 handle_events,
103 ));
104
105 // Layouts
106 nwg::GridLayout::builder()
107 .parent(&ui.window)
108 .spacing(1)
109 .child(0, 0, &ui.name_edit)
110 .child_item(nwg::GridLayoutItem::new(&ui.hello_button, 0, 1, 1, 2))
111 .build(&ui.layout)?;
112
113 return Ok(ui);
114 }examples/message_bank.rs (line 96)
87 fn build_ui(mut data: MessageBank) -> Result<MessageBankUi, nwg::NwgError> {
88 use nwg::Event as E;
89
90 // Controls
91 nwg::Window::builder()
92 .flags(nwg::WindowFlags::MAIN_WINDOW | nwg::WindowFlags::VISIBLE)
93 .size((400, 300))
94 .position((800, 300))
95 .title("My message bank")
96 .build(&mut data.window)?;
97
98 nwg::TextInput::builder()
99 .text("Hello World!")
100 .focus(true)
101 .parent(&data.window)
102 .build(&mut data.message_content)?;
103
104 nwg::Button::builder()
105 .text("Save")
106 .parent(&data.window)
107 .build(&mut data.add_message_btn)?;
108
109 nwg::TextInput::builder()
110 .text("Title")
111 .parent(&data.window)
112 .build(&mut data.message_title)?;
113
114 // Wrap-up
115 let ui = MessageBankUi {
116 inner: Rc::new(data),
117 default_handler: Default::default(),
118 };
119
120 // Events
121 let window_handles = [&ui.window.handle];
122
123 for handle in window_handles.iter() {
124 let evt_ui = Rc::downgrade(&ui.inner);
125 let handle_events = move |evt, _evt_data, handle| {
126 if let Some(evt_ui) = evt_ui.upgrade() {
127 match evt {
128 E::OnButtonClick => {
129 if &handle == &evt_ui.add_message_btn {
130 MessageBank::add_message(&evt_ui);
131 }
132 }
133 E::OnWindowClose => {
134 if &handle == &evt_ui.window {
135 MessageBank::exit(&evt_ui);
136 }
137 }
138 _ => {}
139 }
140 }
141 };
142
143 ui.default_handler
144 .borrow_mut()
145 .push(nwg::full_bind_event_handler(handle, handle_events));
146 }
147
148 // Layout
149 nwg::GridLayout::builder()
150 .parent(&ui.window)
151 .max_row(Some(6))
152 .child(0, 0, &ui.add_message_btn)
153 .child_item(nwg::GridLayoutItem::new(&ui.message_title, 1, 0, 2, 1))
154 .child_item(nwg::GridLayoutItem::new(&ui.message_content, 3, 0, 3, 1))
155 .build(&ui.layout)?;
156
157 return Ok(ui);
158 }examples/flexbox_sub_layout.rs (line 50)
42 fn build_ui(mut data: FlexBoxApp) -> Result<FlexBoxAppUi, nwg::NwgError> {
43 use nwg::Event as E;
44
45 // Controls
46 nwg::Window::builder()
47 .size((500, 500))
48 .position((300, 300))
49 .title("Flexbox example")
50 .build(&mut data.window)?;
51
52 nwg::Button::builder()
53 .text("Btn 1")
54 .parent(&data.window)
55 .focus(true)
56 .build(&mut data.button1)?;
57
58 nwg::Button::builder()
59 .text("Btn 2")
60 .parent(&data.window)
61 .focus(true)
62 .build(&mut data.button2)?;
63
64 nwg::Button::builder()
65 .text("Btn 3")
66 .parent(&data.window)
67 .focus(true)
68 .build(&mut data.button3)?;
69
70 // Wrap-up
71 let ui = FlexBoxAppUi {
72 inner: Rc::new(data),
73 default_handler: Default::default(),
74 };
75
76 // Events
77 let evt_ui = Rc::downgrade(&ui.inner);
78 let handle_events = move |evt, _evt_data, handle| {
79 if let Some(evt_ui) = evt_ui.upgrade() {
80 match evt {
81 E::OnWindowClose => {
82 if &handle == &evt_ui.window {
83 FlexBoxApp::exit(&evt_ui);
84 }
85 }
86 _ => {}
87 }
88 }
89 };
90
91 *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(
92 &ui.window.handle,
93 handle_events,
94 ));
95
96 // Layout
97 use nwg::stretch::{
98 geometry::Size,
99 style::{Dimension as D, FlexDirection},
100 };
101
102 nwg::FlexboxLayout::builder()
103 .parent(&ui.window)
104 .flex_direction(FlexDirection::Column)
105 .child(&ui.button2)
106 .child_size(Size {
107 width: D::Auto,
108 height: D::Points(200.0),
109 })
110 .child(&ui.button3)
111 .child_flex_grow(2.0)
112 .child_size(Size {
113 width: D::Auto,
114 height: D::Auto,
115 })
116 .build_partial(&ui.layout2)?;
117
118 nwg::FlexboxLayout::builder()
119 .parent(&ui.window)
120 .flex_direction(FlexDirection::Row)
121 .child(&ui.button1)
122 .child_flex_grow(2.0)
123 .child_size(Size {
124 width: D::Auto,
125 height: D::Auto,
126 })
127 .child_layout(&ui.layout2)
128 .child_size(Size {
129 width: D::Points(300.0),
130 height: D::Auto,
131 })
132 .build(&ui.layout)?;
133
134 return Ok(ui);
135 }Additional examples can be found in:
Auto Trait Implementations§
impl<'a> !Send for WindowBuilder<'a>
impl<'a> !Sync for WindowBuilder<'a>
impl<'a> Freeze for WindowBuilder<'a>
impl<'a> RefUnwindSafe for WindowBuilder<'a>
impl<'a> Unpin for WindowBuilder<'a>
impl<'a> UnsafeUnpin for WindowBuilder<'a>
impl<'a> UnwindSafe for WindowBuilder<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more