Skip to main content

FlexboxLayoutBuilder

Struct FlexboxLayoutBuilder 

Source
pub struct FlexboxLayoutBuilder { /* private fields */ }

Implementations§

Source§

impl FlexboxLayoutBuilder

Source

pub fn parent<W: Into<ControlHandle>>(self, p: W) -> FlexboxLayoutBuilder

Set the layout parent. The handle must be a window object otherwise the function will panic

Examples found in repository?
examples/flexbox_sub_layout.rs (line 103)
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        }
More examples
Hide additional examples
examples/flexbox.rs (line 115)
41        fn build_ui(mut data: FlexBoxApp) -> Result<FlexBoxAppUi, nwg::NwgError> {
42            use nwg::Event as E;
43
44            // Controls
45            nwg::Window::builder()
46                .size((500, 300))
47                .position((300, 300))
48                .title("Flexbox example")
49                .build(&mut data.window)?;
50
51            nwg::Button::builder()
52                .text("Btn 1")
53                .parent(&data.window)
54                .focus(true)
55                .build(&mut data.button1)?;
56
57            nwg::Button::builder()
58                .text("Btn 2")
59                .parent(&data.window)
60                .build(&mut data.button2)?;
61
62            nwg::Button::builder()
63                .text("Btn 3")
64                .parent(&data.window)
65                .build(&mut data.button3)?;
66
67            // Wrap-up
68            let ui = FlexBoxAppUi {
69                inner: Rc::new(data),
70                default_handler: Default::default(),
71            };
72
73            // Events
74            let evt_ui = Rc::downgrade(&ui.inner);
75            let handle_events = move |evt, _evt_data, handle| {
76                if let Some(evt_ui) = evt_ui.upgrade() {
77                    match evt {
78                        E::OnWindowClose => {
79                            if &handle == &evt_ui.window {
80                                FlexBoxApp::exit(&evt_ui);
81                            }
82                        }
83                        _ => {}
84                    }
85                }
86            };
87
88            *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(
89                &ui.window.handle,
90                handle_events,
91            ));
92
93            // Layout
94            use nwg::stretch::{
95                geometry::{Rect, Size},
96                style::{AlignSelf, Dimension as D, FlexDirection},
97            };
98            const FIFTY_PC: D = D::Percent(0.5);
99            const PT_10: D = D::Points(10.0);
100            const PT_5: D = D::Points(5.0);
101            const PADDING: Rect<D> = Rect {
102                start: PT_10,
103                end: PT_10,
104                top: PT_10,
105                bottom: PT_10,
106            };
107            const MARGIN: Rect<D> = Rect {
108                start: PT_5,
109                end: PT_5,
110                top: PT_5,
111                bottom: PT_5,
112            };
113
114            nwg::FlexboxLayout::builder()
115                .parent(&ui.window)
116                .flex_direction(FlexDirection::Row)
117                .padding(PADDING)
118                .child(&ui.button1)
119                .child_margin(MARGIN)
120                .child_max_size(Size {
121                    width: D::Points(200.0),
122                    height: D::Undefined,
123                })
124                .child_size(Size {
125                    width: FIFTY_PC,
126                    height: D::Auto,
127                })
128                .child(&ui.button2)
129                .child_margin(MARGIN)
130                .child_align_self(AlignSelf::FlexEnd)
131                .child_size(Size {
132                    width: D::Percent(0.25),
133                    height: FIFTY_PC,
134                })
135                .child(&ui.button3)
136                .child_margin(MARGIN)
137                .child_flex_grow(2.0)
138                .child_size(Size {
139                    width: D::Auto,
140                    height: D::Auto,
141                })
142                .build(&ui.layout)?;
143
144            return Ok(ui);
145        }
examples/partials.rs (line 227)
141        fn build_ui(mut data: PartialDemo) -> Result<Rc<PartialDemoUi>, nwg::NwgError> {
142            use nwg::Event as E;
143
144            // Controls
145            nwg::Window::builder()
146                .size((500, 400))
147                .position((300, 300))
148                .title("Many UI")
149                .build(&mut data.window)?;
150
151            nwg::ListBox::builder()
152                .collection(vec!["People", "Animals", "Food"])
153                .focus(true)
154                .parent(&data.window)
155                .build(&mut data.menu)?;
156
157            nwg::Frame::builder()
158                .parent(&data.window)
159                .build(&mut data.frame1)?;
160
161            nwg::Frame::builder()
162                .flags(nwg::FrameFlags::BORDER)
163                .parent(&data.window)
164                .build(&mut data.frame2)?;
165
166            nwg::Frame::builder()
167                .flags(nwg::FrameFlags::BORDER)
168                .parent(&data.window)
169                .build(&mut data.frame3)?;
170
171            // Partials
172            PeopleUi::build_partial(&mut data.people_ui, Some(&data.frame1))?;
173            AnimalUi::build_partial(&mut data.animal_ui, Some(&data.frame2))?;
174            FoodUi::build_partial(&mut data.food_ui, Some(&data.frame3))?;
175
176            // Wrap-up
177            let ui = Rc::new(PartialDemoUi {
178                inner: data,
179                default_handler: Default::default(),
180            });
181
182            // Events
183            let mut window_handles = vec![&ui.window.handle];
184            window_handles.append(&mut ui.people_ui.handles());
185            window_handles.append(&mut ui.animal_ui.handles());
186            window_handles.append(&mut ui.food_ui.handles());
187
188            for handle in window_handles.iter() {
189                let evt_ui = ui.clone();
190                let handle_events = move |evt, evt_data, handle| {
191                    evt_ui.people_ui.process_event(evt, &evt_data, handle);
192                    evt_ui.animal_ui.process_event(evt, &evt_data, handle);
193                    evt_ui.food_ui.process_event(evt, &evt_data, handle);
194
195                    match evt {
196                        E::OnListBoxSelect => {
197                            if &handle == &evt_ui.menu {
198                                PartialDemo::change_interface(&evt_ui.inner);
199                            }
200                        }
201                        E::OnWindowClose => {
202                            if &handle == &evt_ui.window {
203                                PartialDemo::exit(&evt_ui.inner);
204                            }
205                        }
206                        E::OnButtonClick => {
207                            if &handle == &evt_ui.people_ui.save_btn
208                                || &handle == &evt_ui.animal_ui.save_btn
209                                || &handle == &evt_ui.food_ui.save_btn
210                            {
211                                PartialDemo::save(&evt_ui.inner);
212                            }
213                        }
214                        _ => {}
215                    }
216                };
217
218                ui.default_handler
219                    .borrow_mut()
220                    .push(nwg::full_bind_event_handler(handle, handle_events));
221            }
222
223            // Layout
224            use nwg::stretch::{geometry::Size, style::Dimension as D};
225
226            nwg::FlexboxLayout::builder()
227                .parent(&ui.window)
228                .child(&ui.menu)
229                .child_size(Size {
230                    width: D::Percent(0.3),
231                    height: D::Auto,
232                })
233                .child(&ui.frame1)
234                .child_size(Size {
235                    width: D::Percent(1.0),
236                    height: D::Auto,
237                })
238                .build(&ui.layout)?;
239
240            return Ok(ui);
241        }
Source

