#define DEFAULT_ELETABLE_SIZE 64
#define BORDER_EVERYTHING 0
+// === IMPORTS ===
+extern tWidgetDef _widget_typedef_ELETYPE_IMAGE;
+extern tWidgetDef _widget_typedef_ELETYPE_BUTTON;
+extern tWidgetDef _widget_typedef_ELETYPE_TEXT;
+extern tWidgetDef _widget_typedef_ELETYPE_TEXTINPUT;
+extern tWidgetDef _widget_typedef_ELETYPE_SPACER;
+extern tWidgetDef _widget_typedef_ELETYPE_SUBWIN;
+
// === PROTOTYPES ===
int Renderer_Widget_Init(void);
tWindow *Renderer_Widget_Create(int Flags);
};
// --- Element callbacks
-tWidgetDef *gaWM_WidgetTypes[NUM_ELETYPES];
+tWidgetDef *gaWM_WidgetTypes[NUM_ELETYPES] = {
+ [ELETYPE_IMAGE] = &_widget_typedef_ELETYPE_IMAGE,
+ [ELETYPE_BUTTON] = &_widget_typedef_ELETYPE_BUTTON,
+ [ELETYPE_TEXT] = &_widget_typedef_ELETYPE_TEXT,
+ [ELETYPE_TEXTINPUT] = &_widget_typedef_ELETYPE_TEXTINPUT,
+ [ELETYPE_SPACER] = &_widget_typedef_ELETYPE_SPACER,
+ [ELETYPE_SUBWIN] = &_widget_typedef_ELETYPE_SUBWIN,
+ };
const int ciWM_NumWidgetTypes = sizeof(gaWM_WidgetTypes)/sizeof(gaWM_WidgetTypes[0]);
tWidgetDef gWidget_NullWidgetDef;
// === CODE ===
int Renderer_Widget_Init(void)
{
- int i;
WM_RegisterRenderer(&gRenderer_Widget);
- for(i = 0; i < ciWM_NumWidgetTypes; i ++)
+ for(int i = 0; i < ciWM_NumWidgetTypes; i ++)
{
if(gaWM_WidgetTypes[i] != NULL) continue;
}
gaWM_WidgetTypes[Type] = Ptr;
+ _SysDebug("Registered widget type %i '%s'", Type, Ptr->Name);
}
tWindow *Renderer_Widget_Create(int Flags)
*/
void Widget_UpdatePosition(tElement *Element)
{
- tElement *child;
int x, y;
if( Element->Flags & ELEFLAG_NORENDER ) return ;
y = Element->CachedY + Element->PaddingT;
// Update each child
- for(child = Element->FirstChild; child; child = child->NextSibling)
+ for(tElement *child = Element->FirstChild; child; child = child->NextSibling)
{
int newX, newY;
// Ignore elements that will not be rendered
*/
void Widget_UpdateMinDims(tElement *Element)
{
- tElement *child;
int minW, minH;
int nChildren;
minH = 0;
nChildren = 0;
- for(child = Element->FirstChild; child; child = child->NextSibling)
+ for( tElement *child = Element->FirstChild; child; child = child->NextSibling )
{
int cross;
tElement *Widget_GetElementByPos(tWidgetWin *Info, int X, int Y)
{
- tElement *ret, *next, *ele;
-
- next = &Info->RootElement;
- do
- {
+ tElement *ret;
+ tElement *next = &Info->RootElement;
+ // Scan down tree
+ do {
ret = next;
next = NULL;
- for(ele = ret->FirstChild; ele; ele = ele->NextSibling)
+ for(tElement *ele = ret->FirstChild; ele; ele = ele->NextSibling)
{
if(ele->Flags & ELEFLAG_NORENDER) continue;
if(X < ele->CachedX) continue;
{
if( Widget_GetElementById(Info, ID) )
return NULL;
+ if( Type >= NUM_ELETYPES ) {
+ return NULL;
+ }
+
+ _SysDebug("Widget Create #%i '%s' 0x%x",
+ ID, gaWM_WidgetTypes[Type]->Name, Flags);
// Create new element
tElement *new = calloc(sizeof(tElement), 1);
new->PaddingL = 2;
new->PaddingR = 2;
new->CachedX = -1;
-
+
if( gaWM_WidgetTypes[Type]->Init )
gaWM_WidgetTypes[Type]->Init(new);
if( gaWM_WidgetTypes[ele->Type]->UpdateText )
{
+ _SysDebug(" - calling handler");
gaWM_WidgetTypes[ele->Type]->UpdateText( ele, Msg->Text );
}
// else
struct sWidgetDef
{
+ const char *Name;
int Flags;
void (*Init)(tElement *Ele);
void (*Delete)(tElement *Ele);
extern void Widget_UpdateMinDims(tElement *Element);
extern void Widget_Fire(tElement *Element);
-#define DEFWIDGETTYPE(_type, _flags, _attribs...) \
-tWidgetDef _widget_typedef_##_type = {.Flags=(_flags),_attribs};\
+#define DEFWIDGETTYPE(_type, _name, _flags, _attribs...) \
+tWidgetDef _widget_typedef_##_type = {.Name=_name,.Flags=(_flags),_attribs};\
void _widget_set_##_type(void) __attribute__((constructor));\
-void _widget_set_##_type(void) { Widget_int_SetTypeDef(_type, &_widget_typedef_##_type);}
+void _widget_set_##_type(void) { _SysDebug("hai!\n"); Widget_int_SetTypeDef(_type, &_widget_typedef_##_type);}
#endif