Skip to content

Commit

Permalink
feat(gui): add default methods for widget prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-soft committed Jun 17, 2019
1 parent 7dd08d7 commit e68e8e5
Showing 1 changed file with 43 additions and 6 deletions.
49 changes: 43 additions & 6 deletions src/gui/widget_prototype.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
* POSSIBILITY OF SUCH DAMAGE.
*/


#include <string.h>
#include <stdlib.h>
#include <LCUI_Build.h>
Expand All @@ -38,12 +37,40 @@
static struct LCUI_WidgetPrototypeModule {
Dict *prototypes;
DictType dicttype;
LCUI_WidgetPrototypeRec empty_prototype;
LCUI_WidgetPrototypeRec default_prototype;
} self = { 0 };

static void Widget_DefaultMethod(LCUI_Widget w)
{
}

static void Widget_DefaultAttrSetter(LCUI_Widget w, const char *name,
const char *value)
{
}

static void Widget_DefaultTextSetter(LCUI_Widget w, const char *text)
{
}

static void Widget_DefaultPropertyBinder(LCUI_Widget w, const char *name,
LCUI_Object prop)
{
}

static void Widget_DefaultResizer(LCUI_Widget w, float *width, float *height)
{
}

static void Widget_DefaultPainter(LCUI_Widget w, LCUI_PaintContext paint,
LCUI_WidgetActualStyle style)
{
}

static void DeletePrototype(void *privdata, void *data)
{
LCUI_WidgetPrototype proto = data;

free(proto->name);
free(proto);
}
Expand All @@ -53,6 +80,15 @@ void LCUIWidget_InitPrototype(void)
self.dicttype = DictType_StringKey;
self.dicttype.valDestructor = DeletePrototype;
self.prototypes = Dict_Create(&self.dicttype, NULL);
self.default_prototype.init = Widget_DefaultMethod;
self.default_prototype.refresh = Widget_DefaultMethod;
self.default_prototype.destroy = Widget_DefaultMethod;
self.default_prototype.update = Widget_DefaultMethod;
self.default_prototype.runtask = Widget_DefaultMethod;
self.default_prototype.setattr = Widget_DefaultAttrSetter;
self.default_prototype.settext = Widget_DefaultTextSetter;
self.default_prototype.bindprop = Widget_DefaultPropertyBinder;
self.default_prototype.autosize = Widget_DefaultResizer;
}

void LCUIWidget_FreePrototype(void)
Expand All @@ -69,6 +105,7 @@ LCUI_WidgetPrototype LCUIWidget_NewPrototype(const char *name,
const char *parent_name)
{
LCUI_WidgetPrototype proto;

if (Dict_FetchValue(self.prototypes, name)) {
return NULL;
}
Expand All @@ -80,10 +117,10 @@ LCUI_WidgetPrototype LCUIWidget_NewPrototype(const char *name,
*proto = *parent;
proto->proto = parent;
} else {
*proto = self.empty_prototype;
*proto = self.default_prototype;
}
} else {
*proto = self.empty_prototype;
*proto = self.default_prototype;
}
proto->name = strdup2(name);
if (Dict_Add(self.prototypes, proto->name, proto) == 0) {
Expand Down Expand Up @@ -140,8 +177,8 @@ void *Widget_GetData(LCUI_Widget widget, LCUI_WidgetPrototype proto)
return NULL;
}

void *Widget_AddData(LCUI_Widget widget,
LCUI_WidgetPrototype proto, size_t data_size)
void *Widget_AddData(LCUI_Widget widget, LCUI_WidgetPrototype proto,
size_t data_size)
{
void *data;
LCUI_WidgetDataEntryRec *list;
Expand Down

0 comments on commit e68e8e5

Please sign in to comment.