Add widget tag support (and fix a couple of doxygen problems)

ugfx_release_2.6
inmarket 2014-07-15 16:38:13 +10:00
parent 679961a25e
commit 0587e35169
14 changed files with 96 additions and 3 deletions

View File

@ -166,6 +166,7 @@
// #define GWIN_NEED_PROGRESSBAR FALSE // #define GWIN_NEED_PROGRESSBAR FALSE
// #define GWIN_PROGRESSBAR_AUTO FALSE // #define GWIN_PROGRESSBAR_AUTO FALSE
// #define GWIN_FLAT_STYLING FALSE // #define GWIN_FLAT_STYLING FALSE
// #define GWIN_WIDGET_TAGS FALSE
//#define GWIN_NEED_CONTAINERS FALSE //#define GWIN_NEED_CONTAINERS FALSE
// #define GWIN_NEED_CONTAINER FALSE // #define GWIN_NEED_CONTAINER FALSE

View File

@ -39,6 +39,9 @@ static void SendButtonEvent(GWidgetObject *gw) {
continue; continue;
pbe->type = GEVENT_GWIN_BUTTON; pbe->type = GEVENT_GWIN_BUTTON;
pbe->button = (GHandle)gw; pbe->button = (GHandle)gw;
#if GWIN_WIDGET_TAGS
pbe->tag = gw->tag;
#endif
geventSendEvent(psl); geventSendEvent(psl);
} }

View File

@ -38,6 +38,9 @@
typedef struct GEventGWinButton { typedef struct GEventGWinButton {
GEventType type; // The type of this event (GEVENT_GWIN_BUTTON) GEventType type; // The type of this event (GEVENT_GWIN_BUTTON)
GHandle button; // The button that has been depressed (actually triggered on release) GHandle button; // The button that has been depressed (actually triggered on release)
#if GWIN_WIDGET_TAGS
WidgetTag tag; // The button tag
#endif
} GEventGWinButton; } GEventGWinButton;
/** /**

View File

@ -33,6 +33,9 @@ static void SendCheckboxEvent(GWidgetObject *gw) {
pce->type = GEVENT_GWIN_CHECKBOX; pce->type = GEVENT_GWIN_CHECKBOX;
pce->checkbox = &gw->g; pce->checkbox = &gw->g;
pce->isChecked = (gw->g.flags & GCHECKBOX_FLG_CHECKED) ? TRUE : FALSE; pce->isChecked = (gw->g.flags & GCHECKBOX_FLG_CHECKED) ? TRUE : FALSE;
#if GWIN_WIDGET_TAGS
pce->tag = gw->tag;
#endif
geventSendEvent(psl); geventSendEvent(psl);
} }

View File

@ -38,6 +38,9 @@ typedef struct GEventGWinCheckbox {
GEventType type; // The type of this event (GEVENT_GWIN_CHECKBOX) GEventType type; // The type of this event (GEVENT_GWIN_CHECKBOX)
GHandle checkbox; // The checkbox that has been depressed (actually triggered on release) GHandle checkbox; // The checkbox that has been depressed (actually triggered on release)
bool_t isChecked; // Is the checkbox currently checked or unchecked? bool_t isChecked; // Is the checkbox currently checked or unchecked?
#if GWIN_WIDGET_TAGS
WidgetTag tag; // The checkbox tag
#endif
} GEventGWinCheckbox; } GEventGWinCheckbox;
/* A Checkbox window */ /* A Checkbox window */

View File

@ -242,6 +242,9 @@ GHandle _gwidgetCreate(GDisplay *g, GWidgetObject *pgw, const GWidgetInit *pInit
pgw->fnDraw = pInit->customDraw ? pInit->customDraw : vmt->DefaultDraw; pgw->fnDraw = pInit->customDraw ? pInit->customDraw : vmt->DefaultDraw;
pgw->fnParam = pInit->customParam; pgw->fnParam = pInit->customParam;
pgw->pstyle = pInit->customStyle ? pInit->customStyle : defaultStyle; pgw->pstyle = pInit->customStyle ? pInit->customStyle : defaultStyle;
#if GWIN_WIDGET_TAGS
pgw->tag = pInit->tag;
#endif
return &pgw->g; return &pgw->g;
} }
@ -473,5 +476,16 @@ bool_t gwinAttachListener(GListener *pl) {
} }
#endif #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 */ #endif /* GFX_USE_GWIN && GWIN_NEED_WIDGET */
/** @} */ /** @} */

View File

