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