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 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
//! 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 presented in crate's dependencies list. /// /// 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] /// Attribute may be added to private member which /// implements [uniui_core::Slot] trait. For the structure new method will be generated /// with he 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\] /// Attribute may be added to private member which /// implements [uniui_core::Signal] trait. For the structure new method will be generated /// with he same name as memeber's name. The method will give public access to the /// member as `&mut dyn Signal`. /// /// Example: /// ``` /// mod string_provider { /// #[derive(uniui_gui::DataProcessor)] /// pub struct StringProvider { /// #[public_signal] /// signal_new_string: uniui_core::Signal<String>, /// } /// /// // That kind of code will be generated automatically by derive macos: /// // /// // impl StringProvider { /// // pub fn signal_new_string(&mut self) -> &mut dyn Signal<String> { /// // return &mut self.signal_new_string; /// // } /// // } /// } /// /// // Usage: /// /// use string_provider::StringProvider; /// /// fn listen_for_new_string(provider: StringProvider, s: &dyn Slot<String>) { /// provider.signal_new_string().connect_slot(s); /// } /// ``` /// /// # #\[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] and [uniui_gui::DataProcessor#process_data] /// for more info about ticks). /// /// Example /// ``` /// #[derive(uniui_gui::DataProcessor)] /// #[uprocess_self(tick)] /// pub struct SelfProcessor { /// } /// /// impl SelfProcessor { /// pub tick(&mut self, _: i64, _: &mut uniui_gui::Application) { /// log:trace!("tick"); /// } /// } /// ``` /// /// # #\[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 `<method_name>`. /// /// Example: /// ``` /// #[derive(uniui_gui::DataProcessor)] /// pub struct StringLogger { /// #[public_slot] /// #[uprocess_each(log_string)] /// slot_log_string: uniui_gui::core::SlotImpl<String>, /// } /// /// impl StringLogger{ /// pub fn new() -> Self { /// slot_lot_string: uniui_gui::core::SlotImpl::new(), /// } /// /// // The method will be called for each value posted to the slot_log_string /// fn log_string(&self, s: String) { /// log::info!("new string:{}", s); /// } /// } /// ``` /// /// # #\[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. See /// [uprocess_each](derive.DataProcessor.html#uprocess_each) for usage example /// /// # #\[uprocess_each_app(<method_name>)\] /// The same as [uprocess_each](derive.DataProcessor.html#uprocess_each) but /// reference to the [uniui_gui::Application] will be provided as an extra /// parameter for the method. /// /// Example: /// ``` /// #[derive(uniui_gui::DataProcessor)] /// pub struct StringLogger { /// #[public_slot] /// #[uprocess_each_app(log_string)] /// slot_log_string: uniui_gui::core::SlotImpl<String>, /// } /// /// impl StringLogger{ /// pub fn new() -> Self { /// slot_lot_string: uniui_gui::core::SlotImpl::new(), /// } /// /// // The method will be called for each value posted to the slot_log_string /// fn log_string(&self, s: String, _app: &mut uniui_gui::core::Application) { /// log::info!("new string:{}", s); /// } /// } /// ``` /// /// /// # #\[uprocess_last_app(<method_name>)\] /// The same as [uprocess_last](derive.DataProcessor.html#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. /// /// # #\[base_widget\] /// 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, base_widget, data_processor, ) )] pub fn derive_widget(input: TokenStream) -> TokenStream { return derives::derive_widget(input); }