pub fn child<W: Into<ControlHandle>>(self, child: W) -> FlexboxLayoutBuilder

Add a new child to the layout build. Panics if child is not a window-like control.

Examples found in repository?
examples/flexbox_sub_layout.rs (line 105)
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        }
More examples
Hide additional examples
examples/flexbox.rs (line 118)
41        fn build_ui(mut data: FlexBoxApp) -> Result<FlexBoxAppUi, nwg::NwgError> {
42            use nwg::Event as E;
43
44            // Controls
45            nwg::Window::builder()
46                .size((500, 300))
47                .position((300, 300))
48                .title("Flexbox example")
49                .build(&mut data.window)?;
50
51            nwg::Button::builder()
52                .text("Btn 1")
53                .parent(&data.window)
54                .focus(true)
55                .build(&mut data.button1)?;
56
57            nwg::Button::builder()
58                .text("Btn 2")
59                .parent(&data.window)
60                .build(&mut data.button2)?;
61
62            nwg::Button::builder()
63                .text("Btn 3")
64                .parent(&data.window)
65                .build(&mut data.button3)?;
66
67            // Wrap-up
68            let ui = FlexBoxAppUi {
69                inner: Rc::new(data),
70                default_handler: Default::default(),
71            };
72
73            // Events
74            let evt_ui = Rc::downgrade(&ui.inner);
75            let handle_events = move |evt, _evt_data, handle| {
76                if let Some(evt_ui) = evt_ui.upgrade() {
77                    match evt {
78                        E::OnWindowClose => {
79                            if &handle == &evt_ui.window {
80                                FlexBoxApp::exit(&evt_ui);
81                            }
82                        }
83                        _ => {}
84                    }
85                }
86            };
87
88            *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(
89                &ui.window.handle,
90                handle_events,
91            ));
92
93            // Layout
94            use nwg::stretch::{
95                geometry::{Rect, Size},
96                style::{AlignSelf, Dimension as D, FlexDirection},
97            };
98            const FIFTY_PC: D = D::Percent(0.5);
99            const PT_10: D = D::Points(10.0);
100            const PT_5: D = D::Points(5.0);
101            const PADDING: Rect<D> = Rect {
102                start: PT_10,
103                end: PT_10,
104                top: PT_10,
105                bottom: PT_10,
106            };
107            const MARGIN: Rect<D> = Rect {
108                start: PT_5,
109                end: PT_5,
110                top: PT_5,
111                bottom: PT_5,
112            };
113
114            nwg::FlexboxLayout::builder()
115                .parent(&ui.window)
116                .flex_direction(FlexDirection::Row)
117                .padding(PADDING)
118                .child(&ui.button1)
119                .child_margin(MARGIN)
120                .child_max_size(Size {
121                    width: D::Points(200.0),
122                    height: D::Undefined,
123                })
124                .child_size(Size {
125                    width: FIFTY_PC,
126                    height: D::Auto,
127                })
128                .child(&ui.button2)
129                .child_margin(MARGIN)
130                .child_align_self(AlignSelf::FlexEnd)
131                .child_size(Size {
132                    width: D::Percent(0.25),
133                    height: FIFTY_PC,
134                })
135                .child(&ui.button3)
136                .child_margin(MARGIN)
137                .child_flex_grow(2.0)
138                .child_size(Size {
139                    width: D::Auto,
140                    height: D::Auto,
141                })
142                .build(&ui.layout)?;
143
144            return Ok(ui);
145        }
examples/partials.rs (line 228)
141        fn build_ui(mut data: PartialDemo) -> Result<Rc<PartialDemoUi>, nwg::NwgError> {
142            use nwg::Event as E;
143
144            // Controls
145            nwg::Window::builder()
146                .size((500, 400))
147                .position((300, 300))
148                .title("Many UI")
149                .build(&mut data.window)?;
150
151            nwg::ListBox::builder()
152                .collection(vec!["People", "Animals", "Food"])
153                .focus(true)
154                .parent(&data.window)
155                .build(&mut data.menu)?;
156
157            nwg::Frame::builder()
158                .parent(&data.window)
159                .build(&mut data.frame1)?;
160
161            nwg::Frame::builder()
162                .flags(nwg::FrameFlags::BORDER)
163                .parent(&data.window)
164                .build(&mut data.frame2)?;
165
166            nwg::Frame::builder()
167                .flags(nwg::FrameFlags::BORDER)
168                .parent(&data.window)
169                .build(&mut data.frame3)?;
170
171            // Partials
172            PeopleUi::build_partial(&mut data.people_ui, Some(&data.frame1))?;
173            AnimalUi::build_partial(&mut data.animal_ui, Some(&data.frame2))?;
174            FoodUi::build_partial(&mut data.food_ui, Some(&data.frame3))?;
175
176            // Wrap-up
177            let ui = Rc::new(PartialDemoUi {
178                inner: data,
179                default_handler: Default::default(),
180            });
181
182            // Events
183            let mut window_handles = vec![&ui.window.handle];
184            window_handles.append(&mut ui.people_ui.handles());
185            window_handles.append(&mut ui.animal_ui.handles());
186            window_handles.append(&mut ui.food_ui.handles());
187
188            for handle in window_handles.iter() {
189                let evt_ui = ui.clone();
190                let handle_events = move |evt, evt_data, handle| {
191                    evt_ui.people_ui.process_event(evt, &evt_data, handle);
192                    evt_ui.animal_ui.process_event(evt, &evt_data, handle);
193                    evt_ui.food_ui.process_event(evt, &evt_data, handle);
194
195                    match evt {
196                        E::OnListBoxSelect => {
197                            if &handle == &evt_ui.menu {
198                                PartialDemo::change_interface(&evt_ui.inner);
199                            }
200                        }
201                        E::OnWindowClose => {
202                            if &handle == &evt_ui.window {
203                                PartialDemo::exit(&evt_ui.inner);
204                            }
205                        }
206                        E::OnButtonClick => {
207                            if &handle == &evt_ui.people_ui.save_btn
208                                || &handle == &evt_ui.animal_ui.save_btn
209                                || &handle == &evt_ui.food_ui.save_btn
210                            {
211                                PartialDemo::save(&evt_ui.inner);
212                            }
213                        }
214                        _ => {}
215                    }
216                };
217
218                ui.default_handler
219                    .borrow_mut()
220                    .push(nwg::full_bind_event_handler(handle, handle_events));
221            }
222
223            // Layout
224            use nwg::stretch::{geometry::Size, style::Dimension as D};
225
226            nwg::FlexboxLayout::builder()
227                .parent(&ui.window)
228                .child(&ui.menu)
229                .child_size(Size {
230                    width: D::Percent(0.3),
231                    height: D::Auto,
232                })
233                .child(&ui.frame1)
234                .child_size(Size {
235                    width: D::Percent(1.0),
236                    height: D::Auto,
237                })
238                .build(&ui.layout)?;
239
240            return Ok(ui);
241        }
Source

