aboutsummaryrefslogtreecommitdiffstats
path: root/include/gwin/gwidget.h
diff options
context:
space:
mode:
authorinmarket <andrewh@inmarket.com.au>2013-07-07 19:40:37 +1000
committerinmarket <andrewh@inmarket.com.au>2013-07-07 19:40:37 +1000
commit3957505ab119b21c7b0f4e72f56030c97711988a (patch)
tree5a059012d5fa0d07a93fcb70e72518bdaca1d4c5 /include/gwin/gwidget.h
parentde28112a7d6db829142ad113c93eb8ad071b0d65 (diff)
downloaduGFX-3957505ab119b21c7b0f4e72f56030c97711988a.tar.gz
uGFX-3957505ab119b21c7b0f4e72f56030c97711988a.tar.bz2
uGFX-3957505ab119b21c7b0f4e72f56030c97711988a.zip
GWIN renaming, tidy up, color styles
Diffstat (limited to 'include/gwin/gwidget.h')
-rw-r--r--include/gwin/gwidget.h124
1 files changed, 106 insertions, 18 deletions
diff --git a/include/gwin/gwidget.h b/include/gwin/gwidget.h
index ffd8e26f..222a3af5 100644
--- a/include/gwin/gwidget.h
+++ b/include/gwin/gwidget.h
@@ -31,28 +31,50 @@
struct GWidgetObject;
/**
- * @brief Defines a custom drawing function for a widget
+ * @brief The GColorSet structure
+ * @{
*/
-typedef void (*CustomWidgetDrawFunction)(struct GWidgetObject *gw, void *param);
+typedef struct GColorSet {
+ color_t text; // @< The text color
+ color_t edge; // @< The edge color
+ color_t fill; // @< The fill color
+ color_t progress; // @< The color of progress bars
+} GColorSet;
+/* @} */
/**
- * @brief The GWIN Widget structure
- * @note A widget is a GWIN window that accepts user input.
- * It also has a number of other properties such as its ability
- * to redraw itself (a widget maintains drawing state).
- * @note Do not access the members directly. Treat it as a black-box and use the method functions.
- *
+ * @brief The GWidgetStyle structure
+ * @details A GWidgetStyle is a set of colors that together form a "style".
+ * These colors should not be confused with the GWindow foreground
+ * and background colors which are used for drawing operations.
* @{
*/
-typedef struct GWidgetObject {
- GWindowObject g; // @< This is still a GWIN
- const char * txt; // @< The widget text
- CustomWidgetDrawFunction fnDraw; // @< The current draw function
- void * fnParam; // @< A parameter for the current draw function
-} GWidgetObject;
+typedef struct GWidgetStyle {
+ color_t background; // @< The window background color
+ GColorSet enabled; // @< The colors when enabled
+ GColorSet disabled; // @< The colors when disabled
+ GColorSet pressed; // @< The colors when pressed
+} GWidgetStyle;
/* @} */
/**
+ * @brief We define a couple of GWidgetStyle's that you can use in your
+ * application. The Black style is the default style if you don't
+ * specify one.
+ * @note BlackWidgetStyle means that it is designed for a Black background.
+ * Similarly WhiteWidgetStyle is designed for a White background.
+ * @{
+ */
+extern const GWidgetStyle BlackWidgetStyle;
+extern const GWidgetStyle WhiteWidgetStyle;
+/* @} */
+
+/**
+ * @brief Defines a custom drawing function for a widget
+ */
+typedef void (*CustomWidgetDrawFunction)(struct GWidgetObject *gw, void *param);
+
+/**
* @brief The structure to initialise a widget.
*
* @note Some widgets may have extra parameters.
@@ -63,12 +85,33 @@ typedef struct GWidgetObject {
* @{
*/
typedef struct GWidgetInit {
- GWindowInit g; // @< The GWIN initializer
- const char * text; // @< The initial text
+ GWindowInit g; // @< The GWIN initializer
+ const char * text; // @< The initial text
+ 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
} GWidgetInit;
/* @} */
/**
+ * @brief The GWIN Widget structure
+ * @note A widget is a GWIN window that accepts user input.
+ * It also has a number of other properties such as its ability
+ * to redraw itself (a widget maintains drawing state).
+ * @note Do not access the members directly. Treat it as a black-box and use the method functions.
+ *
+ * @{
+ */
+typedef struct GWidgetObject {
+ GWindowObject g; // @< This is still a GWIN
+ const char * text; // @< The widget text
+ CustomWidgetDrawFunction fnDraw; // @< The current draw function
+ void * fnParam; // @< A parameter for the current draw function
+ const GWidgetStyle * pstyle; // @< The current widget style colors
+} GWidgetObject;
+/* @} */
+
+/**
* A comment/rant on the above structure:
* We would really like the GWindowObject member to be anonymous. While this is
* allowed under the C11, C99, GNU and various other standards which have been
@@ -84,10 +127,31 @@ extern "C" {
#endif
/**
+ * @brief Set the default style for widgets created hereafter.
+ *
+ * @param[in] pstyle The default style. Passing NULL uses the system compiled style.
+ * @param[in] updateAll If TRUE then all existing widgets that are using the current default style
+ * will be updated to use this new style. Widgets that have custom styles different
+ * from the default style will not be updated.
+ *
+ * @note The style must be allocated statically (not on the stack) as only the pointer is stored.
+ *
+ * @api
+ */
+void gwinSetDefaultStyle(const GWidgetStyle *pstyle, bool_t updateAll);
+
+/**
+ * @brief Get the current default style.
+ *
+ * @api
+ */
+const GWidgetStyle *gwinGetDefaultStyle(void);
+
+/**
* @brief Set the text of a widget.
*
* @param[in] gh The widget handle
- * @param[in] txt The text to set. This must be a constant string unless useAlloc is set.
+ * @param[in] text The text to set. This must be a constant string unless useAlloc is set.
* @param[in] useAlloc If TRUE the string specified will be copied into dynamically allocated memory.
*
* @note The widget is automatically redrawn
@@ -95,7 +159,7 @@ extern "C" {
*
* @api
*/
-void gwinSetText(GHandle gh, const char *txt, bool_t useAlloc);
+void gwinSetText(GHandle gh, const char *text, bool_t useAlloc);
/**
* @brief Get the text of a widget.
@@ -108,6 +172,30 @@ void gwinSetText(GHandle gh, const char *txt, bool_t useAlloc);
const char *gwinGetText(GHandle gh);
/**
+ * @brief Set the style of a widget.
+ *
+ * @param[in] gh The widget handle
+ * @param[in] pstyle The style to set. This must be a static structure (not allocated on a transient stack).
+ * Use NULL to reset to the default style.
+ *
+ * @note The widget is automatically redrawn
+ * @note Non-widgets will ignore this call.
+ *
+ * @api
+ */
+void gwinSetStyle(GHandle gh, const GWidgetStyle *pstyle);
+
+/**
+ * @brief Get the style of a widget.
+ * @return The widget style or NULL if it isn't a widget
+ *
+ * @param[in] gh The widget handle
+ *
+ * @api
+ */
+const GWidgetStyle *gwinGetStyle(GHandle gh);
+
+/**
* @brief Set the routine to perform a custom widget drawing.
*
* @param[in] gh The widget handle