Frame

Struct Frame 

Source
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. Unlike flags, ex_flags must be used straight from winapi

Control events:

  • MousePress(_): Generic mouse press events on the button
  • OnMouseMove: Generic mouse mouse event
  • OnMouseWheel: Generic mouse wheel event

Fields§

§handle: ControlHandle

Implementations§

Source§

impl Frame

Source

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        }
Source

pub fn focus(&self) -> bool

Returns true if the control currently has the keyboard focus

Source

pub fn set_focus(&self)

Sets the keyboard focus on the button.

Source

pub fn enabled(&self) -> bool

Returns true if the control user can interact with the control, return false otherwise

Source

pub fn set_enabled(&self, v: bool)

Enable or disable the control

Source

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))

Source

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    }
Source

pub fn size(&self) -> (u32, u32)

Returns the size of the button in the parent window

Source

pub fn set_size(&self, x: u32, y: u32)

Sets the size of the button in the parent window

Source

pub fn position(&self) -> (i32, i32)

Returns the position of the button in the parent window

Source

pub fn set_position(&self, x: i32, y: i32)

Sets the position of the button in the parent window

Source

pub fn class_name(&self) -> &'static str

Winapi class name used during control creation

Source

pub fn flags(&self) -> u32

Winapi base flags used during window creation

Source

pub fn forced_flags(&self) -> u32

Winapi flags required by the control

Trait Implementations§

Source§

impl Default for Frame

Source§

fn default() -> Frame

Returns the “default value” for a type. Read more
Source§

impl Drop for Frame

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl From<&Frame> for ControlHandle

Source§

fn from(control: &Frame) -> Self

Converts to this type from the input type.
Source§

impl From<&mut Frame> for ControlHandle

Source§

fn from(control: &mut Frame) -> Self

Converts to this type from the input type.
Source§

impl PartialEq<ControlHandle> for Frame

Source§

fn eq(&self, other: &ControlHandle) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<Frame> for ControlHandle

Source§

fn eq(&self, other: &Frame) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for Frame

Source§

fn eq(&self, other: &Frame) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Frame

Source§

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> 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.