TextInputBuilder

Struct TextInputBuilder 

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

Implementations§

Source§

impl<'a> TextInputBuilder<'a>

Source

pub fn flags(self, flags: TextInputFlags) -> TextInputBuilder<'a>

Examples found in repository?
examples/partials.rs (line 300)
269        fn build_partial<W: Into<ControlHandle>>(
270            data: &mut PeopleUi,
271            parent: Option<W>,
272        ) -> Result<(), NwgError> {
273            let parent = parent.unwrap().into();
274
275            nwg::Label::builder()
276                .text("Name:")
277                .h_align(nwg::HTextAlign::Right)
278                .parent(&parent)
279                .build(&mut data.label1)?;
280
281            nwg::Label::builder()
282                .text("Age:")
283                .h_align(nwg::HTextAlign::Right)
284                .parent(&parent)
285                .build(&mut data.label2)?;
286
287            nwg::Label::builder()
288                .text("Job:")
289                .h_align(nwg::HTextAlign::Right)
290                .parent(&parent)
291                .build(&mut data.label3)?;
292
293            nwg::TextInput::builder()
294                .text("John Doe")
295                .parent(&parent)
296                .build(&mut data.name_input)?;
297
298            nwg::TextInput::builder()
299                .text("75")
300                .flags(nwg::TextInputFlags::VISIBLE | nwg::TextInputFlags::NUMBER)
301                .parent(&parent)
302                .build(&mut data.age_input)?;
303
304            nwg::TextInput::builder()
305                .text("Programmer")
306                .parent(&parent)
307                .build(&mut data.job_input)?;
308
309            nwg::Button::builder()
310                .text("Save")
311                .parent(&parent)
312                .build(&mut data.save_btn)?;
313
314            nwg::GridLayout::builder()
315                .parent(&parent)
316                .max_size([1000, 150])
317                .min_size([100, 120])
318                .child(0, 0, &data.label1)
319                .child(0, 1, &data.label2)
320                .child(0, 2, &data.label3)
321                .child(1, 0, &data.name_input)
322                .child(1, 1, &data.age_input)
323                .child(1, 2, &data.job_input)
324                .build(&data.layout)?;
325
326            nwg::GridLayout::builder()
327                .min_size([100, 200])
328                .max_column(Some(2))
329                .max_row(Some(6))
330                .child(1, 5, &data.save_btn)
331                .parent(&parent)
332                .build(&data.layout2)?;
333
334            Ok(())
335        }
Source

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

Source

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