pub fn child_layout(self, child: &FlexboxLayout) -> FlexboxLayoutBuilder

Add a new child layout to the layout build.

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

pub fn auto_size(self, auto: bool) -> FlexboxLayoutBuilder

Make it so that the children of the layout all have equal size This flags is erased when size, max_size, or min_size is set on the children.

Source

pub fn auto_spacing(self, auto: Option<u32>) -> FlexboxLayoutBuilder

Automatically generate padding and margin for the parent layout and the children from the selected value. This flags is erased when padding is called on the layout or when child_margin is called on the children

Source

pub fn direction(self, value: Direction) -> FlexboxLayoutBuilder

Source

pub fn flex_direction(self, value: FlexDirection) -> FlexboxLayoutBuilder

Examples found in repository?
examples/flexbox_sub_layout.rs (line 104)
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        }
More examples
Hide additional examples
examples/flexbox.rs (line 116)
41        fn build_ui(mut data: FlexBoxApp) -> Result<FlexBoxAppUi, nwg::NwgError> {
42            use nwg::Event as E;
43
44            // Controls
45            nwg::Window::builder()
46                .size((500, 300))
47                .position((300, 300))
48                .title("Flexbox example")
49                .build(&mut data.window)?;
50
51            nwg::Button::builder()
52                .text("Btn 1")
53                .parent(&data.window)
54                .focus(true)
55                .build(&mut data.button1)?;
56
57            nwg::Button::builder()
58                .text("Btn 2")
59                .parent(&data.window)
60                .build(&mut data.button2)?;
61
62            nwg::Button::builder()
63                .text("Btn 3")
64                .parent(&data.window)
65                .build(&mut data.button3)?;
66
67            // Wrap-up
68            let ui = FlexBoxAppUi {
69                inner: Rc::new(data),
70                default_handler: Default::default(),
71            };
72
73            // Events
74            let evt_ui = Rc::downgrade(&ui.inner);
75            let handle_events = move |evt, _evt_data, handle| {
76                if let Some(evt_ui) = evt_ui.upgrade() {
77                    match evt {
78                        E::OnWindowClose => {
79                            if &handle == &evt_ui.window {
80                                FlexBoxApp::exit(&evt_ui);
81                            }
82                        }
83                        _ => {}
84                    }
85                }
86            };
87
88            *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(
89                &ui.window.handle,
90                handle_events,
91            ));
92
93            // Layout
94            use nwg::stretch::{
95                geometry::{Rect, Size},
96                style::{AlignSelf, Dimension as D, FlexDirection},
97            };
98            const FIFTY_PC: D = D::Percent(0.5);
99            const PT_10: D = D::Points(10.0);
100            const PT_5: D = D::Points(5.0);
101            const PADDING: Rect<D> = Rect {
102                start: PT_10,
103                end: PT_10,
104                top: PT_10,
105                bottom: PT_10,
106            };
107            const MARGIN: Rect<D> = Rect {
108                start: PT_5,
109                end: PT_5,
110                top: PT_5,
111                bottom: PT_5,
112            };
113
114            nwg::FlexboxLayout::builder()
115                .parent(&ui.window)
116                .flex_direction(FlexDirection::Row)
117                .padding(PADDING)
118                .child(&ui.button1)
119                .child_margin(MARGIN)
120                .child_max_size(Size {
121                    width: D::Points(200.0),
122                    height: D::Undefined,
123                })
124                .child_size(Size {
125                    width: FIFTY_PC,
126                    height: D::Auto,
127                })
128                .child(&ui.button2)
129                .child_margin(MARGIN)
130                .child_align_self(AlignSelf::FlexEnd)
131                .child_size(Size {
132                    width: D::Percent(0.25),
133                    height: FIFTY_PC,
134                })
135                .child(&ui.button3)
136                .child_margin(MARGIN)
137                .child_flex_grow(2.0)
138                .child_size(Size {
139                    width: D::Auto,
140                    height: D::Auto,
141                })
142                .build(&ui.layout)?;
143
144            return Ok(ui);
145        }
Source

pub fn flex_wrap(self, value: FlexWrap) -> FlexboxLayoutBuilder

Source

pub fn overflow(self, value: Overflow) -> FlexboxLayoutBuilder

Source

pub fn align_items(self, value: AlignItems) -> FlexboxLayoutBuilder

Source

pub fn align_content(self, value: AlignContent) -> FlexboxLayoutBuilder

Source

pub fn justify_content(self, value: JustifyContent) -> FlexboxLayoutBuilder

Source

pub fn padding(self, value: Rect<Dimension>) -> FlexboxLayoutBuilder

