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: ControlHandle
Implementations§
Source§impl Frame
impl Frame
Sourcepub fn builder() -> FrameBuilder
pub fn builder() -> FrameBuilder
Examples found in repository?
examples/partials.rs (line 148)
132 fn build_ui(mut data: PartialDemo) -> Result<Rc<PartialDemoUi>, nwg::NwgError> {
133 use nwg::Event as E;
134
135 // Controls
136 nwg::Window::builder()
137 .size((500, 400))
138 .position((300, 300))
139 .title("Many UI")
140 .build(&mut data.window)?;
141
142 nwg::ListBox::builder()
143 .collection(vec!["People", "Animals", "Food"])
144 .focus(true)
145 .parent(&data.window)
146 .build(&mut data.menu)?;
147
148 nwg::Frame::builder()
149 .parent(&data.window)
150 .build(&mut data.frame1)?;
151
152 nwg::Frame::builder()
153 .flags(nwg::FrameFlags::BORDER)
154 .parent(&data.window)
155 .build(&mut data.frame2)?;
156
157 nwg::Frame::builder()
158 .flags(nwg::FrameFlags::BORDER)
159 .parent(&data.window)
160 .build(&mut data.frame3)?;
161
162 // Partials
163 PeopleUi::build_partial(&mut data.people_ui, Some(&data.frame1))?;
164 AnimalUi::build_partial(&mut data.animal_ui, Some(&data.frame2))?;
165 FoodUi::build_partial(&mut data.food_ui, Some(&data.frame3))?;
166
167 // Wrap-up
168 let ui = Rc::new(PartialDemoUi {
169 inner: data,
170 default_handler: Default::default()
171 });
172
173 // Events
174 let mut window_handles = vec![&ui.window.handle];
175 window_handles.append(&mut ui.people_ui.handles());
176 window_handles.append(&mut ui.animal_ui.handles());
177 window_handles.append(&mut ui.food_ui.handles());
178
179 for handle in window_handles.iter() {
180 let evt_ui = ui.clone();
181 let handle_events = move |evt, evt_data, handle| {
182 evt_ui.people_ui.process_event(evt, &evt_data, handle);
183 evt_ui.animal_ui.process_event(evt, &evt_data, handle);
184 evt_ui.food_ui.process_event(evt, &evt_data, handle);
185
186 match evt {
187 E::OnListBoxSelect =>
188 if &handle == &evt_ui.menu {
189 PartialDemo::change_interface(&evt_ui.inner);
190 },
191 E::OnWindowClose =>
192 if &handle == &evt_ui.window {
193 PartialDemo::exit(&evt_ui.inner);
194 },
195 E::OnButtonClick =>
196 if &handle == &evt_ui.people_ui.save_btn || &handle == &evt_ui.animal_ui.save_btn ||&handle == &evt_ui.food_ui.save_btn {
197 PartialDemo::save(&evt_ui.inner);
198 },
199 _ => {}
200 }
201 };
202
203 ui.default_handler.borrow_mut().push(
204 nwg::full_bind_event_handler(handle, handle_events)
205 );
206 }
207
208 // Layout
209 use nwg::stretch::{geometry::Size, style::Dimension as D};
210
211 nwg::FlexboxLayout::builder()
212 .parent(&ui.window)
213 .child(&ui.menu)
214 .child_size(Size { width: D::Percent(0.3), height: D::Auto })
215 .child(&ui.frame1)
216 .child_size(Size { width: D::Percent(1.0), height: D::Auto })
217 .build(&ui.layout)?;
218
219 return Ok(ui);
220 }
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 29)
28 fn change_interface(&self) {
29 self.frame1.set_visible(false);
30 self.frame2.set_visible(false);
31 self.frame3.set_visible(false);
32
33 let layout = &self.layout;
34 if layout.has_child(&self.frame1) { layout.remove_child(&self.frame1); }
35 if layout.has_child(&self.frame2) { layout.remove_child(&self.frame2); }
36 if layout.has_child(&self.frame3) { layout.remove_child(&self.frame3); }
37
38 use nwg::stretch::{geometry::Size, style::{Style, Dimension as D}};
39 let mut style = Style::default();
40 style.size = Size { width: D::Percent(1.0), height: D::Auto };
41
42 match self.menu.selection() {
43 None | Some(0) => {
44 layout.add_child(&self.frame1, style).unwrap();
45 self.frame1.set_visible(true);
46 },
47 Some(1) => {
48 layout.add_child(&self.frame2, style).unwrap();
49 self.frame2.set_visible(true);
50 },
51 Some(2) => {
52 layout.add_child(&self.frame3, style).unwrap();
53 self.frame3.set_visible(true);
54 },
55 Some(_) => unreachable!()
56 }
57 }
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§
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§impl PartialEq<Frame> for ControlHandle
impl PartialEq<Frame> for ControlHandle
impl Eq for Frame
impl StructuralPartialEq for Frame
Auto Trait Implementations§
impl Freeze for Frame
impl RefUnwindSafe for Frame
impl !Send for Frame
impl !Sync for Frame
impl Unpin 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