native_windows_gui2/
lib.rs

1#[macro_use]
2extern crate bitflags;
3
4#[macro_use]
5extern crate lazy_static;
6
7extern crate winapi;
8
9#[cfg(feature = "flexbox")]
10pub extern crate stretch;
11
12#[cfg(feature = "all")]
13#[cfg(test)]
14mod tests;
15
16mod errors;
17pub use errors::NwgError;
18
19mod events;
20pub use events::*;
21
22mod common_types;
23pub use common_types::*;
24
25pub(crate) mod win32;
26pub use win32::{
27    dispatch_thread_events, dispatch_thread_events_blocking_with_callback,
28    dispatch_thread_events_with_callback, enable_visual_styles, init_common_controls,
29    message_box::*,
30    stop_thread_dispatch,
31    window::{
32        EventHandler, RawEventHandler, bind_event_handler, bind_raw_event_handler,
33        full_bind_event_handler, has_raw_handler, unbind_event_handler, unbind_raw_event_handler,
34    },
35};
36
37pub(crate) use win32::window::bind_raw_event_handler_inner;
38
39#[allow(deprecated)]
40pub use win32::high_dpi::{dpi, scale_factor, set_dpi_awareness};
41
42pub use win32::monitor::Monitor;
43
44#[cfg(feature = "cursor")]
45pub use win32::cursor::GlobalCursor;
46
47#[cfg(feature = "clipboard")]
48pub use win32::clipboard::{Clipboard, ClipboardData, ClipboardFormat};
49
50mod resources;
51pub use resources::*;
52
53mod controls;
54pub use controls::*;
55
56mod layouts;
57pub use layouts::*;
58
59#[cfg(feature = "winnls")]
60mod winnls;
61
62#[cfg(feature = "winnls")]
63pub use winnls::*;
64
65/**
66    A structure that implements this trait is considered a GUI structure. The structure will hold GUI components and possibly user data.
67
68    A structure that implements `PartialUi` must be part of another UI structure and cannot be used as it is. It will most likely be used
69    as the struct member of another struct that implements `NativeUi`.
70
71    The goal of `NativeUi` and `PartialUi` is to provide a common way to define NWG applications.
72    Native-windows-derive can automatically implement this trait.
73
74    For an example on how to implement this trait, see the **Small application layout** section in the NWG documentation.
75*/
76pub trait PartialUi {
77    /**
78        Should initialize the GUI components. Similar to `NativeUi::build_ui` except it doesn't handle event binding.
79
80        Parameters:
81          - `data`: A reference to the struct data from the parent struct
82          - `parent`: An optional reference to the parent UI control. If this is defined, the ui controls of the partial should be children of this value.
83    */
84    fn build_partial<W: Into<ControlHandle>>(
85        data: &mut Self,
86        parent: Option<W>,
87    ) -> Result<(), NwgError>;
88
89    /**
90        Should process the events of the partial. This method will probably be called from an event handler bound in the parent GUI structure.
91
92        Parameters:
93          - `base`: A reference to the parent struct data
94          - `evt`: The event raised
95          - `evt_data`: The data of the event raised
96          - `handle`: Handle of the control that raised the event
97    */
98    fn process_event(&self, _evt: Event, _evt_data: &EventData, _handle: ControlHandle) {}
99
100    /**
101        Should return the handles of the top level parent controls (such as Windows). Those handle should be used to bind
102        the default events handler.
103    */
104    fn handles<'a>(&'a self) -> Vec<&'a ControlHandle> {
105        vec![]
106    }
107}
108
109/**
110    A structure that implements this trait is considered a GUI structure. The structure will hold GUI components and possibly user data.
111
112    The goal of `NativeUi` and `PartialUi` is to provide a common way to define NWG applications.
113    Native-windows-derive can automatically implement this trait.
114
115    For an example on how to implement this trait, see the **Small application layout** section in the NWG documentation.
116*/
117pub trait NativeUi<UI> {
118    /**
119        A constructor for the structure. It should initialize the GUI components and bind GUI events.
120
121        Parameters:
122          - `inital_state`: should contain the initial user data. `NativeUi` assumes this data will be wrapped in another type (`UI`).
123    */
124    fn build_ui(inital_state: Self) -> Result<UI, NwgError>;
125}
126
127/// Initializes some application wide GUI settings.
128/// This includes default styling and common controls resources.
129pub fn init() -> std::result::Result<(), errors::NwgError> {
130    if cfg!(not(feature = "no-styling")) {
131        enable_visual_styles();
132    }
133
134    init_common_controls()
135}