Examples found in repository?
examples/flexbox.rs (line 117)
41        fn build_ui(mut data: FlexBoxApp) -> Result<FlexBoxAppUi, nwg::NwgError> {
42            use nwg::Event as E;
43
44            // Controls
45            nwg::Window::builder()
46                .size((500, 300))
47                .position((300, 300))
48                .title("Flexbox example")
49                .build(&mut data.window)?;
50
51            nwg::Button::builder()
52                .text("Btn 1")
53                .parent(&data.window)
54                .focus(true)
55                .build(&mut data.button1)?;
56
57            nwg::Button::builder()
58                .text("Btn 2")
59                .parent(&data.window)
60                .build(&mut data.button2)?;
61
62            nwg::Button::builder()
63                .text("Btn 3")
64                .parent(&data.window)
65                .build(&mut data.button3)?;
66
67            // Wrap-up
68            let ui = FlexBoxAppUi {
69                inner: Rc::new(data),
70                default_handler: Default::default(),
71            };
72
73            // Events
74            let evt_ui = Rc::downgrade(&ui.inner);
75            let handle_events = move |evt, _evt_data, handle| {
76                if let Some(evt_ui) = evt_ui.upgrade() {
77                    match evt {
78                        E::OnWindowClose => {
79                            if &handle == &evt_ui.window {
80                                FlexBoxApp::exit(&evt_ui);
81                            }
82                        }
83                        _ => {}
84                    }
85                }
86            };
87
88            *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(
89                &ui.window.handle,
90                handle_events,
91            ));
92
93            // Layout
94            use nwg::stretch::{
95                geometry::{Rect, Size},
96                style::{AlignSelf, Dimension as D, FlexDirection},
97            };
98            const FIFTY_PC: D = D::Percent(0.5);
99            const PT_10: D = D::Points(10.0);
100            const PT_5: D = D::Points(5.0);
101            const PADDING: Rect<D> = Rect {
102                start: PT_10,
103                end: PT_10,
104                top: PT_10,
105                bottom: PT_10,
106            };
107            const MARGIN: Rect<D> = Rect {
108                start: PT_5,
109                end: PT_5,
110                top: PT_5,
111                bottom: PT_5,
112            };
113
114            nwg::FlexboxLayout::builder()
115                .parent(&ui.window)
116                .flex_direction(FlexDirection::Row)
117                .padding(PADDING)
118                .child(&ui.button1)
119                .child_margin(MARGIN)
120                .child_max_size(Size {
121                    width: D::Points(200.0),
122                    height: D::Undefined,
123                })
124                .child_size(Size {
125                    width: FIFTY_PC,
126                    height: D::Auto,
127                })
128                .child(&ui.button2)
129                .child_margin(MARGIN)
130                .child_align_self(AlignSelf::FlexEnd)
131                .child_size(Size {
132                    width: D::Percent(0.25),
133                    height: FIFTY_PC,
134                })
135                .child(&ui.button3)
136                .child_margin(MARGIN)
137                .child_flex_grow(2.0)
138                .child_size(Size {
139                    width: D::Auto,
140                    height: D::Auto,
141                })
142                .build(&ui.layout)?;
143
144            return Ok(ui);
145        }
Source

pub fn border(self, value: Rect<Dimension>) -> FlexboxLayoutBuilder

Source

pub fn min_size(self, value: Size<Dimension>) -> FlexboxLayoutBuilder

Source

pub fn max_size(self, value: Size<Dimension>) -> FlexboxLayoutBuilder

Source

pub fn aspect_ratio(self, value: Number) -> FlexboxLayoutBuilder

Source

pub fn child_size(self, size: Size<Dimension>) -> FlexboxLayoutBuilder

Set the size of of the current child. Panics if child was not called before.