Examples found in repository?
examples/partial_simple.rs (line 95)
88    fn build_partial<W: Into<nwg::ControlHandle>>(
89        data: &mut SubmitForm,
90        parent: Option<W>,
91    ) -> Result<(), nwg::NwgError> {
92        let parent = parent.unwrap().into();
93
94        nwg::TextInput::builder()
95            .text(&data.form_data)
96            .parent(&parent)
97            .build(&mut data.value)?;
98
99        nwg::Button::builder()
100            .text("Save")
101            .parent(&parent)
102            .build(&mut data.sumbit_button)?;
103
104        nwg::GridLayout::builder()
105            .child(0, 0, &data.value)
106            .child(0, 1, &data.sumbit_button)
107            .parent(&parent)
108            .build(&data.layout)?;
109
110        Ok(())
111    }
More examples
Hide additional examples
examples/basic.rs (line 65)
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 29)
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 64)
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/partials.rs (line 294)
269        fn build_partial<W: Into<ControlHandle>>(
270            data: &mut PeopleUi,
271            parent: Option<W>,
272        ) -> Result<(), NwgError> {
273            let parent = parent.unwrap().into();
274
275            nwg::Label::builder()
276                .text("Name:")
277                .h_align(nwg::HTextAlign::Right)
278                .parent(&parent)
279                .build(&mut data.label1)?;
280
281            nwg::Label::builder()
282                .text("Age:")
283                .h_align(nwg::HTextAlign::Right)
284                .parent(&parent)
285                .build(&mut data.label2)?;
286
287            nwg::Label::builder()
288                .text("Job:")
289                .h_align(nwg::HTextAlign::Right)
290                .parent(&parent)
291                .build(&mut data.label3)?;
292
293            nwg::TextInput::builder()
294                .text("John Doe")
295                .parent(&parent)
296                .build(&mut data.name_input)?;
297
298            nwg::TextInput::builder()
299                .text("75")
300                .flags(nwg::TextInputFlags::VISIBLE | nwg::TextInputFlags::NUMBER)
301                .parent(&parent)
302                .build(&mut data.age_input)?;
303
304            nwg::TextInput::builder()
305                .text("Programmer")
306                .parent(&parent)
307                .build(&mut data.job_input)?;
308
309            nwg::Button::builder()
310                .text("Save")
311                .parent(&parent)
312                .build(&mut data.save_btn)?;
313
314            nwg::GridLayout::builder()
315                .parent(&parent)
316                .max_size([1000, 150])
317                .min_size([100, 120])
318                .child(0, 0, &data.label1)
319                .child(0, 1, &data.label2)
320                .child(0, 2, &data.label3)
321                .child(1, 0, &data.name_input)
322                .child(1, 1, &data.age_input)
323                .child(1, 2, &data.job_input)
324                .build(&data.layout)?;
325
326            nwg::GridLayout::builder()
327                .min_size([100, 200])
328                .max_column(Some(2))
329                .max_row(Some(6))
330                .child(1, 5, &data.save_btn)
331                .parent(&parent)
332                .build(&data.layout2)?;
333
334            Ok(())
335        }
336
337        fn process_event<'a>(
338            &self,
339            _evt: nwg::Event,
340            _evt_data: &nwg::EventData,
341            _handle: ControlHandle,
342        ) {
343        }
344
345        fn handles(&self) -> Vec<&ControlHandle> {
346            Vec::new()
347        }
348    }
349}
350
351mod partial_animal_ui {
352    use self::nwg::{ControlHandle, NwgError, PartialUi};
353    use super::*;
354    use native_windows_gui2 as nwg;
355
356    impl PartialUi for AnimalUi {
357        fn build_partial<W: Into<ControlHandle>>(
358            data: &mut AnimalUi,
359            parent: Option<W>,
360        ) -> Result<(), NwgError> {
361            let parent = parent.unwrap().into();
362
363            nwg::Label::builder()
364                .text("Name:")
365                .h_align(nwg::HTextAlign::Right)
366                .parent(&parent)
367                .build(&mut data.label1)?;
368
369            nwg::Label::builder()
370                .text("Race:")
371                .h_align(nwg::HTextAlign::Right)
372                .parent(&parent)
373                .build(&mut data.label2)?;
374
375            nwg::Label::builder()
376                .text("Is fluffy:")
377                .h_align(nwg::HTextAlign::Right)
378                .parent(&parent)
379                .build(&mut data.label3)?;
380
381            nwg::TextInput::builder()
382                .text("Mittens")
383                .parent(&parent)
384                .build(&mut data.name_input)?;
385
386            nwg::ComboBox::builder()
387                .collection(vec!["Cat", "Dog", "Pidgeon", "Monkey"])
388                .selected_index(Some(0))
389                .parent(&parent)
390                .build(&mut data.race_input)?;
391
392            nwg::CheckBox::builder()
393                .text("")
394                .check_state(nwg::CheckBoxState::Checked)
395                .parent(&parent)
396                .build(&mut data.is_soft_input)?;
397
398            nwg::Button::builder()
399                .text("Save")
400                .parent(&parent)
401                .build(&mut data.save_btn)?;
402
403            nwg::GridLayout::builder()
404                .parent(&parent)
405                .max_size([1000, 150])
406                .min_size([100, 120])
407                .child(0, 0, &data.label1)
408                .child(0, 1, &data.label2)
409                .child(0, 2, &data.label3)
410                .child(1, 0, &data.name_input)
411                .child(1, 1, &data.race_input)
412                .child(1, 2, &data.is_soft_input)
413                .build(&data.layout)?;
414
415            nwg::GridLayout::builder()
416                .min_size([100, 200])
417                .max_column(Some(2))
418                .max_row(Some(6))
419                .child(1, 5, &data.save_btn)
420                .parent(&parent)
421                .build(&data.layout2)?;
422
423            Ok(())
424        }
425
426        fn process_event<'a>(
427            &self,
428            _evt: nwg::Event,
429            _evt_data: &nwg::EventData,
430            _handle: ControlHandle,
431        ) {
432        }
433
434        fn handles(&self) -> Vec<&ControlHandle> {
435            Vec::new()
436        }
437    }
438}
439
440mod partial_food_ui {
441    use self::nwg::{ControlHandle, NwgError, PartialUi};
442    use super::*;
443    use native_windows_gui2 as nwg;
444
445    impl PartialUi for FoodUi {
446        fn build_partial<W: Into<ControlHandle>>(
447            data: &mut FoodUi,
448            parent: Option<W>,
449        ) -> Result<(), NwgError> {
450            let parent = parent.unwrap().into();
451
452            nwg::Label::builder()
453                .text("Name:")
454                .h_align(nwg::HTextAlign::Right)
455                .parent(&parent)
456                .build(&mut data.label1)?;
457
458            nwg::Label::builder()
459                .text("Tasty:")
460                .h_align(nwg::HTextAlign::Right)
461                .parent(&parent)
462                .build(&mut data.label2)?;
463
464            nwg::TextInput::builder()
465                .text("Banana")
466                .parent(&parent)
467                .build(&mut data.name_input)?;
468
469            nwg::CheckBox::builder()
470                .text("")
471                .check_state(nwg::CheckBoxState::Checked)
472                .parent(&parent)
473                .build(&mut data.tasty_input)?;
474
475            nwg::Button::builder()
476                .text("Save")
477                .parent(&parent)
478                .build(&mut data.save_btn)?;
479
480            nwg::GridLayout::builder()
481                .parent(&parent)
482                .max_size([1000, 90])
483                .min_size([100, 80])
484                .child(0, 0, &data.label1)
485                .child(0, 1, &data.label2)
486                .child(1, 0, &data.name_input)
487                .child(1, 1, &data.tasty_input)
488                .build(&data.layout)?;
489
490            nwg::GridLayout::builder()
491                .min_size([100, 200])
492                .max_column(Some(2))
493                .max_row(Some(6))
494                .child(1, 5, &data.save_btn)
495                .parent(&parent)
496                .build(&data.layout2)?;
497
498            Ok(())
499        }
examples/message_bank.rs (line 99)
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        }
Source

pub fn placeholder_text( self, placeholder_text: Option<&'a str>, ) -> TextInputBuilder<'a>

Source

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

Examples found in repository?
examples/basic.rs (line 63)
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        }
Source

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

Examples found in repository?
examples/basic.rs (line 64)
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        }
Source

