1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
//! The crate with helpful proc macros for uniui_gui.
//!
//! It's better to use that functionality via uniui_gui since the crate itself
//! is not ready to be used directly anythere.

extern crate proc_macro;
use proc_macro::TokenStream;

fn the_crate_name() -> proc_macro2::TokenStream {
	quote::quote! {
		uniui_gui
	}
}

mod derives;
mod u_main;

/// Macros allows to mark function as main entry point for UniUi Application
///
/// uniui_gui crate have to be presented in the scope.
///
/// wasm_bindgen should not be in dependencies of the crate
///
/// Example
/// ```
/// #[uniui_gui::uni_main]
/// pub fn app_main(app: &mut uniui_gui::Application) {
///     // ...
/// }
/// ```
#[proc_macro_attribute]
pub fn u_main(
	attr: TokenStream,
	input: TokenStream,
) -> TokenStream {
	return u_main::u_main(attr, input);
}

/// DataProcessor derive macro
///
/// The DataProcessor trait will be automatically implemented for the structure.
///
/// There is few attributes which will help you to configure the implementation.
///
/// # #[public_slot]
/// Structure's private member which implements [uniui_core::Slot] trait may be that
/// attribute. Then new method will be generated with the same name as memeber's name.
/// The method will give public access to the member as `&dyn Slot`.
///
/// Example:
/// ```
/// mod string_processor {
///     #[derive(uniui_gui::DataProcessor)]
///     pub struct StringProcessor {
///         #[public_slot]
///         slot_process_string: uniui_core::SlotImpl<String>,
///     }
///
///     // That kind of code will be generated automatically by derive macos:
///     //
///     // impl StringProcessor {
///     //     pub fn slot_process_string(&self) -> &dyn Slot<String> {
///     //         return &self.slot_process_string;
///     //     }
///     // }
/// }
///
/// // Usage:
///
/// use string_processor::StringProcessor;
///
/// fn send_empty_string(string_processor: StringProcessor, s: String) {
///     let slot: &dyn Slot<String> = string_processor.slot_process_string();
///     slot.exec_for(s);
/// }
/// ```
///
/// # #\[public_signal\]
/// Makes public method to access structure's member of [uniui_core::Signal] type.
///
/// # #\[uprocess_self(<method_name>)\]
/// The structure itself may be marked by the attribute. Structure's method should
/// be provided as parameter to attribue. Then the method will be called every
/// tick (see [uniui_gui::Application] for more info about ticks).
///
/// # #\[uprocess_each(<method_name>)\]
/// Structure's [uniui_core::SlotImpl] may be marked. Then each value arrived
/// to the slot will be processed by the method.
///
/// # #\[uprocess_last(<method_name>)\]
/// Structure's [uniui_core::SlotImpl] may be marked. Then each tick the last arrived
/// value will be processed by the method.
///
/// # #\[uprocess_each_app(<method_name>)\]
/// The same as `#[uprocess_each]` but reference to the [uniui_gui::Application]
/// will be provided as an extra parameter for the method.
///
/// # #\[uprocess_last_app(<method_name>)\]
/// The same as `#[uprocess_last]` but reference to the [uniui_gui::Application]
/// will be provided as an extra parameter for the method.
///
/// # #\[uproperty_process\]
/// Structure's member of type [uniui_core::Property] may be marked by attribute.
/// Then every tick the member will process all incoming values. The method name
/// may be provided as a parameter of the attribute. Then the method will be called
/// every time (Property)[uniui_core::Property]'s value will be changed.
///
/// # #\[uproperty_public_slot(<method_name>)\]
/// Create public method to access [uniui_core::Property]'s slot. New method with
/// provided name will be generated.
///
/// # #\[uproperty_public_signal(<method_name>)\]
/// Create public method to access [uniui_core::Property]'s signal. New method with
/// provided name will be generated.
///
/// # #\[data_processor\]
/// Structure's member of type [DataProcessor] may be marked by that attribute.
/// Then the member's [process_data](DataProcessor#process_data) method
/// will be called every time when [process_data](DataProcessor#process_data)
/// called for the Structure.
#[proc_macro_derive(
	DataProcessor,
	attributes(
		public_slot,
		public_signal,
		uprocess_self,
		uprocess_each,
		uprocess_last,
		uprocess_each_app,
		uprocess_last_app,
		uproperty_process,
		uproperty_public_slot,
		uproperty_public_signal,
		data_processor,
	)
)]
pub fn derive_data_processor(input: TokenStream) -> TokenStream {
	return derives::derive_uobject(input);
}

/// Widget derive macro
///
/// The Widget (and DataProcessor) trait will be automatically implemented for the
/// structure.
///
/// There is few attributes which will help you to configure the implementation.
///
/// # #\[uwidget\]
/// Exactly one structure's member with implemented [Widget] trait have to be
/// marked by the attribute. All [Widget] stuff will be delegated to the member.
///
/// # #\[public_slot\]
/// see [DataProcessor's public_slot](derive.DataProcessor.html#public_slot)
///
/// # #\[public_signal\]
/// see [DataProcessor's public_signal](derive.DataProcessor.html#public_signal)
///
/// # #\[uprocess_self(<method_name>)\]
/// see [DataProcessor's uprocess_self](derive.DataProcessor.html#uprocess_self)
///
/// # #\[uprocess_each(<method_name>)\]
/// see [DataProcessor's uprocess_each](derive.DataProcessor.html#uprocess_each)
///
/// # #\[uprocess_last(<method_name>)\]
/// see [DataProcessor's uprocess_last](derive.DataProcessor.html#uprocess_last)
///
/// # #\[uprocess_each_app(<method_name>)\]
/// see [DataProcessor's uprocess_each_app](derive.DataProcessor.html#uprocess_each_app)
///
/// # #\[uprocess_last_app(<method_name>)\]
/// see [DataProcessor's uprocess_last_app](derive.DataProcessor.html#uprocess_last_app)
///
/// # #\[uproperty_process\]
/// see [DataProcessor's uproperty_process](derive.DataProcessor.html#uproperty_process)
///
/// # #\[uproperty_public_slot(<method_name>)\]
/// see [DataProcessor's
/// uproperty_public_slot](derive.DataProcessor.html#uproperty_public_slot)
///
/// # #\[uproperty_public_signal(<method_name>)\]
/// see [DataProcessor's
/// uproperty_public_signal](derive.DataProcessor.html#uproperty_public_signal)
///
/// # #\[data_processor\]
/// see [DataProcessor's data_processor](derive.DataProcessor.html#data_processor)
#[proc_macro_derive(
	Widget,
	attributes(
		public_slot,
		public_signal,
		uprocess_self,
		uprocess_each,
		uprocess_last,
		uprocess_each_app,
		uprocess_last_app,
		uproperty_process,
		uproperty_public_slot,
		uproperty_public_signal,
		uwidget,
		data_processor,
	)
)]
pub fn derive_widget(input: TokenStream) -> TokenStream {
	return derives::derive_uwidget(input);
}