Examples found in repository?
examples/flexbox_sub_layout.rs (lines 106-109)
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        }
More examples
Hide additional examples
examples/flexbox.rs (lines 124-127)
41        fn build_ui(mut data: FlexBoxApp) -> Result<FlexBoxAppUi, nwg::NwgError> {
42            use nwg::Event as E;
43
44            // Controls
45            nwg::Window::builder()
46                .size((500, 300))
47                .position((300, 300))
48                .title("Flexbox example")
49                .build(&mut data.window)?;
50
51            nwg::Button::builder()
52                .text("Btn 1")
53                .parent(&data.window)
54                .focus(true)
55                .build(&mut data.button1)?;
56
57            nwg::Button::builder()
58                .text("Btn 2")
59                .parent(&data.window)
60                .build(&mut data.button2)?;
61
62            nwg::Button::builder()
63                .text("Btn 3")
64                .parent(&data.window)
65                .build(&mut data.button3)?;
66
67            // Wrap-up
68            let ui = FlexBoxAppUi {
69                inner: Rc::new(data),
70                default_handler: Default::default(),
71            };
72
73            // Events
74            let evt_ui = Rc::downgrade(&ui.inner);
75            let handle_events = move |evt, _evt_data, handle| {
76                if let Some(evt_ui) = evt_ui.upgrade() {
77                    match evt {
78                        E::OnWindowClose => {
79                            if &handle == &evt_ui.window {
80                                FlexBoxApp::exit(&evt_ui);
81                            }
82                        }
83                        _ => {}
84                    }
85                }
86            };
87
88            *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(
89                &ui.window.handle,
90                handle_events,
91            ));
92
93            // Layout
94            use nwg::stretch::{
95                geometry::{Rect, Size},
96                style::{AlignSelf, Dimension as D, FlexDirection},
97            };
98            const FIFTY_PC: D = D::Percent(0.5);
99            const PT_10: D = D::Points(10.0);
100            const PT_5: D = D::Points(5.0);
101            const PADDING: Rect<D> = Rect {
102                start: PT_10,
103                end: PT_10,
104                top: PT_10,
105                bottom: PT_10,
106            };
107            const MARGIN: Rect<D> = Rect {
108                start: PT_5,
109                end: PT_5,
110                top: PT_5,
111                bottom: PT_5,
112            };
113
114            nwg::FlexboxLayout::builder()
115                .parent(&ui.window)
116                .flex_direction(FlexDirection::Row)
117                .padding(PADDING)
118                .child(&ui.button1)
119                .child_margin(MARGIN)
120                .child_max_size(Size {
121                    width: D::Points(200.0),
122                    height: D::Undefined,
123                })
124                .child_size(Size {
125                    width: FIFTY_PC,
126                    height: D::Auto,
127                })
128                .child(&ui.button2)
129                .child_margin(MARGIN)
130                .child_align_self(AlignSelf::FlexEnd)
131                .child_size(Size {
132                    width: D::Percent(0.25),
133                    height: FIFTY_PC,
134                })
135                .child(&ui.button3)
136                .child_margin(MARGIN)
137                .child_flex_grow(2.0)
138                .child_size(Size {
139                    width: D::Auto,
140                    height: D::Auto,
141                })
142                .build(&ui.layout)?;
143
144            return Ok(ui);
145        }
examples/partials.rs (lines 229-232)
141        fn build_ui(mut data: PartialDemo) -> Result<Rc<PartialDemoUi>, nwg::NwgError> {
142            use nwg::Event as E;
143
144            // Controls
145            nwg::Window::builder()
146                .size((500, 400))
147                .position((300, 300))
148                .title("Many UI")
149                .build(&mut data.window)?;
150
151            nwg::ListBox::builder()
152                .collection(vec!["People", "Animals", "Food"])
153                .focus(true)
154                .parent(&data.window)
155                .build(&mut data.menu)?;
156
157            nwg::Frame::builder()
158                .parent(&data.window)
159                .build(&mut data.frame1)?;
160
161            nwg::Frame::builder()
162                .flags(nwg::FrameFlags::BORDER)
163                .parent(&data.window)
164                .build(&mut data.frame2)?;
165
166            nwg::Frame::builder()
167                .flags(nwg::FrameFlags::BORDER)
168                .parent(&data.window)
169                .build(&mut data.frame3)?;
170
171            // Partials
172            PeopleUi::build_partial(&mut data.people_ui, Some(&data.frame1))?;
173            AnimalUi::build_partial(&mut data.animal_ui, Some(&data.frame2))?;
174            FoodUi::build_partial(&mut data.food_ui, Some(&data.frame3))?;
175
176            // Wrap-up
177            let ui = Rc::new(PartialDemoUi {
178                inner: data,
179                default_handler: Default::default(),
180            });
181
182            // Events
183            let mut window_handles = vec![&ui.window.handle];
184            window_handles.append(&mut ui.people_ui.handles());
185            window_handles.append(&mut ui.animal_ui.handles());
186            window_handles.append(&mut ui.food_ui.handles());
187
188            for handle in window_handles.iter() {
189                let evt_ui = ui.clone();
190                let handle_events = move |evt, evt_data, handle| {
191                    evt_ui.people_ui.process_event(evt, &evt_data, handle);
192                    evt_ui.animal_ui.process_event(evt, &evt_data, handle);
193                    evt_ui.food_ui.process_event(evt, &evt_data, handle);
194
195                    match evt {
196                        E::OnListBoxSelect => {
197                            if &handle == &evt_ui.menu {
198                                PartialDemo::change_interface(&evt_ui.inner);
199                            }
200                        }
201                        E::OnWindowClose => {
202                            if &handle == &evt_ui.window {
203                                PartialDemo::exit(&evt_ui.inner);
204                            }
205                        }
206                        E::OnButtonClick => {
207                            if &handle == &evt_ui.people_ui.save_btn
208                                || &handle == &evt_ui.animal_ui.save_btn
209                                || &handle == &evt_ui.food_ui.save_btn
210                            {
211                                PartialDemo::save(&evt_ui.inner);
212                            }
213                        }
214                        _ => {}
215                    }
216                };
217
218                ui.default_handler
219                    .borrow_mut()
220                    .push(nwg::full_bind_event_handler(handle, handle_events));
221            }
222
223            // Layout
224            use nwg::stretch::{geometry::Size, style::Dimension as D};
225
226            nwg::FlexboxLayout::builder()
227                .parent(&ui.window)
228                .child(&ui.menu)
229                .child_size(Size {
230                    width: D::Percent(0.3),
231                    height: D::Auto,
232                })
233                .child(&ui.frame1)
234                .child_size(Size {
235                    width: D::Percent(1.0),
236                    height: D::Auto,
237                })
238                .build(&ui.layout)?;
239
240            return Ok(ui);
241        }
Source

pub fn child_position(self, position: Rect<Dimension>) -> FlexboxLayoutBuilder

Set the position of the current child. Panics if child was not called before.

Source

pub fn child_margin(self, value: Rect<Dimension>) -> FlexboxLayoutBuilder

Set the margin of the current child. Panics if child was not called before.

Examples found in repository?
examples/flexbox.rs (line 119)
41        fn build_ui(mut data: FlexBoxApp) -> Result<FlexBoxAppUi, nwg::NwgError> {
42            use nwg::Event as E;
43
44            // Controls
45            nwg::Window::builder()
46                .size((500, 300))
47                .position((300, 300))
48                .title("Flexbox example")
49                .build(&mut data.window)?;
50
51            nwg::Button::builder()
52                .text("Btn 1")
53                .parent(&data.window)
54                .focus(true)
55                .build(&mut data.button1)?;
56
57            nwg::Button::builder()
58                .text("Btn 2")
59                .parent(&data.window)
60                .build(&mut data.button2)?;
61
62            nwg::Button::builder()
63                .text("Btn 3")
64                .parent(&data.window)
65                .build(&mut data.button3)?;
66
67            // Wrap-up
68            let ui = FlexBoxAppUi {
69                inner: Rc::new(data),
70                default_handler: Default::default(),
71            };
72
73            // Events
74            let evt_ui = Rc::downgrade(&ui.inner);
75            let handle_events = move |evt, _evt_data, handle| {
76                if let Some(evt_ui) = evt_ui.upgrade() {
77                    match evt {
78                        E::OnWindowClose => {
79                            if &handle == &evt_ui.window {
80                                FlexBoxApp::exit(&evt_ui);
81                            }
82                        }
83                        _ => {}
84                    }
85                }
86            };
87
88            *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(
89                &ui.window.handle,
90                handle_events,
91            ));
92
93            // Layout
94            use nwg::stretch::{
95                geometry::{Rect, Size},
96                style::{AlignSelf, Dimension as D, FlexDirection},
97            };
98            const FIFTY_PC: D = D::Percent(0.5);
99            const PT_10: D = D::Points(10.0);
100            const PT_5: D = D::Points(5.0);
101            const PADDING: Rect<D> = Rect {
102                start: PT_10,
103                end: PT_10,
104                top: PT_10,
105                bottom: PT_10,
106            };
107            const MARGIN: Rect<D> = Rect {
108                start: PT_5,
109                end: PT_5,
110                top: PT_5,
111                bottom: PT_5,
112            };
113
114            nwg::FlexboxLayout::builder()
115                .parent(&ui.window)
116                .flex_direction(FlexDirection::Row)
117                .padding(PADDING)
118                .child(&ui.button1)
119                .child_margin(MARGIN)
120                .child_max_size(Size {
121                    width: D::Points(200.0),
122                    height: D::Undefined,
123                })
124                .child_size(Size {
125                    width: FIFTY_PC,
126                    height: D::Auto,
127                })
128                .child(&ui.button2)
129                .child_margin(MARGIN)
130                .child_align_self(AlignSelf::FlexEnd)
131                .child_size(Size {
132                    width: D::Percent(0.25),
133                    height: FIFTY_PC,
134                })
135                .child(&ui.button3)
136                .child_margin(MARGIN)
137                .child_flex_grow(2.0)
138                .child_size(Size {
139                    width: D::Auto,
140                    height: D::Auto,
141                })
142                .build(&ui.layout)?;
143
144            return Ok(ui);
145        }
Source

