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