diff --git a/gfxconf.example.h b/gfxconf.example.h index ef6bedbe..8754ba32 100644 --- a/gfxconf.example.h +++ b/gfxconf.example.h @@ -166,6 +166,7 @@ // #define GWIN_NEED_PROGRESSBAR FALSE // #define GWIN_PROGRESSBAR_AUTO FALSE // #define GWIN_FLAT_STYLING FALSE +// #define GWIN_WIDGET_TAGS FALSE //#define GWIN_NEED_CONTAINERS FALSE // #define GWIN_NEED_CONTAINER FALSE diff --git a/src/gwin/button.c b/src/gwin/button.c index d489ecb0..fc1cb976 100644 --- a/src/gwin/button.c +++ b/src/gwin/button.c @@ -39,6 +39,9 @@ static void SendButtonEvent(GWidgetObject *gw) { continue; pbe->type = GEVENT_GWIN_BUTTON; pbe->button = (GHandle)gw; + #if GWIN_WIDGET_TAGS + pbe->tag = gw->tag; + #endif geventSendEvent(psl); } diff --git a/src/gwin/button.h b/src/gwin/button.h index 73d5f9f1..077b50f4 100644 --- a/src/gwin/button.h +++ b/src/gwin/button.h @@ -38,6 +38,9 @@ typedef struct GEventGWinButton { GEventType type; // The type of this event (GEVENT_GWIN_BUTTON) GHandle button; // The button that has been depressed (actually triggered on release) + #if GWIN_WIDGET_TAGS + WidgetTag tag; // The button tag + #endif } GEventGWinButton; /** diff --git a/src/gwin/checkbox.c b/src/gwin/checkbox.c index f162d8fc..7914ee82 100644 --- a/src/gwin/checkbox.c +++ b/src/gwin/checkbox.c @@ -33,6 +33,9 @@ static void SendCheckboxEvent(GWidgetObject *gw) { pce->type = GEVENT_GWIN_CHECKBOX; pce->checkbox = &gw->g; pce->isChecked = (gw->g.flags & GCHECKBOX_FLG_CHECKED) ? TRUE : FALSE; + #if GWIN_WIDGET_TAGS + pce->tag = gw->tag; + #endif geventSendEvent(psl); } diff --git a/src/gwin/checkbox.h b/src/gwin/checkbox.h index 2b1fb801..ebd35a0b 100644 --- a/src/gwin/checkbox.h +++ b/src/gwin/checkbox.h @@ -38,6 +38,9 @@ typedef struct GEventGWinCheckbox { GEventType type; // The type of this event (GEVENT_GWIN_CHECKBOX) GHandle checkbox; // The checkbox that has been depressed (actually triggered on release) bool_t isChecked; // Is the checkbox currently checked or unchecked? + #if GWIN_WIDGET_TAGS + WidgetTag tag; // The checkbox tag + #endif } GEventGWinCheckbox; /* A Checkbox window */ diff --git a/src/gwin/gwidget.c b/src/gwin/gwidget.c index 8ccb47fc..a2e6f472 100644 --- a/src/gwin/gwidget.c +++ b/src/gwin/gwidget.c @@ -242,6 +242,9 @@ GHandle _gwidgetCreate(GDisplay *g, GWidgetObject *pgw, const GWidgetInit *pInit pgw->fnDraw = pInit->customDraw ? pInit->customDraw : vmt->DefaultDraw; pgw->fnParam = pInit->customParam; pgw->pstyle = pInit->customStyle ? pInit->customStyle : defaultStyle; + #if GWIN_WIDGET_TAGS + pgw->tag = pInit->tag; + #endif return &pgw->g; } @@ -473,5 +476,16 @@ bool_t gwinAttachListener(GListener *pl) { } #endif +#if GWIN_WIDGET_TAGS + void gwinSetTag(GHandle gh, WidgetTag tag) { + if ((gh->flags & GWIN_FLG_WIDGET)) + gw->tag = tag; + } + + WidgetTag gwinGetTag(GHandle gh) { + return ((gh->flags & GWIN_FLG_WIDGET)) ? gw->tag : 0; + } +#endif + #endif /* GFX_USE_GWIN && GWIN_NEED_WIDGET */ /** @} */ diff --git a/src/gwin/gwidget.h b/src/gwin/gwidget.h index 0a7bc72f..bd1ea4c8 100644 --- a/src/gwin/gwidget.h +++ b/src/gwin/gwidget.h @@ -72,6 +72,11 @@ extern const GWidgetStyle WhiteWidgetStyle; */ typedef void (*CustomWidgetDrawFunction)(struct GWidgetObject *gw, void *param); +/** + * @brief Defines a the type of a tag on a widget + */ +typedef uint16_t WidgetTag; + /** * @brief The structure to initialise a widget. * @@ -92,6 +97,9 @@ typedef struct GWidgetInit { CustomWidgetDrawFunction customDraw; // @< A custom draw function - use NULL for the standard void * customParam; // @< A parameter for the custom draw function (default = NULL) const GWidgetStyle * customStyle; // @< A custom style to use - use NULL for the default style + #if GWIN_WIDGET_TAGS || defined(__DOXYGEN__) + WidgetTag tag; // @< The tag to associate with the widget + #endif } GWidgetInit; /** @} */ @@ -110,6 +118,9 @@ typedef struct GWidgetObject { CustomWidgetDrawFunction fnDraw; // @< The current draw function void * fnParam; // @< A parameter for the current draw function const GWidgetStyle * pstyle; // @< The current widget style colors + #if GWIN_WIDGET_TAGS || defined(__DOXYGEN__) + WidgetTag tag; // @< The widget tag + #endif } GWidgetObject; /** @} */ @@ -187,6 +198,34 @@ void gwinSetText(GHandle gh, const char *text, bool_t useAlloc); */ const char *gwinGetText(GHandle gh); +#if GWIN_WIDGET_TAGS || defined(__DOXYGEN__) + /** + * @brief Set the tag of a widget. + * + * @param[in] gh The widget handle + * @param[in] tag The tag to set. + * + * @note Non-widgets will ignore this call. + * + * @pre Requires GWIN_WIDGET_TAGS to be TRUE + * + * @api + */ + void gwinSetTag(GHandle gh, WidgetTag tag); + + /** + * @brief Get the tag of a widget. + * @return The widget tag value (or 0 if it is not a widget) + * + * @param[in] gh The widget handle + * + * @pre Requires GWIN_WIDGET_TAGS to be TRUE + * + * @api + */ + WidgetTag gwinGetTag(GHandle gh); +#endif + /** * @brief Set the style of a widget. * @@ -235,7 +274,7 @@ void gwinSetCustomDraw(GHandle gh, CustomWidgetDrawFunction fn, void *param); */ bool_t gwinAttachListener(GListener *pl); -#if GFX_USE_GINPUT && GINPUT_NEED_MOUSE +#if (GFX_USE_GINPUT && GINPUT_NEED_MOUSE) || defined(__DOXYGEN__) /** * @brief Set the mouse to be used to control the widgets * @return TRUE on success @@ -249,7 +288,7 @@ bool_t gwinAttachListener(GListener *pl); bool_t gwinAttachMouse(uint16_t instance); #endif -#if GFX_USE_GINPUT && GINPUT_NEED_TOGGLE +#if (GFX_USE_GINPUT && GINPUT_NEED_TOGGLE) || defined(__DOXYGEN__) /** * @brief Attach a toggle to a widget * @return TRUE on success @@ -267,7 +306,7 @@ bool_t gwinAttachListener(GListener *pl); bool_t gwinAttachToggle(GHandle gh, uint16_t role, uint16_t instance); #endif -#if GFX_USE_GINPUT && GINPUT_NEED_DIAL +#if (GFX_USE_GINPUT && GINPUT_NEED_DIAL) || defined(__DOXYGEN__) /** * @brief Attach a toggle to a widget * @return TRUE on success diff --git a/src/gwin/list.c b/src/gwin/list.c index c2a857e3..98ec2ed5 100644 --- a/src/gwin/list.c +++ b/src/gwin/list.c @@ -66,6 +66,9 @@ static void sendListEvent(GWidgetObject *gw, int item) { ple->type = GEVENT_GWIN_LIST; ple->list = (GHandle)gw; ple->item = item; + #if GWIN_WIDGET_TAGS + ple->tag = gw->tag; + #endif geventSendEvent(psl); } diff --git a/src/gwin/list.h b/src/gwin/list.h index 9e31bf2a..1eae3c19 100644 --- a/src/gwin/list.h +++ b/src/gwin/list.h @@ -40,6 +40,9 @@ typedef struct GEventGWinList { GEventType type; // The type of this event (GEVENT_GWIN_LIST) GHandle list; // The list int item; // The item that has been selected (or unselected in a multi-select listbox) + #if GWIN_WIDGET_TAGS + WidgetTag tag; // The list tag + #endif } GEventGWinList; // A list window diff --git a/src/gwin/radio.c b/src/gwin/radio.c index af7b877d..557061e4 100644 --- a/src/gwin/radio.c +++ b/src/gwin/radio.c @@ -38,6 +38,9 @@ static void SendRadioEvent(GWidgetObject *gw) { pbe->type = GEVENT_GWIN_RADIO; pbe->radio = (GHandle)gw; pbe->group = ((GRadioObject *)gw)->group; + #if GWIN_WIDGET_TAGS + pbe->tag = gw->tag; + #endif geventSendEvent(psl); } diff --git a/src/gwin/radio.h b/src/gwin/radio.h index 196f8e27..eb7ee719 100644 --- a/src/gwin/radio.h +++ b/src/gwin/radio.h @@ -37,6 +37,9 @@ typedef struct GEventGWinRadio { GEventType type; // The type of this event (GEVENT_GWIN_RADIO) GHandle radio; // The radio button that has been depressed uint16_t group; // The group for this radio button + #if GWIN_WIDGET_TAGS + WidgetTag tag; // The radio tag + #endif } GEventGWinRadio; /** diff --git a/src/gwin/slider.c b/src/gwin/slider.c index b488f823..7ce7b83f 100644 --- a/src/gwin/slider.c +++ b/src/gwin/slider.c @@ -38,6 +38,9 @@ static void SendSliderEvent(GWidgetObject *gw) { pse->type = GEVENT_GWIN_SLIDER; pse->slider = (GHandle)gw; pse->position = ((GSliderObject *)gw)->pos; + #if GWIN_WIDGET_TAGS + pse->tag = gw->tag; + #endif geventSendEvent(psl); } diff --git a/src/gwin/slider.h b/src/gwin/slider.h index 41244186..32161d62 100644 --- a/src/gwin/slider.h +++ b/src/gwin/slider.h @@ -30,6 +30,9 @@ typedef struct GEventGWinSlider { GEventType type; // The type of this event (GEVENT_GWIN_BUTTON) GHandle slider; // The slider that is returning results int position; + #if GWIN_WIDGET_TAGS + WidgetTag tag; // The slider tag + #endif } GEventGWinSlider; // There are currently no GEventGWinSlider listening flags - use 0 diff --git a/src/gwin/sys_options.h b/src/gwin/sys_options.h index b1b58a68..d5240556 100644 --- a/src/gwin/sys_options.h +++ b/src/gwin/sys_options.h @@ -127,6 +127,15 @@ * @name GWIN Optional Parameters * @{ */ + /** + * @brief Add a tag to each widget + * @details Defaults to FALSE + * @note Adds a tag member to each widget. Any events created include this tag. + * The enables switch based application logic to detect the event source. + */ + #ifndef GWIN_WIDGET_TAGS + #define GWIN_WIDGET_TAGS FALSE + #endif /** * @brief Use flat styling for controls rather than a 3D look * @details Defaults to FALSE