pub struct GridLayoutItem {
pub col: u32,
pub row: u32,
pub col_span: u32,
pub row_span: u32,
/* private fields */
}
Expand description
A control item in a GridLayout
Fields§
§col: u32
The column position of the control in the layout
row: u32
The row position of the control in the layout
col_span: u32
The number column this item should span. Should be 1 for single column item.
row_span: u32
The number row this item should span. Should be 1 for single row item.
Implementations§
Source§impl GridLayoutItem
impl GridLayoutItem
Sourcepub fn new<W: Into<ControlHandle>>(
c: W,
col: u32,
row: u32,
col_span: u32,
row_span: u32,
) -> GridLayoutItem
pub fn new<W: Into<ControlHandle>>( c: W, col: u32, row: u32, col_span: u32, row_span: u32, ) -> GridLayoutItem
Initialize a new grid layout item
Examples found in repository?
examples/basic_barebone.rs (line 45)
12fn main() {
13 nwg::init().expect("Failed to init Native Windows GUI");
14 nwg::Font::set_global_family("Segoe UI").expect("Failed to set default font");
15
16 let mut window = Default::default();
17 let mut name_edit = Default::default();
18 let mut hello_button = Default::default();
19 let layout = Default::default();
20
21 nwg::Window::builder()
22 .size((300, 115))
23 .position((300, 300))
24 .title("Basic example")
25 .build(&mut window)
26 .unwrap();
27
28 nwg::TextInput::builder()
29 .text("Heisenberg")
30 .focus(true)
31 .parent(&window)
32 .build(&mut name_edit)
33 .unwrap();
34
35 nwg::Button::builder()
36 .text("Say my name")
37 .parent(&window)
38 .build(&mut hello_button)
39 .unwrap();
40
41 nwg::GridLayout::builder()
42 .parent(&window)
43 .spacing(1)
44 .child(0, 0, &name_edit)
45 .child_item(nwg::GridLayoutItem::new(&hello_button, 0, 1, 1, 2))
46 .build(&layout)
47 .unwrap();
48
49 let window = Rc::new(window);
50 let events_window = window.clone();
51
52 let handler = nwg::full_bind_event_handler(&window.handle, move |evt, _evt_data, handle| {
53 use nwg::Event as E;
54
55 match evt {
56 E::OnWindowClose =>
57 if &handle == &events_window as &nwg::Window {
58 nwg::modal_info_message(&events_window.handle, "Goodbye", &format!("Goodbye {}", name_edit.text()));
59 nwg::stop_thread_dispatch();
60 },
61 E::OnButtonClick =>
62 if &handle == &hello_button {
63 nwg::modal_info_message(&events_window.handle, "Hello", &format!("Hello {}", name_edit.text()));
64 },
65 _ => {}
66 }
67 });
68
69 nwg::dispatch_thread_events();
70 nwg::unbind_event_handler(&handler);
71}
More examples
examples/basic_layout.rs (line 100)
47 fn build_ui(mut data: BasicApp) -> Result<BasicAppUi, nwg::NwgError> {
48 use nwg::Event as E;
49
50 // Controls
51 nwg::Window::builder()
52 .flags(nwg::WindowFlags::WINDOW | nwg::WindowFlags::VISIBLE)
53 .size((300, 115))
54 .position((300, 300))
55 .title("Basic example")
56 .build(&mut data.window)?;
57
58 nwg::TextInput::builder()
59 .text("Heisenberg")
60 .parent(&data.window)
61 .focus(true)
62 .build(&mut data.name_edit)?;
63
64 nwg::Button::builder()
65 .text("Say my name")
66 .parent(&data.window)
67 .build(&mut data.hello_button)?;
68
69 // Wrap-up
70 let ui = BasicAppUi {
71 inner: Rc::new(data),
72 default_handler: Default::default(),
73 };
74
75 // Events
76 let evt_ui = Rc::downgrade(&ui.inner);
77 let handle_events = move |evt, _evt_data, handle| {
78 if let Some(evt_ui) = evt_ui.upgrade() {
79 match evt {
80 E::OnButtonClick =>
81 if &handle == &evt_ui.hello_button {
82 BasicApp::say_hello(&evt_ui);
83 },
84 E::OnWindowClose =>
85 if &handle == &evt_ui.window {
86 BasicApp::say_goodbye(&evt_ui);
87 },
88 _ => {}
89 }
90 }
91 };
92
93 *ui.default_handler.borrow_mut() = Some(nwg::full_bind_event_handler(&ui.window.handle, handle_events));
94
95 // Layouts
96 nwg::GridLayout::builder()
97 .parent(&ui.window)
98 .spacing(1)
99 .child(0, 0, &ui.name_edit)
100 .child_item(nwg::GridLayoutItem::new(&ui.hello_button, 0, 1, 1, 2))
101 .build(&ui.layout)?;
102
103 return Ok(ui);
104 }
examples/message_bank.rs (line 150)
88 fn build_ui(mut data: MessageBank) -> Result<MessageBankUi, nwg::NwgError> {
89 use nwg::Event as E;
90
91 // Controls
92 nwg::Window::builder()
93 .flags(nwg::WindowFlags::MAIN_WINDOW | nwg::WindowFlags::VISIBLE)
94 .size((400, 300))
95 .position((800, 300))
96 .title("My message bank")
97 .build(&mut data.window)?;
98
99 nwg::TextInput::builder()
100 .text("Hello World!")
101 .focus(true)
102 .parent(&data.window)
103 .build(&mut data.message_content)?;
104
105 nwg::Button::builder()
106 .text("Save")
107 .parent(&data.window)
108 .build(&mut data.add_message_btn)?;
109
110 nwg::TextInput::builder()
111 .text("Title")
112 .parent(&data.window)
113 .build(&mut data.message_title)?;
114
115 // Wrap-up
116 let ui = MessageBankUi {
117 inner: Rc::new(data),
118 default_handler: Default::default(),
119 };
120
121 // Events
122 let window_handles = [&ui.window.handle];
123
124 for handle in window_handles.iter() {
125 let evt_ui = Rc::downgrade(&ui.inner);
126 let handle_events = move |evt, _evt_data, handle| {
127 if let Some(evt_ui) = evt_ui.upgrade() {
128 match evt {
129 E::OnButtonClick => {
130 if &handle == &evt_ui.add_message_btn { MessageBank::add_message(&evt_ui); }
131 },
132 E::OnWindowClose => {
133 if &handle == &evt_ui.window { MessageBank::exit(&evt_ui); }
134 },
135 _ => {}
136 }
137 }
138 };
139
140 ui.default_handler.borrow_mut().push(
141 nwg::full_bind_event_handler(handle, handle_events)
142 );
143 }
144
145 // Layout
146 nwg::GridLayout::builder()
147 .parent(&ui.window)
148 .max_row(Some(6))
149 .child(0, 0, &ui.add_message_btn)
150 .child_item(nwg::GridLayoutItem::new(&ui.message_title, 1, 0, 2, 1))
151 .child_item(nwg::GridLayoutItem::new(&ui.message_content, 3, 0, 3, 1))
152 .build(&ui.layout)?;
153
154 return Ok(ui);
155 }
examples/calculator.rs (line 236)
143 fn build_ui(mut data: Calculator) -> Result<CalculatorUi, nwg::NwgError> {
144 use nwg::Event as E;
145
146 // Controls
147 nwg::Window::builder()
148 .size((300, 150))
149 .position((300, 300))
150 .title("Calculator")
151 .build(&mut data.window)?;
152
153 nwg::TextInput::builder()
154 .text("")
155 .align(nwg::HTextAlign::Right)
156 .readonly(true)
157 .parent(&data.window)
158 .build(&mut data.input)?;
159
160 nwg::Button::builder()
161 .text("1")
162 .parent(&data.window)
163 .focus(true)
164 .build(&mut data.btn1)?;
165
166 nwg::Button::builder().text("2").parent(&data.window).build(&mut data.btn2)?;
167 nwg::Button::builder().text("3").parent(&data.window).build(&mut data.btn3)?;
168 nwg::Button::builder().text("4").parent(&data.window).build(&mut data.btn4)?;
169 nwg::Button::builder().text("5").parent(&data.window).build(&mut data.btn5)?;
170 nwg::Button::builder().text("6").parent(&data.window).build(&mut data.btn6)?;
171 nwg::Button::builder().text("7").parent(&data.window).build(&mut data.btn7)?;
172 nwg::Button::builder().text("8").parent(&data.window).build(&mut data.btn8)?;
173 nwg::Button::builder().text("9").parent(&data.window).build(&mut data.btn9)?;
174 nwg::Button::builder().text("0").parent(&data.window).build(&mut data.btn0)?;
175
176 nwg::Button::builder().text("+").parent(&data.window).build(&mut data.btn_plus)?;
177 nwg::Button::builder().text("-").parent(&data.window).build(&mut data.btn_minus)?;
178 nwg::Button::builder().text("*").parent(&data.window).build(&mut data.btn_mult)?;
179 nwg::Button::builder().text("/").parent(&data.window).build(&mut data.btn_divide)?;
180 nwg::Button::builder().text("Clear").parent(&data.window).build(&mut data.btn_clear)?;
181 nwg::Button::builder().text("=").parent(&data.window).build(&mut data.btn_process)?;
182
183
184 // Wrap-up
185 let ui = CalculatorUi {
186 inner: Rc::new(data),
187 default_handler: Default::default()
188 };
189
190 // Events
191 let window_handles = [&ui.window.handle];
192 for handle in window_handles.iter() {
193 let evt_ui = Rc::downgrade(&ui.inner);
194 let handle_events = move |evt, _evt_data, handle| {
195 if let Some(evt_ui) = evt_ui.upgrade() {
196 match evt {
197 E::OnButtonClick =>
198 if &handle == &evt_ui.btn0 { Calculator::number(&evt_ui, &evt_ui.btn0); }
199 else if &handle == &evt_ui.btn1 { Calculator::number(&evt_ui, &evt_ui.btn1); }
200 else if &handle == &evt_ui.btn2 { Calculator::number(&evt_ui, &evt_ui.btn2); }
201 else if &handle == &evt_ui.btn3 { Calculator::number(&evt_ui, &evt_ui.btn3); }
202 else if &handle == &evt_ui.btn4 { Calculator::number(&evt_ui, &evt_ui.btn4); }
203 else if &handle == &evt_ui.btn5 { Calculator::number(&evt_ui, &evt_ui.btn5); }
204 else if &handle == &evt_ui.btn6 { Calculator::number(&evt_ui, &evt_ui.btn6); }
205 else if &handle == &evt_ui.btn7 { Calculator::number(&evt_ui, &evt_ui.btn7); }
206 else if &handle == &evt_ui.btn8 { Calculator::number(&evt_ui, &evt_ui.btn8); }
207 else if &handle == &evt_ui.btn9 { Calculator::number(&evt_ui, &evt_ui.btn9); }
208
209 else if &handle == &evt_ui.btn_plus { Calculator::number(&evt_ui, &evt_ui.btn_plus); }
210 else if &handle == &evt_ui.btn_minus { Calculator::number(&evt_ui, &evt_ui.btn_minus); }
211 else if &handle == &evt_ui.btn_mult { Calculator::number(&evt_ui, &evt_ui.btn_mult); }
212 else if &handle == &evt_ui.btn_divide { Calculator::number(&evt_ui, &evt_ui.btn_divide); }
213
214 else if &handle == &evt_ui.btn_clear { Calculator::clear(&evt_ui); }
215
216 else if &handle == &evt_ui.btn_process { Calculator::compute(&evt_ui); }
217 E::OnWindowClose =>
218 if &handle == &evt_ui.window {
219 Calculator::exit(&evt_ui);
220 },
221 _ => {}
222 }
223 }
224 };
225
226 ui.default_handler.borrow_mut().push(
227 nwg::full_bind_event_handler(handle, handle_events)
228 );
229 }
230
231 // Layouts
232 nwg::GridLayout::builder()
233 .parent(&ui.window)
234 .spacing(2)
235 .min_size([150, 140])
236 .child_item(nwg::GridLayoutItem::new(&ui.input, 0, 0, 5, 1))
237 .child(0, 1, &ui.btn1)
238 .child(1, 1, &ui.btn2)
239 .child(2, 1, &ui.btn3)
240 .child(0, 2, &ui.btn4)
241 .child(1, 2, &ui.btn5)
242 .child(2, 2, &ui.btn6)
243 .child(0, 3, &ui.btn7)
244 .child(1, 3, &ui.btn8)
245 .child(2, 3, &ui.btn9)
246 .child(3, 1, &ui.btn_plus)
247 .child(4, 1, &ui.btn_minus)
248 .child(3, 2, &ui.btn_mult)
249 .child(4, 2, &ui.btn_divide)
250 .child_item(nwg::GridLayoutItem::new(&ui.btn_clear, 3, 3, 2, 1))
251 .child_item(nwg::GridLayoutItem::new(&ui.btn_process, 3, 4, 2, 1))
252 .child_item(nwg::GridLayoutItem::new(&ui.btn0, 0, 4, 3, 1))
253 .build(&ui.layout)?;
254
255 return Ok(ui);
256 }
Trait Implementations§
Auto Trait Implementations§
impl Freeze for GridLayoutItem
impl RefUnwindSafe for GridLayoutItem
impl !Send for GridLayoutItem
impl !Sync for GridLayoutItem
impl Unpin for GridLayoutItem
impl UnwindSafe for GridLayoutItem
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more