pub struct Frame {
pub handle: ControlHandle,
}Expand description
A frame is a rectangle containing children controls. Frame is implemented as a custom control.
Requires the frame feature.
Builder parameters:
parent: Required. The frame parent container.size: The frame size.position: The frame position.enabled: If the frame children can be used by the user.flags: A combination of the FrameFlags values.ex_flags: A combination of win32 window extended flags. Unlikeflags, ex_flags must be used straight from winapi
Control events:
MousePress(_): Generic mouse press events on the buttonOnMouseMove: Generic mouse mouse eventOnMouseWheel: Generic mouse wheel event
Fields§
§handle: ControlHandleImplementations§
Source§impl Frame
impl Frame
Sourcepub fn builder() -> FrameBuilder
pub fn builder() -> FrameBuilder
Examples found in repository?
examples/partials.rs (line 157)
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 }Sourcepub fn enabled(&self) -> bool
pub fn enabled(&self) -> bool
Returns true if the control user can interact with the control, return false otherwise
Sourcepub fn set_enabled(&self, v: bool)
pub fn set_enabled(&self, v: bool)
Enable or disable the control
Sourcepub fn visible(&self) -> bool
pub fn visible(&self) -> bool
Returns true if the control is visible to the user. Will return true even if the control is outside of the parent client view (ex: at the position (10000, 10000))
Sourcepub fn set_visible(&self, v: bool)
pub fn set_visible(&self, v: bool)
Show or hide the control to the user
Examples found in repository?
examples/partials.rs (line 27)
26 fn change_interface(&self) {
27 self.frame1.set_visible(false);
28 self.frame2.set_visible(false);
29 self.frame3.set_visible(false);
30
31 let layout = &self.layout;
32 if layout.has_child(&self.frame1) {
33 layout.remove_child(&self.frame1);
34 }
35 if layout.has_child(&self.frame2) {
36 layout.remove_child(&self.frame2);
37 }
38 if layout.has_child(&self.frame3) {
39 layout.remove_child(&self.frame3);
40 }
41
42 use nwg::stretch::{
43 geometry::Size,
44 style::{Dimension as D, Style},
45 };
46 let mut style = Style::default();
47 style.size = Size {
48 width: D::Percent(1.0),
49 height: D::Auto,
50 };
51
52 match self.menu.selection() {
53 None | Some(0) => {
54 layout.add_child(&self.frame1, style).unwrap();
55 self.frame1.set_visible(true);
56 }
57 Some(1) => {
58 layout.add_child(&self.frame2, style).unwrap();
59 self.frame2.set_visible(true);
60 }
61 Some(2) => {
62 layout.add_child(&self.frame3, style).unwrap();
63 self.frame3.set_visible(true);
64 }
65 Some(_) => unreachable!(),
66 }
67 }Sourcepub fn set_position(&self, x: i32, y: i32)
pub fn set_position(&self, x: i32, y: i32)
Sets the position of the button in the parent window
Sourcepub fn class_name(&self) -> &'static str
pub fn class_name(&self) -> &'static str
Winapi class name used during control creation
Sourcepub fn forced_flags(&self) -> u32
pub fn forced_flags(&self) -> u32
Winapi flags required by the control
Trait Implementations§
impl Eq for Frame
Source§impl From<&Frame> for ControlHandle
impl From<&Frame> for ControlHandle
Source§impl From<&mut Frame> for ControlHandle
impl From<&mut Frame> for ControlHandle
Source§impl PartialEq<ControlHandle> for Frame
impl PartialEq<ControlHandle> for Frame
Source§fn eq(&self, other: &ControlHandle) -> bool
fn eq(&self, other: &ControlHandle) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl PartialEq<Frame> for ControlHandle
impl PartialEq<Frame> for ControlHandle
impl StructuralPartialEq for Frame
Auto Trait Implementations§
impl !Send for Frame
impl !Sync for Frame
impl Freeze for Frame
impl RefUnwindSafe for Frame
impl Unpin for Frame
impl UnsafeUnpin for Frame
impl UnwindSafe for Frame
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