pub fn limit(self, limit: usize) -> TextInputBuilder<'a>

Source

pub fn password(self, psw: Option<char>) -> TextInputBuilder<'a>

Source

pub fn align(self, align: HTextAlign) -> TextInputBuilder<'a>

Examples found in repository?
examples/calculator.rs (line 162)
150        fn build_ui(mut data: Calculator) -> Result<CalculatorUi, nwg::NwgError> {
151            use nwg::Event as E;
152
153            // Controls
154            nwg::Window::builder()
155                .size((300, 150))
156                .position((300, 300))
157                .title("Calculator")
158                .build(&mut data.window)?;
159
160            nwg::TextInput::builder()
161                .text("")
162                .align(nwg::HTextAlign::Right)
163                .readonly(true)
164                .parent(&data.window)
165                .build(&mut data.input)?;
166
167            nwg::Button::builder()
168                .text("1")
169                .parent(&data.window)
170                .focus(true)
171                .build(&mut data.btn1)?;
172
173            nwg::Button::builder()
174                .text("2")
175                .parent(&data.window)
176                .build(&mut data.btn2)?;
177            nwg::Button::builder()
178                .text("3")
179                .parent(&data.window)
180                .build(&mut data.btn3)?;
181            nwg::Button::builder()
182                .text("4")
183                .parent(&data.window)
184                .build(&mut data.btn4)?;
185            nwg::Button::builder()
186                .text("5")
187                .parent(&data.window)
188                .build(&mut data.btn5)?;
189            nwg::Button::builder()
190                .text("6")
191                .parent(&data.window)
192                .build(&mut data.btn6)?;
193            nwg::Button::builder()
194                .text("7")
195                .parent(&data.window)
196                .build(&mut data.btn7)?;
197            nwg::Button::builder()
198                .text("8")
199                .parent(&data.window)
200                .build(&mut data.btn8)?;
201            nwg::Button::builder()
202                .text("9")
203                .parent(&data.window)
204                .build(&mut data.btn9)?;
205            nwg::Button::builder()
206                .text("0")
207                .parent(&data.window)
208                .build(&mut data.btn0)?;
209
210            nwg::Button::builder()
211                .text("+")
212                .parent(&data.window)
213                .build(&mut data.btn_plus)?;
214            nwg::Button::builder()
215                .text("-")
216                .parent(&data.window)
217                .build(&mut data.btn_minus)?;
218            nwg::Button::builder()
219                .text("*")
220                .parent(&data.window)
221                .build(&mut data.btn_mult)?;
222            nwg::Button::builder()
223                .text("/")
224                .parent(&data.window)
225                .build(&mut data.btn_divide)?;
226            nwg::Button::builder()
227                .text("Clear")
228                .parent(&data.window)
229                .build(&mut data.btn_clear)?;
230            nwg::Button::builder()
231                .text("=")
232                .parent(&data.window)
233                .build(&mut data.btn_process)?;
234
235            // Wrap-up
236            let ui = CalculatorUi {
237                inner: Rc::new(data),
238                default_handler: Default::default(),
239            };
240
241            // Events
242            let window_handles = [&ui.window.handle];
243            for handle in window_handles.iter() {
244                let evt_ui = Rc::downgrade(&ui.inner);
245                let handle_events = move |evt, _evt_data, handle| {
246                    if let Some(evt_ui) = evt_ui.upgrade() {
247                        match evt {
248                            E::OnButtonClick => {
249                                if &handle == &evt_ui.btn0 {
250                                    Calculator::number(&evt_ui, &evt_ui.btn0);
251                                } else if &handle == &evt_ui.btn1 {
252                                    Calculator::number(&evt_ui, &evt_ui.btn1);
253                                } else if &handle == &evt_ui.btn2 {
254                                    Calculator::number(&evt_ui, &evt_ui.btn2);
255                                } else if &handle == &evt_ui.btn3 {
256                                    Calculator::number(&evt_ui, &evt_ui.btn3);
257                                } else if &handle == &evt_ui.btn4 {
258                                    Calculator::number(&evt_ui, &evt_ui.btn4);
259                                } else if &handle == &evt_ui.btn5 {
260                                    Calculator::number(&evt_ui, &evt_ui.btn5);
261                                } else if &handle == &evt_ui.btn6 {
262                                    Calculator::number(&evt_ui, &evt_ui.btn6);
263                                } else if &handle == &evt_ui.btn7 {
264                                    Calculator::number(&evt_ui, &evt_ui.btn7);
265                                } else if &handle == &evt_ui.btn8 {
266                                    Calculator::number(&evt_ui, &evt_ui.btn8);
267                                } else if &handle == &evt_ui.btn9 {
268                                    Calculator::number(&evt_ui, &evt_ui.btn9);
269                                } else if &handle == &evt_ui.btn_plus {
270                                    Calculator::number(&evt_ui, &evt_ui.btn_plus);
271                                } else if &handle == &evt_ui.btn_minus {
272                                    Calculator::number(&evt_ui, &evt_ui.btn_minus);
273                                } else if &handle == &evt_ui.btn_mult {
274                                    Calculator::number(&evt_ui, &evt_ui.btn_mult);
275                                } else if &handle == &evt_ui.btn_divide {
276                                    Calculator::number(&evt_ui, &evt_ui.btn_divide);
277                                } else if &handle == &evt_ui.btn_clear {
278                                    Calculator::clear(&evt_ui);
279                                } else if &handle == &evt_ui.btn_process {
280                                    Calculator::compute(&evt_ui);
281                                }
282                            }
283                            E::OnWindowClose => {
284                                if &handle == &evt_ui.window {
285                                    Calculator::exit(&evt_ui);
286                                }
287                            }
288                            _ => {}
289                        }
290                    }
291                };
292
293                ui.default_handler
294                    .borrow_mut()
295                    .push(nwg::full_bind_event_handler(handle, handle_events));
296            }
297
298            // Layouts
299            nwg::GridLayout::builder()
300                .parent(&ui.window)
301                .spacing(2)
302                .min_size([150, 140])
303                .child_item(nwg::GridLayoutItem::new(&ui.input, 0, 0, 5, 1))
304                .child(0, 1, &ui.btn1)
305                .child(1, 1, &ui.btn2)
306                .child(2, 1, &ui.btn3)
307                .child(0, 2, &ui.btn4)
308                .child(1, 2, &ui.btn5)
309                .child(2, 2, &ui.btn6)
310                .child(0, 3, &ui.btn7)
311                .child(1, 3, &ui.btn8)
312                .child(2, 3, &ui.btn9)
313                .child(3, 1, &ui.btn_plus)
314                .child(4, 1, &ui.btn_minus)
315                .child(3, 2, &ui.btn_mult)
316                .child(4, 2, &ui.btn_divide)
317                .child_item(nwg::GridLayoutItem::new(&ui.btn_clear, 3, 3, 2, 1))
318                .child_item(nwg::GridLayoutItem::new(&ui.btn_process, 3, 4, 2, 1))
319                .child_item(nwg::GridLayoutItem::new(&ui.btn0, 0, 4, 3, 1))
320                .build(&ui.layout)?;
321
322            return Ok(ui);
323        }
Source

