label work in progress - not working anymore
parent
ad57ab7967
commit
3f80e1f89d
|
@ -48,7 +48,7 @@ typedef uint16_t GEventType;
|
||||||
typedef union GEvent_u {
|
typedef union GEvent_u {
|
||||||
GEventType type; // The type of this event
|
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.
|
char pad[GEVENT_MAXIMUM_SIZE]; // This is here to allow static initialisation of GEventObject's in the application.
|
||||||
} GEvent;
|
} GEvent;
|
||||||
|
|
||||||
// A special callback function
|
// A special callback function
|
||||||
typedef void (*GEventCallbackFn)(void *param, GEvent *pe);
|
typedef void (*GEventCallbackFn)(void *param, GEvent *pe);
|
||||||
|
|
|
@ -129,8 +129,16 @@ extern "C" {
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
void gwinSetDefaultFont(font_t font);
|
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
|
* Base functions
|
||||||
|
|
|
@ -31,9 +31,7 @@
|
||||||
|
|
||||||
// An label window
|
// An label window
|
||||||
typedef struct GLabelWidget_t {
|
typedef struct GLabelWidget_t {
|
||||||
GWindowObject g;
|
GWidgetObject w;
|
||||||
|
|
||||||
const char* text;
|
|
||||||
} GLabelWidget;
|
} GLabelWidget;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -51,12 +49,7 @@ extern "C" {
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
GHandle gwinLabelCreate(GLabelWidget *widget, GWindowInit *pInit);
|
GHandle gwinLabelCreate(GLabelWidget *widget, GWidgetInit *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);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,20 @@
|
||||||
#ifndef GWIN_NEED_CHECKBOX
|
#ifndef GWIN_NEED_CHECKBOX
|
||||||
#define GWIN_NEED_CHECKBOX FALSE
|
#define GWIN_NEED_CHECKBOX FALSE
|
||||||
#endif
|
#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
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*
|
*
|
||||||
|
|
|
@ -143,6 +143,10 @@ void gwinSetDefaultBgColor(color_t bgclr) {
|
||||||
void gwinSetDefaultFont(font_t font) {
|
void gwinSetDefaultFont(font_t font) {
|
||||||
defaultFont = font;
|
defaultFont = font;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
font_t gwinGetDefaultFont(void) {
|
||||||
|
return defaultFont;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*-----------------------------------------------
|
/*-----------------------------------------------
|
||||||
|
|
120
src/gwin/label.c
120
src/gwin/label.c
|
@ -21,74 +21,80 @@
|
||||||
|
|
||||||
#include "gwin/class_gwin.h"
|
#include "gwin/class_gwin.h"
|
||||||
|
|
||||||
#define widget(gh) ((GLabelWidget*)gh)
|
#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 _destroy(GWindowObject *gh) {
|
static void gwinLabelDefaultDraw(GHandle gh) {
|
||||||
(void)gh;
|
// if( check if auto flag is set )
|
||||||
|
// if( call current size != font size )
|
||||||
|
// gwinResize();
|
||||||
|
|
||||||
return;
|
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
|
||||||
|
);
|
||||||
|
|
||||||
|
gdispFillArea( widget(gh)->w.g.x, widget(gh)->w.g.y, widget(gh)->w.g.width, widget(gh)->w.g.height, Green);
|
||||||
|
|
||||||
|
printf("Text: %s\r\n", widget(gh)->w.txt);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _redraw(GWindowObject *gh) {
|
static const gwidgetVMT labelVMT = {
|
||||||
(void)gh;
|
{
|
||||||
|
"Label", // The class name
|
||||||
return;
|
sizeof(GLabelWidget), // The object size
|
||||||
}
|
_gwidgetDestroy, // The destroy routine
|
||||||
|
_gwidgetRedraw, // The redraw routine
|
||||||
static void _afterClear(GWindowObject *gh) {
|
0, // The after-clear routine
|
||||||
(void)gh;
|
},
|
||||||
|
gwinLabelDefaultDraw, // default drawing routine
|
||||||
return;
|
{
|
||||||
}
|
0, // Process mose down events (NOT USED)
|
||||||
|
0, // Process mouse up events (NOT USED)
|
||||||
static const gwinVMT labelVMT = {
|
0, // Process mouse move events (NOT USED)
|
||||||
"Label", // The class name
|
},
|
||||||
sizeof(GLabelWidget), // The object size
|
{
|
||||||
_destroy, // The destroy routine
|
0, // No toggle role
|
||||||
0, // The redraw routine
|
0, // Assign Toggles (NOT USED)
|
||||||
_afterClear // The after-clear routine
|
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) {
|
GHandle gwinLabelCreate(GLabelWidget *widget, GWidgetInit *pInit) {
|
||||||
if (!(widget = (GLabelWidget *)_gwindowCreate(&widget->g, pInit, &labelVMT, 0)))
|
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;
|
return 0;
|
||||||
|
|
||||||
widget->g.x = pInit->x;
|
gwinLabelDefaultDraw((GHandle)widget);
|
||||||
widget->g.y = pInit->y;
|
widget->w.g.flags |= flags;
|
||||||
widget->g.width = pInit->width;
|
|
||||||
widget->g.height = pInit->height;
|
|
||||||
gwinSetVisible((GHandle)widget, pInit->show);
|
|
||||||
|
|
||||||
return (GHandle)widget;
|
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
|
#endif // GFX_USE_GWIN && GFX_NEED_LABEL
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue