//+------------------------------------------------------------------+ //| UEventQueue.mqh | //| Copyright 2026, DearMQL5 GUI Engine | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2026, DearMQL5 GUI Engine" #property link "https://www.mql5.com" #property strict /// Event types generated by DearMQL5 widgets. enum ENUM_U_EVENT_TYPE { U_EVENT_NONE = 0, U_EVENT_CLICK = 1, U_EVENT_VALUE_CHANGE= 2, U_EVENT_SUBMIT = 3, U_EVENT_DRAG = 4 }; /// Discrete GUI event packet. struct SUIEvent { ENUM_U_EVENT_TYPE type; ///< Category of event ulong widget_id; ///< FNV-1a hash of source widget double float_value; ///< Numeric payload (slider values, etc.) string string_value; ///< Textual payload (edit boxes, etc.) }; /// Circular event buffer for decoupling widget interaction from consumer code. class UEventQueue { private: static SUIEvent s_queue[64]; static int s_head; static int s_tail; static int s_count; public: /// Resets the event queue. static void Clear(void) { s_head = 0; s_tail = 0; s_count = 0; } /// Pushes an event to the queue. static bool Push(const ENUM_U_EVENT_TYPE type, const ulong widget_id, const double float_val = 0.0, const string str_val = "") { if(s_count >= 64) return(false); // Buffer full s_queue[s_tail].type = type; s_queue[s_tail].widget_id = widget_id; s_queue[s_tail].float_value = float_val; s_queue[s_tail].string_value = str_val; s_tail = (s_tail + 1) % 64; s_count++; return(true); } /// Pops the next event from the queue. Returns false if queue is empty. static bool Pop(SUIEvent &event) { if(s_count <= 0) return(false); event = s_queue[s_head]; s_head = (s_head + 1) % 64; s_count--; return(true); } /// Returns whether there are pending events in the queue. static bool HasEvents(void) { return(s_count > 0); } }; SUIEvent UEventQueue::s_queue[64]; int UEventQueue::s_head = 0; int UEventQueue::s_tail = 0; int UEventQueue::s_count = 0;