pub fn child_min_size(self, value: Size<Dimension>) -> FlexboxLayoutBuilder

Set the min size of the current child. Panics if child was not called before.

Source

pub fn child_max_size(self, value: Size<Dimension>) -> FlexboxLayoutBuilder

Set the max size of the current child. Panics if child was not called before.

Examples found in repository?
examples/flexbox.rs (lines 120-123)
41        fn build_ui(mut data: FlexBoxApp) -> Result<FlexBoxAppUi, nwg::NwgError> {
42            use nwg::Event as E;
43
44            // Controls
45            nwg::Window::builder()
46                .size((500, 300))
47                .position((300, 300))
48                .title("Flexbox example")
49                .build(&mut data.window)?;
50
51            nwg::Button::builder()
52                .text("Btn 1")
53                .parent(&data.window)
54                .focus(true)
55                .build(&mut data.button1)?;
56
57            nwg::Button::builder()
58                .text("Btn 2")
59                .parent(&data.window)
60                .build(&mut data.button2)?;
61
62            nwg::Button::builder()
63                .text("Btn 3")
64                .parent(&data.window)
65                .build(&mut data.button3)?;
66
67            // Wrap-up
68            let ui = FlexBoxAppUi {
69                inner: Rc::new(data),
70                default_handler: Default::default(),
71            };
72
73            // Events
74            let evt_ui = Rc::downgrade(&ui.inner);
75            let handle_events = move |evt, _evt_data, handle| {
76                if let Some(evt_ui) = evt_ui.upgrade() {
77                    match evt {
78                        E::OnWindowClose => {
79                            if &handle == &evt_ui.window {
80                                FlexBoxApp::exit(&evt_ui);
81                            }
82                        }
83                        _ => {}
84                    }
85                }
86            };
87
88            *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(
89                &ui.window.handle,
90                handle_events,
91            ));
92
93            // Layout
94            use nwg::stretch::{
95                geometry::{Rect, Size},
96                style::{AlignSelf, Dimension as D, FlexDirection},
97            };
98            const FIFTY_PC: D = D::Percent(0.5);
99            const PT_10: D = D::Points(10.0);
100            const PT_5: D = D::Points(5.0);
101            const PADDING: Rect<D> = Rect {
102                start: PT_10,
103                end: PT_10,
104                top: PT_10,
105                bottom: PT_10,
106            };
107            const MARGIN: Rect<D> = Rect {
108                start: PT_5,
109                end: PT_5,
110                top: PT_5,
111                bottom: PT_5,
112            };
113
114            nwg::FlexboxLayout::builder()
115                .parent(&ui.window)
116                .flex_direction(FlexDirection::Row)
117                .padding(PADDING)
118                .child(&ui.button1)
119                .child_margin(MARGIN)
120                .child_max_size(Size {
121                    width: D::Points(200.0),
122                    height: D::Undefined,
123                })
124                .child_size(Size {
125                    width: FIFTY_PC,
126                    height: D::Auto,
127                })
128                .child(&ui.button2)
129                .child_margin(MARGIN)
130                .child_align_self(AlignSelf::FlexEnd)
131                .child_size(Size {
132                    width: D::Percent(0.25),
133                    height: FIFTY_PC,
134                })
135                .child(&ui.button3)
136                .child_margin(MARGIN)
137                .child_flex_grow(2.0)
138                .child_size(Size {
139                    width: D::Auto,
140                    height: D::Auto,
141                })
142                .build(&ui.layout)?;
143
144            return Ok(ui);
145        }
Source

pub fn child_flex_grow(self, value: f32) -> FlexboxLayoutBuilder

Panics if child was not called before.