pub fn readonly(self, read: bool) -> TextInputBuilder<'a>

Examples found in repository?
examples/calculator.rs (line 163)
150        fn build_ui(mut data: Calculator) -> Result<CalculatorUi, nwg::NwgError> {
151            use nwg::Event as E;
152
153            // Controls
154            nwg::Window::builder()
155                .size((300, 150))
156                .position((300, 300))
157                .title("Calculator")
158                .build(&mut data.window)?;
159
160            nwg::TextInput::builder()
161                .text("")
162                .align(nwg::HTextAlign::Right)
163                .readonly(true)
164                .parent(&data.window)
165                .build(&mut data.input)?;
166
167            nwg::Button::builder()
168                .text("1")
169                .parent(&data.window)
170                .focus(true)
171                .build(&mut data.btn1)?;
172
173            nwg::Button::builder()
174                .text("2")
175                .parent(&data.window)
176                .build(&mut data.btn2)?;
177            nwg::Button::builder()
178                .text("3")
179                .parent(&data.window)
180                .build(&mut data.btn3)?;
181            nwg::Button::builder()
182                .text("4")
183                .parent(&data.window)
184                .build(&mut data.btn4)?;
185            nwg::Button::builder()
186                .text("5")
187                .parent(&data.window)
188                .build(&mut data.btn5)?;
189            nwg::Button::builder()
190                .text("6")
191                .parent(&data.window)
192                .build(&mut data.btn6)?;
193            nwg::Button::builder()
194                .text("7")
195                .parent(&data.window)
196                .build(&mut data.btn7)?;
197            nwg::Button::builder()
198                .text("8")
199                .parent(&data.window)
200                .build(&mut data.btn8)?;
201            nwg::Button::builder()
202                .text("9")
203                .parent(&data.window)
204                .build(&mut data.btn9)?;
205            nwg::Button::builder()
206                .text("0")
207                .parent(&data.window)
208                .build(&mut data.btn0)?;
209
210            nwg::Button::builder()
211                .text("+")
212                .parent(&data.window)
213                .build(&mut data.btn_plus)?;
214            nwg::Button::builder()
215                .text("-")
216                .parent(&data.window)
217                .build(&mut data.btn_minus)?;
218            nwg::Button::builder()
219                .text("*")
220                .parent(&data.window)
221                .build(&mut data.btn_mult)?;
222            nwg::Button::builder()
223                .text("/")
224                .parent(&data.window)
225                .build(&mut data.btn_divide)?;
226            nwg::Button::builder()
227                .text("Clear")
228                .parent(&data.window)
229                .build(&mut data.btn_clear)?;
230            nwg::Button::builder()
231                .text("=")
232                .parent(&data.window)
233                .build(&mut data.btn_process)?;
234
235            // Wrap-up
236            let ui = CalculatorUi {
237                inner: Rc::new(data),
238                default_handler: Default::default(),
239            };
240
241            // Events
242            let window_handles = [&ui.window.handle];
243            for handle in window_handles.iter() {
244                let evt_ui = Rc::downgrade(&ui.inner);
245                let handle_events = move |evt, _evt_data, handle| {
246                    if let Some(evt_ui) = evt_ui.upgrade() {
247                        match evt {
248                            E::OnButtonClick => {
249                                if &handle == &evt_ui.btn0 {
250                                    Calculator::number(&evt_ui, &evt_ui.btn0);
251                                } else if &handle == &evt_ui.btn1 {
252                                    Calculator::number(&evt_ui, &evt_ui.btn1);
253                                } else if &handle == &evt_ui.btn2 {
254                                    Calculator::number(&evt_ui, &evt_ui.btn2);
255                                } else if &handle == &evt_ui.btn3 {
256                                    Calculator::number(&evt_ui, &evt_ui.btn3);
257                                } else if &handle == &evt_ui.btn4 {
258                                    Calculator::number(&evt_ui, &evt_ui.btn4);
259                                } else if &handle == &evt_ui.btn5 {
260                                    Calculator::number(&evt_ui, &evt_ui.btn5);
261                                } else if &handle == &evt_ui.btn6 {
262                                    Calculator::number(&evt_ui, &evt_ui.btn6);
263                                } else if &handle == &evt_ui.btn7 {
264                                    Calculator::number(&evt_ui, &evt_ui.btn7);
265                                } else if &handle == &evt_ui.btn8 {
266                                    Calculator::number(&evt_ui, &evt_ui.btn8);
267                                } else if &handle == &evt_ui.btn9 {
268                                    Calculator::number(&evt_ui, &evt_ui.btn9);
269                                } else if &handle == &evt_ui.btn_plus {
270                                    Calculator::number(&evt_ui, &evt_ui.btn_plus);
271                                } else if &handle == &evt_ui.btn_minus {
272                                    Calculator::number(&evt_ui, &evt_ui.btn_minus);
273                                } else if &handle == &evt_ui.btn_mult {
274                                    Calculator::number(&evt_ui, &evt_ui.btn_mult);
275                                } else if &handle == &evt_ui.btn_divide {
276                                    Calculator::number(&evt_ui, &evt_ui.btn_divide);
277                                } else if &handle == &evt_ui.btn_clear {
278                                    Calculator::clear(&evt_ui);
279                                } else if &handle == &evt_ui.btn_process {
280                                    Calculator::compute(&evt_ui);
281                                }
282                            }
283                            E::OnWindowClose => {
284                                if &handle == &evt_ui.window {
285                                    Calculator::exit(&evt_ui);
286                                }
287                            }
288                            _ => {}
289                        }
290                    }
291                };
292
293                ui.default_handler
294                    .borrow_mut()
295                    .push(nwg::full_bind_event_handler(handle, handle_events));
296            }
297
298            // Layouts
299            nwg::GridLayout::builder()
300                .parent(&ui.window)
301                .spacing(2)
302                .min_size([150, 140])
303                .child_item(nwg::GridLayoutItem::new(&ui.input, 0, 0, 5, 1))
304                .child(0, 1, &ui.btn1)
305                .child(1, 1, &ui.btn2)
306                .child(2, 1, &ui.btn3)
307                .child(0, 2, &ui.btn4)
308                .child(1, 2, &ui.btn5)
309                .child(2, 2, &ui.btn6)
310                .child(0, 3, &ui.btn7)
311                .child(1, 3, &ui.btn8)
312                .child(2, 3, &ui.btn9)
313                .child(3, 1, &ui.btn_plus)
314                .child(4, 1, &ui.btn_minus)
315                .child(3, 2, &ui.btn_mult)
316                .child(4, 2, &ui.btn_divide)
317                .child_item(nwg::GridLayoutItem::new(&ui.btn_clear, 3, 3, 2, 1))
318                .child_item(nwg::GridLayoutItem::new(&ui.btn_process, 3, 4, 2, 1))
319                .child_item(nwg::GridLayoutItem::new(&ui.btn0, 0, 4, 3, 1))
320                .build(&ui.layout)?;
321
322            return Ok(ui);
323        }
Source

