aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/gevent/gevent.h2
-rw-r--r--include/gwin/gwin.h10
-rw-r--r--include/gwin/label.h11
-rw-r--r--include/gwin/options.h14
-rw-r--r--src/gwin/gwin.c4
-rw-r--r--src/gwin/label.c120
6 files changed, 93 insertions, 68 deletions
diff --git a/include/gevent/gevent.h b/include/gevent/gevent.h
index b0039849..5868f70f 100644
--- a/include/gevent/gevent.h
+++ b/include/gevent/gevent.h
@@ -48,7 +48,7 @@ typedef uint16_t GEventType;
typedef union GEvent_u {
GEventType type; // The type of this event
char pad[GEVENT_MAXIMUM_SIZE]; // This is here to allow static initialisation of GEventObject's in the application.
- } GEvent;
+} GEvent;
// A special callback function
typedef void (*GEventCallbackFn)(void *param, GEvent *pe);
diff --git a/include/gwin/gwin.h b/include/gwin/gwin.h
index 10aabf6f..21d465b2 100644
--- a/include/gwin/gwin.h
+++ b/include/gwin/gwin.h
@@ -129,8 +129,16 @@ extern "C" {
* @api
*/
void gwinSetDefaultFont(font_t font);
- #endif
+ /**
+ * @brief Get the current default font
+ *
+ * @return The current default font
+ *
+ * @api
+ */
+ font_t gwinGetDefaultFont(void);
+ #endif
/*-------------------------------------------------
* Base functions
diff --git a/include/gwin/label.h b/include/gwin/label.h
index ed774ed7..d387345d 100644
--- a/include/gwin/label.h
+++ b/include/gwin/label.h
@@ -31,9 +31,7 @@
// An label window
typedef struct GLabelWidget_t {
- GWindowObject g;
-
- const char* text;
+ GWidgetObject w;
} GLabelWidget;
#ifdef __cplusplus
@@ -51,12 +49,7 @@ extern "C" {
*
* @api
*/
-GHandle gwinLabelCreate(GLabelWidget *widget, GWindowInit *pInit);
-void gwinLabelSetColor(GHandle gh, color_t color);
-void gwinLabelSetBgColor(GHandle gh, color_t bgColor);
-void gwinLabelSetFont(GHandle gh, font_t font);
-void gwinLabelSetText(GHandle gh, const char* text);
-void gwinLabelDraw(GHandle gh);
+GHandle gwinLabelCreate(GLabelWidget *widget, GWidgetInit *pInit);
#ifdef __cplusplus
}
diff --git a/include/gwin/options.h b/include/gwin/options.h
index cc164259..11ab7d44 100644
--- a/include/gwin/options.h
+++ b/include/gwin/options.h
@@ -69,6 +69,20 @@
#ifndef GWIN_NEED_CHECKBOX
#define GWIN_NEED_CHECKBOX FALSE
#endif
+ /**
+ * @brief Should image functions be included.
+ * @details Defaults to FALSE
+ */
+ #ifndef GWIN_NEED_IMAGE
+ #define GWIN_NEED_IMAGE FALSE
+ #endif
+ /**
+ * @brief Should label functions be included.
+ * @details Defaults to FALSE
+ */
+ #ifndef GWIN_NEED_LABEL
+ #define GWIN_NEED_LABEL FALSE
+ #endif
/**
* @}
*
diff --git a/src/gwin/gwin.c b/src/gwin/gwin.c
index 75f1b2d3..f080ac64 100644
--- a/src/gwin/gwin.c
+++ b/src/gwin/gwin.c
@@ -143,6 +143,10 @@ void gwinSetDefaultBgColor(color_t bgclr) {
void gwinSetDefaultFont(font_t font) {
defaultFont = font;
}
+
+ font_t gwinGetDefaultFont(void) {
+ return defaultFont;
+ }
#endif
/*-----------------------------------------------
diff --git a/src/gwin/label.c b/src/gwin/label.c
index 8c892217..7f8ab814 100644
--- a/src/gwin/label.c
+++ b/src/gwin/label.c
@@ -21,74 +21,80 @@
#include "gwin/class_gwin.h"
-#define widget(gh) ((GLabelWidget*)gh)
-
-static void _destroy(GWindowObject *gh) {
- (void)gh;
-
- return;
-}
-
-static void _redraw(GWindowObject *gh) {
- (void)gh;
-
- return;
-}
+#define widget(gh) ((GLabelWidget*)gh)
+#define GLABEL_FLG_WAUTO (GWIN_FIRST_CONTROL_FLAG<<0)
+#define GLABEL_FLG_HAUTO (GWIN_FIRST_CONTROL_FLAG<<1)
+
+static void gwinLabelDefaultDraw(GHandle gh) {
+ // if( check if auto flag is set )
+ // if( call current size != font size )
+ // gwinResize();
+
+ gdispFillString( widget(gh)->w.g.x,
+ widget(gh)->w.g.y,
+ widget(gh)->w.txt,
+ widget(gh)->w.g.font,
+ widget(gh)->w.g.color,
+ widget(gh)->w.g.bgcolor
+ );
-static void _afterClear(GWindowObject *gh) {
- (void)gh;
+ gdispFillArea( widget(gh)->w.g.x, widget(gh)->w.g.y, widget(gh)->w.g.width, widget(gh)->w.g.height, Green);
- return;
+ printf("Text: %s\r\n", widget(gh)->w.txt);
}
-static const gwinVMT labelVMT = {
- "Label", // The class name
- sizeof(GLabelWidget), // The object size
- _destroy, // The destroy routine
- 0, // The redraw routine
- _afterClear // The after-clear routine
+static const gwidgetVMT labelVMT = {
+ {
+ "Label", // The class name
+ sizeof(GLabelWidget), // The object size
+ _gwidgetDestroy, // The destroy routine
+ _gwidgetRedraw, // The redraw routine
+ 0, // The after-clear routine
+ },
+ gwinLabelDefaultDraw, // default drawing routine
+ {
+ 0, // Process mose down events (NOT USED)
+ 0, // Process mouse up events (NOT USED)
+ 0, // Process mouse move events (NOT USED)
+ },
+ {
+ 0, // No toggle role
+ 0, // Assign Toggles (NOT USED)
+ 0, // Get Toggles (NOT USED)
+ 0, // Process toggle off event (NOT USED)
+ 0, // Process toggle on event (NOT USED)
+ },
+ {
+ 0, // No dial roles
+ 0, // Assign Dials (NOT USED)
+ 0, // Get Dials (NOT USED)
+ 0, // Procees dial move events (NOT USED)
+ }
};
-GHandle gwinLabelCreate(GLabelWidget *widget, GWindowInit *pInit) {
- if (!(widget = (GLabelWidget *)_gwindowCreate(&widget->g, pInit, &labelVMT, 0)))
+GHandle gwinLabelCreate(GLabelWidget *widget, GWidgetInit *pInit) {
+ uint16_t flags = 0;
+
+ // auto assign width
+ if (pInit->g.width <= 0) {
+ flags |= GLABEL_FLG_WAUTO;
+ pInit->g.width = gdispGetStringWidth(pInit->text, gwinGetDefaultFont());
+ }
+
+ // auto assign height
+ if (pInit->g.height <= 0) {
+ flags |= GLABEL_FLG_HAUTO;
+ pInit->g.height = gdispGetFontMetric(gwinGetDefaultFont(), fontHeight);
+ }
+
+ if (!(widget = (GLabelWidget *)_gwidgetCreate(&widget->w, pInit, &labelVMT)))
return 0;
- widget->g.x = pInit->x;
- widget->g.y = pInit->y;
- widget->g.width = pInit->width;
- widget->g.height = pInit->height;
- gwinSetVisible((GHandle)widget, pInit->show);
+ gwinLabelDefaultDraw((GHandle)widget);
+ widget->w.g.flags |= flags;
return (GHandle)widget;
}
-void gwinLabelSetColor(GHandle gh, color_t color) {
- widget(gh)->g.color = color;
-}
-
-void gwinLabelSetBgColor(GHandle gh, color_t bgColor) {
- widget(gh)->g.bgcolor = bgColor;
-}
-
-void gwinLabelSetFont(GHandle gh, font_t font) {
- widget(gh)->g.font = font;
-}
-
-void gwinLabelSetText(GHandle gh, const char* text) {
- widget(gh)->text = text;
-
- gwinLabelDraw(gh);
-}
-
-void gwinLabelDraw(GHandle gh) {
- gdispFillString( widget(gh)->g.x,
- widget(gh)->g.y,
- widget(gh)->text,
- widget(gh)->g.font,
- widget(gh)->g.color,
- widget(gh)->g.bgcolor
- );
-}
-
#endif // GFX_USE_GWIN && GFX_NEED_LABEL