@ -72,6 +72,11 @@ extern const GWidgetStyle WhiteWidgetStyle;
*/ */
typedef void (*CustomWidgetDrawFunction)(struct GWidgetObject *gw, void *param); 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. * @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 CustomWidgetDrawFunction customDraw; // @< A custom draw function - use NULL for the standard
void * customParam; // @< A parameter for the custom draw function (default = NULL) 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 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; } GWidgetInit;
/** @} */ /** @} */
@ -110,6 +118,9 @@ typedef struct GWidgetObject {
CustomWidgetDrawFunction fnDraw; // @< The current draw function CustomWidgetDrawFunction fnDraw; // @< The current draw function
void * fnParam; // @< A parameter for the current draw function void * fnParam; // @< A parameter for the current draw function
const GWidgetStyle * pstyle; // @< The current widget style colors const GWidgetStyle * pstyle; // @< The current widget style colors
#if GWIN_WIDGET_TAGS || defined(__DOXYGEN__)
WidgetTag tag; // @< The widget tag
#endif
} GWidgetObject; } GWidgetObject;
/** @} */ /** @} */
@ -187,6 +198,34 @@ void gwinSetText(GHandle gh, const char *text, bool_t useAlloc);
*/ */
const char *gwinGetText(GHandle gh); 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. * @brief Set the style of a widget.
* *
@ -235,7 +274,7 @@ void gwinSetCustomDraw(GHandle gh, CustomWidgetDrawFunction fn, void *param);
*/ */
bool_t gwinAttachListener(GListener *pl); 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 * @brief Set the mouse to be used to control the widgets
* @return TRUE on success * @return TRUE on success
@ -249,7 +288,7 @@ bool_t gwinAttachListener(GListener *pl);
bool_t gwinAttachMouse(uint16_t instance); bool_t gwinAttachMouse(uint16_t instance);
#endif #endif
#if GFX_USE_GINPUT && GINPUT_NEED_TOGGLE #if (GFX_USE_GINPUT && GINPUT_NEED_TOGGLE) || defined(__DOXYGEN__)
/** /**
* @brief Attach a toggle to a widget * @brief Attach a toggle to a widget
* @return TRUE on success * @return TRUE on success
@ -267,7 +306,7 @@ bool_t gwinAttachListener(GListener *pl);
bool_t gwinAttachToggle(GHandle gh, uint16_t role, uint16_t instance); bool_t gwinAttachToggle(GHandle gh, uint16_t role, uint16_t instance);
#endif #endif
#if GFX_USE_GINPUT && GINPUT_NEED_DIAL #if (GFX_USE_GINPUT && GINPUT_NEED_DIAL) || defined(__DOXYGEN__)
/** /**
* @brief Attach a toggle to a widget * @brief Attach a toggle to a widget
* @return TRUE on success * @return TRUE on success

View File

@ -66,6 +66,9 @@ static void sendListEvent(GWidgetObject *gw, int item) {
ple->type = GEVENT_GWIN_LIST; ple->type = GEVENT_GWIN_LIST;
ple->list = (GHandle)gw; ple->list = (GHandle)gw;
ple->item = item; ple->item = item;
#if GWIN_WIDGET_TAGS
ple->tag = gw->tag;
#endif
geventSendEvent(psl); geventSendEvent(psl);
} }

View File

@ -40,6 +40,9 @@ typedef struct GEventGWinList {
GEventType type; // The type of this event (GEVENT_GWIN_LIST) GEventType type; // The type of this event (GEVENT_GWIN_LIST)
GHandle list; // The list GHandle list; // The list
int item; // The item that has been selected (or unselected in a multi-select listbox) 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; } GEventGWinList;
// A list window // A list window

View File

@ -38,6 +38,9 @@ static void SendRadioEvent(GWidgetObject *gw) {
pbe->type = GEVENT_GWIN_RADIO; pbe->type = GEVENT_GWIN_RADIO;
pbe->radio = (GHandle)gw; pbe->radio = (GHandle)gw;
pbe->group = ((GRadioObject *)gw)->group; pbe->group = ((GRadioObject *)gw)->group;
#if GWIN_WIDGET_TAGS
pbe->tag = gw->tag;
#endif
geventSendEvent(psl); geventSendEvent(psl);
} }

View File

@ -37,6 +37,9 @@ typedef struct GEventGWinRadio {
GEventType type; // The type of this event (GEVENT_GWIN_RADIO) GEventType type; // The type of this event (GEVENT_GWIN_RADIO)
GHandle radio; // The radio button that has been depressed GHandle radio; // The radio button that has been depressed
uint16_t group; // The group for this radio button uint16_t group; // The group for this radio button
#if GWIN_WIDGET_TAGS
WidgetTag tag; // The radio tag
#endif
} GEventGWinRadio; } GEventGWinRadio;
/** /**

View File

@ -38,6 +38,9 @@ static void SendSliderEvent(GWidgetObject *gw) {
pse->type = GEVENT_GWIN_SLIDER; pse->type = GEVENT_GWIN_SLIDER;
pse->slider = (GHandle)gw; pse->slider = (GHandle)gw;
pse->position = ((GSliderObject *)gw)->pos; pse->position = ((GSliderObject *)gw)->pos;
#if GWIN_WIDGET_TAGS
pse->tag = gw->tag;
#endif
geventSendEvent(psl); geventSendEvent(psl);
} }

View File

@ -30,6 +30,9 @@ typedef struct GEventGWinSlider {
GEventType type; // The type of this event (GEVENT_GWIN_BUTTON) GEventType type; // The type of this event (GEVENT_GWIN_BUTTON)
GHandle slider; // The slider that is returning results GHandle slider; // The slider that is returning results
int position; int position;
#if GWIN_WIDGET_TAGS
WidgetTag tag; // The slider tag
#endif
} GEventGWinSlider; } GEventGWinSlider;
// There are currently no GEventGWinSlider listening flags - use 0 // There are currently no GEventGWinSlider listening flags - use 0

View File

@ -127,6 +127,15 @@
* @name GWIN Optional Parameters * @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 * @brief Use flat styling for controls rather than a 3D look
* @details Defaults to FALSE * @details Defaults to FALSE