[Add] Possibility for custom widgets.
This commit is contained in:
parent
6a12954b7b
commit
ef2bfd2052
@ -13,7 +13,8 @@ typedef enum WidgetType_ {
|
||||
WIDGET_TEXT,
|
||||
WIDGET_IMAGE,
|
||||
WIDGET_LIST,
|
||||
WIDGET_RECT
|
||||
WIDGET_RECT,
|
||||
WIDGET_CUST
|
||||
} WidgetType;
|
||||
|
||||
typedef enum WidgetStatus_ {
|
||||
@ -61,6 +62,10 @@ typedef struct Widget_ {
|
||||
glColour* colour; // Background colour.
|
||||
int border; // Border.
|
||||
} rct;
|
||||
// Widget cust.
|
||||
struct {
|
||||
void(*render) (double bx, double by);
|
||||
} cst;
|
||||
} dat;
|
||||
} Widget;
|
||||
|
||||
@ -234,6 +239,28 @@ void window_addRect(const unsigned int wid, const int x, const int y, const int
|
||||
else wgt->y = (double)y;
|
||||
}
|
||||
|
||||
void window_addCust(const unsigned int wid, const int x, const int y,
|
||||
const int w, const int h, char* name, void(*render) (double x, double y)) {
|
||||
|
||||
Window* wdw = window_wget(wid);
|
||||
Widget* wgt = window_newWidget(wdw);
|
||||
|
||||
// Generic.
|
||||
wgt->type = WIDGET_CUST;
|
||||
wgt->name = strdup(name);
|
||||
|
||||
// Specific.
|
||||
wgt->dat.cst.render = render;
|
||||
|
||||
// Position/size.
|
||||
wgt->w = (double)w;
|
||||
wgt->h = (double)h;
|
||||
if(x < 0) wgt->x = wdw->w - wgt->w + x;
|
||||
else wgt->x = (double) x;
|
||||
if(y < 0) wgt->y = wdw->h - wgt->h + y;
|
||||
else wgt->y = (double) y;
|
||||
}
|
||||
|
||||
// Return pointer to newly allocated widget.
|
||||
static Widget* window_newWidget(Window* w) {
|
||||
Widget* wgt = NULL;
|
||||
@ -630,6 +657,9 @@ static void window_render(Window* w) {
|
||||
case WIDGET_RECT:
|
||||
toolkit_renderRect(&w->widgets[i], x, y);
|
||||
break;
|
||||
case WIDGET_CUST:
|
||||
(*w->widgets[i].dat.cst.render)(x, y);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Focus widget.
|
||||
|
@ -30,6 +30,11 @@ void window_addRect(const unsigned int wid,
|
||||
const int w, const int h, // size.
|
||||
char* name, glColour* colour, int border); // Properties.
|
||||
|
||||
void window_addCust(const unsigned int wid,
|
||||
const int x, const int y, // Position.
|
||||
const int w, const int h, // Size.
|
||||
char* name, void(*render) (double x, double y));
|
||||
|
||||
// Popups and alerts.
|
||||
void toolkit_alert(const char* fmt, ...);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user