pub fn font(self, font: Option<&'a Font>) -> TextInputBuilder<'a>

Source

pub fn background_color(self, color: Option<[u8; 3]>) -> TextInputBuilder<'a>

Source

pub fn focus(self, focus: bool) -> TextInputBuilder<'a>

Examples found in repository?
examples/basic.rs (line 67)
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
Hide additional examples
examples/basic_barebone.rs (line 30)
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 66)
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 100)
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        }
Source

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

Examples found in repository?
examples/partial_simple.rs (line 96)
88    fn build_partial<W: Into<nwg::ControlHandle>>(
89        data: &mut SubmitForm,
90        parent: Option<W>,
91    ) -> Result<(), nwg::NwgError> {
92        let parent = parent.unwrap().into();
93
94        nwg::TextInput::builder()
95            .text(&data.form_data)
96            .parent(&parent)
97            .build(&mut data.value)?;
98
99        nwg::Button::builder()
100            .text("Save")
101            .parent(&parent)
102            .build(&mut data.sumbit_button)?;
103
104        nwg::GridLayout::builder()
105            .child(0, 0, &data.value)
106            .child(0, 1, &data.sumbit_button)
107            .parent(&parent)
108            .build(&data.layout)?;
109
110        Ok(())
111    }
More examples
Hide additional examples
examples/basic.rs (line 66)
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 31)
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 65)
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/partials.rs (line 295)
269        fn build_partial<W: Into<ControlHandle>>(
270            data: &mut PeopleUi,
271            parent: Option<W>,
272        ) -> Result<(), NwgError> {
273            let parent = parent.unwrap().into();
274
275            nwg::Label::builder()
276                .text("Name:")
277                .h_align(nwg::HTextAlign::Right)
278                .parent(&parent)
279                .build(&mut data.label1)?;
280
281            nwg::Label::builder()
282                .text("Age:")
283                .h_align(nwg::HTextAlign::Right)
284                .parent(&parent)
285                .build(&mut data.label2)?;
286
287            nwg::Label::builder()
288                .text("Job:")
289                .h_align(nwg::HTextAlign::Right)
290                .parent(&parent)
291                .build(&mut data.label3)?;
292
293            nwg::TextInput::builder()
294                .text("John Doe")
295                .parent(&parent)
296                .build(&mut data.name_input)?;
297
298            nwg::TextInput::builder()
299                .text("75")
300                .flags(nwg::TextInputFlags::VISIBLE | nwg::TextInputFlags::NUMBER)
301                .parent(&parent)
302                .build(&mut data.age_input)?;
303
304            nwg::TextInput::builder()
305                .text("Programmer")
306                .parent(&parent)
307                .build(&mut data.job_input)?;
308
309            nwg::Button::builder()
310                .text("Save")
311                .parent(&parent)
312                .build(&mut data.save_btn)?;
313
314            nwg::GridLayout::builder()
315                .parent(&parent)
316                .max_size([1000, 150])
317                .min_size([100, 120])
318                .child(0, 0, &data.label1)
319                .child(0, 1, &data.label2)
320                .child(0, 2, &data.label3)
321                .child(1, 0, &data.name_input)
322                .child(1, 1, &data.age_input)
323                .child(1, 2, &data.job_input)
324                .build(&data.layout)?;
325
326            nwg::GridLayout::builder()
327                .min_size([100, 200])
328                .max_column(Some(2))
329                .max_row(Some(6))
330                .child(1, 5, &data.save_btn)
331                .parent(&parent)
332                .build(&data.layout2)?;
333
334            Ok(())
335        }
336
337        fn process_event<'a>(
338            &self,
339            _evt: nwg::Event,
340            _evt_data: &nwg::EventData,
341            _handle: ControlHandle,
342        ) {
343        }
344
345        fn handles(&self) -> Vec<&ControlHandle> {
346            Vec::new()
347        }
348    }
349}
350
351mod partial_animal_ui {
352    use self::nwg::{ControlHandle, NwgError, PartialUi};
353    use super::*;
354    use native_windows_gui2 as nwg;
355
356    impl PartialUi for AnimalUi {
357        fn build_partial<W: Into<ControlHandle>>(
358            data: &mut AnimalUi,
359            parent: Option<W>,
360        ) -> Result<(), NwgError> {
361            let parent = parent.unwrap().into();
362
363            nwg::Label::builder()
364                .text("Name:")
365                .h_align(nwg::HTextAlign::Right)
366                .parent(&parent)
367                .build(&mut data.label1)?;
368
369            nwg::Label::builder()
370                .text("Race:")
371                .h_align(nwg::HTextAlign::Right)
372                .parent(&parent)
373                .build(&mut data.label2)?;
374
375            nwg::Label::builder()
376                .text("Is fluffy:")
377                .h_align(nwg::HTextAlign::Right)
378                .parent(&parent)
379                .build(&mut data.label3)?;
380
381            nwg::TextInput::builder()
382                .text("Mittens")
383                .parent(&parent)
384                .build(&mut data.name_input)?;
385
386            nwg::ComboBox::builder()
387                .collection(vec!["Cat", "Dog", "Pidgeon", "Monkey"])
388                .selected_index(Some(0))
389                .parent(&parent)
390                .build(&mut data.race_input)?;
391
392            nwg::CheckBox::builder()
393                .text("")
394                .check_state(nwg::CheckBoxState::Checked)
395                .parent(&parent)
396                .build(&mut data.is_soft_input)?;
397
398            nwg::Button::builder()
399                .text("Save")
400                .parent(&parent)
401                .build(&mut data.save_btn)?;
402
403            nwg::GridLayout::builder()
404                .parent(&parent)
405                .max_size([1000, 150])
406                .min_size([100, 120])
407                .child(0, 0, &data.label1)
408                .child(0, 1, &data.label2)
409                .child(0, 2, &data.label3)
410                .child(1, 0, &data.name_input)
411                .child(1, 1, &data.race_input)
412                .child(1, 2, &data.is_soft_input)
413                .build(&data.layout)?;
414
415            nwg::GridLayout::builder()
416                .min_size([100, 200])
417                .max_column(Some(2))
418                .max_row(Some(6))
419                .child(1, 5, &data.save_btn)
420                .parent(&parent)
421                .build(&data.layout2)?;
422
423            Ok(())
424        }
425
426        fn process_event<'a>(
427            &self,
428            _evt: nwg::Event,
429            _evt_data: &nwg::EventData,
430            _handle: ControlHandle,
431        ) {
432        }
433
434        fn handles(&self) -> Vec<&ControlHandle> {
435            Vec::new()
436        }
437    }
438}
439
440mod partial_food_ui {
441    use self::nwg::{ControlHandle, NwgError, PartialUi};
442    use super::*;
443    use native_windows_gui2 as nwg;
444
445    impl PartialUi for FoodUi {
446        fn build_partial<W: Into<ControlHandle>>(
447            data: &mut FoodUi,
448            parent: Option<W>,
449        ) -> Result<(), NwgError> {
450            let parent = parent.unwrap().into();
451
452            nwg::Label::builder()
453                .text("Name:")
454                .h_align(nwg::HTextAlign::Right)
455                .parent(&parent)
456                .build(&mut data.label1)?;
457
458            nwg::Label::builder()
459                .text("Tasty:")
460                .h_align(nwg::HTextAlign::Right)
461                .parent(&parent)
462                .build(&mut data.label2)?;
463
464            nwg::TextInput::builder()
465                .text("Banana")
466                .parent(&parent)
467                .build(&mut data.name_input)?;
468
469            nwg::CheckBox::builder()
470                .text("")
471                .check_state(nwg::CheckBoxState::Checked)
472                .parent(&parent)
473                .build(&mut data.tasty_input)?;
474
475            nwg::Button::builder()
476                .text("Save")
477                .parent(&parent)
478                .build(&mut data.save_btn)?;
479
480            nwg::GridLayout::builder()
481                .parent(&parent)
482                .max_size([1000, 90])
483                .min_size([100, 80])
484                .child(0, 0, &data.label1)
485                .child(0, 1, &data.label2)
486                .child(1, 0, &data.name_input)
487                .child(1, 1, &data.tasty_input)
488                .build(&data.layout)?;
489
490            nwg::GridLayout::builder()
491                .min_size([100, 200])
492                .max_column(Some(2))
493                .max_row(Some(6))
494                .child(1, 5, &data.save_btn)
495                .parent(&parent)
496                .build(&data.layout2)?;
497
498            Ok(())
499        }
examples/message_bank.rs (line 101)
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        }
Source

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

Examples found in repository?
examples/partial_simple.rs (line 97)
88    fn build_partial<W: Into<nwg::ControlHandle>>(
89        data: &mut SubmitForm,
90        parent: Option<W>,
91    ) -> Result<(), nwg::NwgError> {
92        let parent = parent.unwrap().into();
93
94        nwg::TextInput::builder()
95            .text(&data.form_data)
96            .parent(&parent)
97            .build(&mut data.value)?;
98
99        nwg::Button::builder()
100            .text("Save")
101            .parent(&parent)
102            .build(&mut data.sumbit_button)?;
103
104        nwg::GridLayout::builder()
105            .child(0, 0, &data.value)
106            .child(0, 1, &data.sumbit_button)
107            .parent(&parent)
108            .build(&data.layout)?;
109
110        Ok(())
111    }
More examples
Hide additional examples
examples/basic.rs (line 68)
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 32)
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 67)
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/partials.rs (line 296)
269        fn build_partial<W: Into<ControlHandle>>(
270            data: &mut PeopleUi,
271            parent: Option<W>,
272        ) -> Result<(), NwgError> {
273            let parent = parent.unwrap().into();
274
275            nwg::Label::builder()
276                .text("Name:")
277                .h_align(nwg::HTextAlign::Right)
278                .parent(&parent)
279                .build(&mut data.label1)?;
280
281            nwg::Label::builder()
282                .text("Age:")
283                .h_align(nwg::HTextAlign::Right)
284                .parent(&parent)
285                .build(&mut data.label2)?;
286
287            nwg::Label::builder()
288                .text("Job:")
289                .h_align(nwg::HTextAlign::Right)
290                .parent(&parent)
291                .build(&mut data.label3)?;
292
293            nwg::TextInput::builder()
294                .text("John Doe")
295                .parent(&parent)
296                .build(&mut data.name_input)?;
297
298            nwg::TextInput::builder()
299                .text("75")
300                .flags(nwg::TextInputFlags::VISIBLE | nwg::TextInputFlags::NUMBER)
301                .parent(&parent)
302                .build(&mut data.age_input)?;
303
304            nwg::TextInput::builder()
305                .text("Programmer")
306                .parent(&parent)
307                .build(&mut data.job_input)?;
308
309            nwg::Button::builder()
310                .text("Save")
311                .parent(&parent)
312                .build(&mut data.save_btn)?;
313
314            nwg::GridLayout::builder()
315                .parent(&parent)
316                .max_size([1000, 150])
317                .min_size([100, 120])
318                .child(0, 0, &data.label1)
319                .child(0, 1, &data.label2)
320                .child(0, 2, &data.label3)
321                .child(1, 0, &data.name_input)
322                .child(1, 1, &data.age_input)
323                .child(1, 2, &data.job_input)
324                .build(&data.layout)?;
325
326            nwg::GridLayout::builder()
327                .min_size([100, 200])
328                .max_column(Some(2))
329                .max_row(Some(6))
330                .child(1, 5, &data.save_btn)
331                .parent(&parent)
332                .build(&data.layout2)?;
333
334            Ok(())
335        }
336
337        fn process_event<'a>(
338            &self,
339            _evt: nwg::Event,
340            _evt_data: &nwg::EventData,
341            _handle: ControlHandle,
342        ) {
343        }
344
345        fn handles(&self) -> Vec<&ControlHandle> {
346            Vec::new()
347        }
348    }
349}
350
351mod partial_animal_ui {
352    use self::nwg::{ControlHandle, NwgError, PartialUi};
353    use super::*;
354    use native_windows_gui2 as nwg;
355
356    impl PartialUi for AnimalUi {
357        fn build_partial<W: Into<ControlHandle>>(
358            data: &mut AnimalUi,
359            parent: Option<W>,
360        ) -> Result<(), NwgError> {
361            let parent = parent.unwrap().into();
362
363            nwg::Label::builder()
364                .text("Name:")
365                .h_align(nwg::HTextAlign::Right)
366                .parent(&parent)
367                .build(&mut data.label1)?;
368
369            nwg::Label::builder()
370                .text("Race:")
371                .h_align(nwg::HTextAlign::Right)
372                .parent(&parent)
373                .build(&mut data.label2)?;
374
375            nwg::Label::builder()
376                .text("Is fluffy:")
377                .h_align(nwg::HTextAlign::Right)
378                .parent(&parent)
379                .build(&mut data.label3)?;
380
381            nwg::TextInput::builder()
382                .text("Mittens")
383                .parent(&parent)
384                .build(&mut data.name_input)?;
385
386            nwg::ComboBox::builder()
387                .collection(vec!["Cat", "Dog", "Pidgeon", "Monkey"])
388                .selected_index(Some(0))
389                .parent(&parent)
390                .build(&mut data.race_input)?;
391
392            nwg::CheckBox::builder()
393                .text("")
394                .check_state(nwg::CheckBoxState::Checked)
395                .parent(&parent)
396                .build(&mut data.is_soft_input)?;
397
398            nwg::Button::builder()
399                .text("Save")
400                .parent(&parent)
401                .build(&mut data.save_btn)?;
402
403            nwg::GridLayout::builder()
404                .parent(&parent)
405                .max_size([1000, 150])
406                .min_size([100, 120])
407                .child(0, 0, &data.label1)
408                .child(0, 1, &data.label2)
409                .child(0, 2, &data.label3)
410                .child(1, 0, &data.name_input)
411                .child(1, 1, &data.race_input)
412                .child(1, 2, &data.is_soft_input)
413                .build(&data.layout)?;
414
415            nwg::GridLayout::builder()
416                .min_size([100, 200])
417                .max_column(Some(2))
418                .max_row(Some(6))
419                .child(1, 5, &data.save_btn)
420                .parent(&parent)
421                .build(&data.layout2)?;
422
423            Ok(())
424        }
425
426        fn process_event<'a>(
427            &self,
428            _evt: nwg::Event,
429            _evt_data: &nwg::EventData,
430            _handle: ControlHandle,
431        ) {
432        }
433
434        fn handles(&self) -> Vec<&ControlHandle> {
435            Vec::new()
436        }
437    }
438}
439
440mod partial_food_ui {
441    use self::nwg::{ControlHandle, NwgError, PartialUi};
442    use super::*;
443    use native_windows_gui2 as nwg;
444
445    impl PartialUi for FoodUi {
446        fn build_partial<W: Into<ControlHandle>>(
447            data: &mut FoodUi,
448            parent: Option<W>,
449        ) -> Result<(), NwgError> {
450            let parent = parent.unwrap().into();
451
452            nwg::Label::builder()
453                .text("Name:")
454                .h_align(nwg::HTextAlign::Right)
455                .parent(&parent)
456                .build(&mut data.label1)?;
457
458            nwg::Label::builder()
459                .text("Tasty:")
460                .h_align(nwg::HTextAlign::Right)
461                .parent(&parent)
462                .build(&mut data.label2)?;
463
464            nwg::TextInput::builder()
465                .text("Banana")
466                .parent(&parent)
467                .build(&mut data.name_input)?;
468
469            nwg::CheckBox::builder()
470                .text("")
471                .check_state(nwg::CheckBoxState::Checked)
472                .parent(&parent)
473                .build(&mut data.tasty_input)?;
474
475            nwg::Button::builder()
476                .text("Save")
477                .parent(&parent)
478                .build(&mut data.save_btn)?;
479
480            nwg::GridLayout::builder()
481                .parent(&parent)
482                .max_size([1000, 90])
483                .min_size([100, 80])
484                .child(0, 0, &data.label1)
485                .child(0, 1, &data.label2)
486                .child(1, 0, &data.name_input)
487                .child(1, 1, &data.tasty_input)
488                .build(&data.layout)?;
489
490            nwg::GridLayout::builder()
491                .min_size([100, 200])
492                .max_column(Some(2))
493                .max_row(Some(6))
494                .child(1, 5, &data.save_btn)
495                .parent(&parent)
496                .build(&data.layout2)?;
497
498            Ok(())
499        }
examples/message_bank.rs (line 102)
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        }

Auto Trait Implementations§

§

impl<'a> Freeze for TextInputBuilder<'a>

§

impl<'a> RefUnwindSafe for TextInputBuilder<'a>

§

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

§

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

§

impl<'a> Unpin for TextInputBuilder<'a>

§

impl<'a> UnwindSafe for TextInputBuilder<'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.