Examples found in repository?
examples/flexbox_sub_layout.rs (line 111)
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        }
More examples
Hide additional examples
examples/flexbox.rs (line 137)
41        fn build_ui(mut data: FlexBoxApp) -> Result<FlexBoxAppUi, nwg::NwgError> {
42            use nwg::Event as E;
43
44            // Controls
45            nwg::Window::builder()
46                .size((500, 300))
47                .position((300, 300))
48                .title("Flexbox example")
49                .build(&mut data.window)?;
50
51            nwg::Button::builder()
52                .text("Btn 1")
53                .parent(&data.window)
54                .focus(true)
55                .build(&mut data.button1)?;
56
57            nwg::Button::builder()
58                .text("Btn 2")
59                .parent(&data.window)
60                .build(&mut data.button2)?;
61
62            nwg::Button::builder()
63                .text("Btn 3")
64                .parent(&data.window)
65                .build(&mut data.button3)?;
66
67            // Wrap-up
68            let ui = FlexBoxAppUi {
69                inner: Rc::new(data),
70                default_handler: Default::default(),
71            };
72
73            // Events
74            let evt_ui = Rc::downgrade(&ui.inner);
75            let handle_events = move |evt, _evt_data, handle| {
76                if let Some(evt_ui) = evt_ui.upgrade() {
77                    match evt {
78                        E::OnWindowClose => {
79                            if &handle == &evt_ui.window {
80                                FlexBoxApp::exit(&evt_ui);
81                            }
82                        }
83                        _ => {}
84                    }
85                }
86            };
87
88            *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(
89                &ui.window.handle,
90                handle_events,
91            ));
92
93            // Layout
94            use nwg::stretch::{
95                geometry::{Rect, Size},
96                style::{AlignSelf, Dimension as D, FlexDirection},
97            };
98            const FIFTY_PC: D = D::Percent(0.5);
99            const PT_10: D = D::Points(10.0);
100            const PT_5: D = D::Points(5.0);
101            const PADDING: Rect<D> = Rect {
102                start: PT_10,
103                end: PT_10,
104                top: PT_10,
105                bottom: PT_10,
106            };
107            const MARGIN: Rect<D> = Rect {
108                start: PT_5,
109                end: PT_5,
110                top: PT_5,
111                bottom: PT_5,
112            };
113
114            nwg::FlexboxLayout::builder()
115                .parent(&ui.window)
116                .flex_direction(FlexDirection::Row)
117                .padding(PADDING)
118                .child(&ui.button1)
119                .child_margin(MARGIN)
120                .child_max_size(Size {
121                    width: D::Points(200.0),
122                    height: D::Undefined,
123                })
124                .child_size(Size {
125                    width: FIFTY_PC,
126                    height: D::Auto,
127                })
128                .child(&ui.button2)
129                .child_margin(MARGIN)
130                .child_align_self(AlignSelf::FlexEnd)
131                .child_size(Size {
132                    width: D::Percent(0.25),
133                    height: FIFTY_PC,
134                })
135                .child(&ui.button3)
136                .child_margin(MARGIN)
137                .child_flex_grow(2.0)
138                .child_size(Size {
139                    width: D::Auto,
140                    height: D::Auto,
141                })
142                .build(&ui.layout)?;
143
144            return Ok(ui);
145        }
Source

pub fn child_flex_shrink(self, value: f32) -> FlexboxLayoutBuilder

Panics if child was not called before.

Source

pub fn child_flex_basis(self, value: Dimension) -> FlexboxLayoutBuilder

Panics if child was not called before.

Source

pub fn child_align_self(self, value: AlignSelf) -> FlexboxLayoutBuilder

Panics if child was not called before.

Examples found in repository?
examples/flexbox.rs (line 130)
41        fn build_ui(mut data: FlexBoxApp) -> Result<FlexBoxAppUi, nwg::NwgError> {
42            use nwg::Event as E;
43
44            // Controls
45            nwg::Window::builder()
46                .size((500, 300))
47                .position((300, 300))
48                .title("Flexbox example")
49                .build(&mut data.window)?;
50
51            nwg::Button::builder()
52                .text("Btn 1")
53                .parent(&data.window)
54                .focus(true)
55                .build(&mut data.button1)?;
56
57            nwg::Button::builder()
58                .text("Btn 2")
59                .parent(&data.window)
60                .build(&mut data.button2)?;
61
62            nwg::Button::builder()
63                .text("Btn 3")
64                .parent(&data.window)
65                .build(&mut data.button3)?;
66
67            // Wrap-up
68            let ui = FlexBoxAppUi {
69                inner: Rc::new(data),
70                default_handler: Default::default(),
71            };
72
73            // Events
74            let evt_ui = Rc::downgrade(&ui.inner);
75            let handle_events = move |evt, _evt_data, handle| {
76                if let Some(evt_ui) = evt_ui.upgrade() {
77                    match evt {
78                        E::OnWindowClose => {
79                            if &handle == &evt_ui.window {
80                                FlexBoxApp::exit(&evt_ui);
81                            }
82                        }
83                        _ => {}
84                    }
85                }
86            };
87
88            *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(
89                &ui.window.handle,
90                handle_events,
91            ));
92
93            // Layout
94            use nwg::stretch::{
95                geometry::{Rect, Size},
96                style::{AlignSelf, Dimension as D, FlexDirection},
97            };
98            const FIFTY_PC: D = D::Percent(0.5);
99            const PT_10: D = D::Points(10.0);
100            const PT_5: D = D::Points(5.0);
101            const PADDING: Rect<D> = Rect {
102                start: PT_10,
103                end: PT_10,
104                top: PT_10,
105                bottom: PT_10,
106            };
107            const MARGIN: Rect<D> = Rect {
108                start: PT_5,
109                end: PT_5,
110                top: PT_5,
111                bottom: PT_5,
112            };
113
114            nwg::FlexboxLayout::builder()
115                .parent(&ui.window)
116                .flex_direction(FlexDirection::Row)
117                .padding(PADDING)
118                .child(&ui.button1)
119                .child_margin(MARGIN)
120                .child_max_size(Size {
121                    width: D::Points(200.0),
122                    height: D::Undefined,
123                })
124                .child_size(Size {
125                    width: FIFTY_PC,
126                    height: D::Auto,
127                })
128                .child(&ui.button2)
129                .child_margin(MARGIN)
130                .child_align_self(AlignSelf::FlexEnd)
131                .child_size(Size {
132                    width: D::Percent(0.25),
133                    height: FIFTY_PC,
134                })
135                .child(&ui.button3)
136                .child_margin(MARGIN)
137                .child_flex_grow(2.0)
138                .child_size(Size {
139                    width: D::Auto,
140                    height: D::Auto,
141                })
142                .build(&ui.layout)?;
143
144            return Ok(ui);
145        }
Source

pub fn style(self, style: Style) -> FlexboxLayoutBuilder

Directly set the style parameter of the current child. Panics if child was not called before.

If defining style is too verbose, other method such as size can be used.

Source

pub fn build(self, layout: &FlexboxLayout) -> Result<(), NwgError>

Build the layout object and bind the callback.

