[−][src]Derive Macro uniui_gui::DataProcessor
#[derive(DataProcessor)] { // Attributes available to this derive: #[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] }
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 for usage example
#[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.
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 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 method will be called every time when process_data called for the Structure.