Examples found in repository?
examples/flexbox_sub_layout.rs (line 132)
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        }
More examples
Hide additional examples
examples/flexbox.rs (line 142)
41        fn build_ui(mut data: FlexBoxApp) -> Result<FlexBoxAppUi, nwg::NwgError> {
42            use nwg::Event as E;
43
44            // Controls
45            nwg::Window::builder()
46                .size((500, 300))
47                .position((300, 300))
48                .title("Flexbox example")
49                .build(&mut data.window)?;
50
51            nwg::Button::builder()
52                .text("Btn 1")
53                .parent(&data.window)
54                .focus(true)
55                .build(&mut data.button1)?;
56
57            nwg::Button::builder()
58                .text("Btn 2")
59                .parent(&data.window)
60                .build(&mut data.button2)?;
61
62            nwg::Button::builder()
63                .text("Btn 3")
64                .parent(&data.window)
65                .build(&mut data.button3)?;
66
67            // Wrap-up
68            let ui = FlexBoxAppUi {
69                inner: Rc::new(data),
70                default_handler: Default::default(),
71            };
72
73            // Events
74            let evt_ui = Rc::downgrade(&ui.inner);
75            let handle_events = move |evt, _evt_data, handle| {
76                if let Some(evt_ui) = evt_ui.upgrade() {
77                    match evt {
78                        E::OnWindowClose => {
79                            if &handle == &evt_ui.window {
80                                FlexBoxApp::exit(&evt_ui);
81                            }
82                        }
83                        _ => {}
84                    }
85                }
86            };
87
88            *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(
89                &ui.window.handle,
90                handle_events,
91            ));
92
93            // Layout
94            use nwg::stretch::{
95                geometry::{Rect, Size},
96                style::{AlignSelf, Dimension as D, FlexDirection},
97            };
98            const FIFTY_PC: D = D::Percent(0.5);
99            const PT_10: D = D::Points(10.0);
100            const PT_5: D = D::Points(5.0);
101            const PADDING: Rect<D> = Rect {
102                start: PT_10,
103                end: PT_10,
104                top: PT_10,
105                bottom: PT_10,
106            };
107            const MARGIN: Rect<D> = Rect {
108                start: PT_5,
109                end: PT_5,
110                top: PT_5,
111                bottom: PT_5,
112            };
113
114            nwg::FlexboxLayout::builder()
115                .parent(&ui.window)
116                .flex_direction(FlexDirection::Row)
117                .padding(PADDING)
118                .child(&ui.button1)
119                .child_margin(MARGIN)
120                .child_max_size(Size {
121                    width: D::Points(200.0),
122                    height: D::Undefined,
123                })
124                .child_size(Size {
125                    width: FIFTY_PC,
126                    height: D::Auto,
127                })
128                .child(&ui.button2)
129                .child_margin(MARGIN)
130                .child_align_self(AlignSelf::FlexEnd)
131                .child_size(Size {
132                    width: D::Percent(0.25),
133                    height: FIFTY_PC,
134                })
135                .child(&ui.button3)
136                .child_margin(MARGIN)
137                .child_flex_grow(2.0)
138                .child_size(Size {
139                    width: D::Auto,
140                    height: D::Auto,
141                })
142                .build(&ui.layout)?;
143
144            return Ok(ui);
145        }
examples/partials.rs (line 238)
141        fn build_ui(mut data: PartialDemo) -> Result<Rc<PartialDemoUi>, nwg::NwgError> {
142            use nwg::Event as E;
143
144            // Controls
145            nwg::Window::builder()
146                .size((500, 400))
147                .position((300, 300))
148                .title("Many UI")
149                .build(&mut data.window)?;
150
151            nwg::ListBox::builder()
152                .collection(vec!["People", "Animals", "Food"])
153                .focus(true)
154                .parent(&data.window)
155                .build(&mut data.menu)?;
156
157            nwg::Frame::builder()
158                .parent(&data.window)
159                .build(&mut data.frame1)?;
160
161            nwg::Frame::builder()
162                .flags(nwg::FrameFlags::BORDER)
163                .parent(&data.window)
164                .build(&mut data.frame2)?;
165
166            nwg::Frame::builder()
167                .flags(nwg::FrameFlags::BORDER)
168                .parent(&data.window)
169                .build(&mut data.frame3)?;
170
171            // Partials
172            PeopleUi::build_partial(&mut data.people_ui, Some(&data.frame1))?;
173            AnimalUi::build_partial(&mut data.animal_ui, Some(&data.frame2))?;
174            FoodUi::build_partial(&mut data.food_ui, Some(&data.frame3))?;
175
176            // Wrap-up
177            let ui = Rc::new(PartialDemoUi {
178                inner: data,
179                default_handler: Default::default(),
180            });
181
182            // Events
183            let mut window_handles = vec![&ui.window.handle];
184            window_handles.append(&mut ui.people_ui.handles());
185            window_handles.append(&mut ui.animal_ui.handles());
186            window_handles.append(&mut ui.food_ui.handles());
187
188            for handle in window_handles.iter() {
189                let evt_ui = ui.clone();
190                let handle_events = move |evt, evt_data, handle| {
191                    evt_ui.people_ui.process_event(evt, &evt_data, handle);
192                    evt_ui.animal_ui.process_event(evt, &evt_data, handle);
193                    evt_ui.food_ui.process_event(evt, &evt_data, handle);
194
195                    match evt {
196                        E::OnListBoxSelect => {
197                            if &handle == &evt_ui.menu {
198                                PartialDemo::change_interface(&evt_ui.inner);
199                            }
200                        }
201                        E::OnWindowClose => {
202                            if &handle == &evt_ui.window {
203                                PartialDemo::exit(&evt_ui.inner);
204                            }
205                        }
206                        E::OnButtonClick => {
207                            if &handle == &evt_ui.people_ui.save_btn
208                                || &handle == &evt_ui.animal_ui.save_btn
209                                || &handle == &evt_ui.food_ui.save_btn
210                            {
211                                PartialDemo::save(&evt_ui.inner);
212                            }
213                        }
214                        _ => {}
215                    }
216                };
217
218                ui.default_handler
219                    .borrow_mut()
220                    .push(nwg::full_bind_event_handler(handle, handle_events));
221            }
222
223            // Layout
224            use nwg::stretch::{geometry::Size, style::Dimension as D};
225
226            nwg::FlexboxLayout::builder()
227                .parent(&ui.window)
228                .child(&ui.menu)
229                .child_size(Size {
230                    width: D::Percent(0.3),
231                    height: D::Auto,
232                })
233                .child(&ui.frame1)
234                .child_size(Size {
235                    width: D::Percent(1.0),
236                    height: D::Auto,
237                })
238                .build(&ui.layout)?;
239
240            return Ok(ui);
241        }
Source

pub fn build_partial(self, layout: &FlexboxLayout) -> Result<(), NwgError>

Build a “partial” layout object - this layout has no direct callback and needs to be added to a parent layout using child_layout

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

Auto Trait Implementations§

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.