From 85eaa17d79ce4eb399470a0a20d6dc59f9b07c43 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sun, 18 May 2014 01:57:28 +1000 Subject: Add widget hide, show, and text setting functions. --- lib/skang.lua | 10 ++++++++-- src/GuiLua/GuiLua.c | 39 +++++++++++++++++++++++++++++++++++++-- src/libraries/winFang.c | 10 ++++++++++ src/libraries/winFang.h | 2 ++ 4 files changed, 57 insertions(+), 4 deletions(-) diff --git a/lib/skang.lua b/lib/skang.lua index 90079ad..e44d4bc 100644 --- a/lib/skang.lua +++ b/lib/skang.lua @@ -1031,14 +1031,18 @@ local widgets = {} --thingasm{widgets, 'window', 'The window.', types='userdata'} thingasm{widgets, 'W', 'Holds all the widgets', types='Keyed'} widgets.W{'Cwidget', 'The widget.', types='userdata'} -widgets.W{'action,a', 'The action for the widget.', 'nada', types='string'} +widgets.W{'action,a', 'The action for the widget.', 'nada()', types='string'} +widgets.W{'text,t', 'The text for the widget.', '', types='string'} local aIsValid = function (self, parent) local result = Thing.isValid(self, parent) if result then local value = parent[self.names[1] ] + if 'userdata' == type(parent.Cwidget) then --print('NEW ACTION - ' .. self.names[1] .. ' = ' .. value .. ' ' .. type(parent.Cwidget)) - action(parent.Cwidget, value) + if ('action' == self.names[1]) and ('nada()' ~= value) then action(parent.Cwidget, value) end + if ('text' == self.names[1]) and ('' ~= value) then text (parent.Cwidget, value) end + end end return result end @@ -1095,6 +1099,8 @@ window = function(w, h, title, name) win = copy(widgets, name) local wMum, wThingy = getStuffed(win.W, 'a') wThingy.isValid = aIsValid + local wMum, wThingy = getStuffed(win.W, 't') + wThingy.isValid = aIsValid win.window = Cwindow(caller, w, h, title, name) return win end diff --git a/src/GuiLua/GuiLua.c b/src/GuiLua/GuiLua.c index ae9af48..5a30ff9 100644 --- a/src/GuiLua/GuiLua.c +++ b/src/GuiLua/GuiLua.c @@ -216,6 +216,37 @@ static int colour(lua_State *L) return 0; } +static int widHide(lua_State *L) +{ + Widget *wid = lua_touserdata(L, 1); + + if (wid && strcmp(wid->magic, "Widget") == 0) + widgetHide(wid); + return 0; +} + +static int widShow(lua_State *L) +{ + Widget *wid = lua_touserdata(L, 1); + + if (wid && strcmp(wid->magic, "Widget") == 0) + widgetShow(wid); + return 0; +} + +static int text(lua_State *L) +{ + Widget *wid = lua_touserdata(L, 1); + char *text = ""; + + pull_lua(L, 2, "$", &text); + if (wid && strcmp(wid->magic, "Widget") == 0) + { + elm_object_text_set(wid->obj, text); + } + return 0; +} + /* userdata vs light userdata Lua wants to allocate the memory for userdata itself. Light user data an actual pointer. @@ -358,11 +389,15 @@ PD("GuiLua 2"); // push_lua(L, "@ ( = $ $ & $ )", skang, THINGASM, skang, "widget", "Create a widget.", widget, "userdata,string,string,number,number,number,number"); push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "widget", "Create a widget.", widget, 0); PD("GuiLua 3"); - push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "action", "Add an action to a widget.", action, 0); + push_lua(L, "@ ( = $ $ & $ )", skang, THINGASM, skang, "action", "Add an action to a widget.", action, "string", 0); push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "Colour", "Change widget colours.", colour, 0); + push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "hide", "Hide a widget.", widHide, 0); + push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "show", "Show a widget.", widShow, 0); + push_lua(L, "@ ( = $ $ & $ )", skang, THINGASM, skang, "text", "Set the text for a widget.", text, "string", 0); + push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "loopWindow", "Run our windows main loop.", loopWindow, 0); push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "quit", "Quit, exit, remove thyself.", quit, 0); - push_lua(L, "@ ( = $ $ & $ )", skang, THINGASM, skang, "closeWindow", "Closes a window.", closeWindow, "userdata", 0); // TODO - closeWindow, "userdata"); + push_lua(L, "@ ( = $ $ & $ )", skang, THINGASM, skang, "closeWindow", "Closes a window.", closeWindow, "userdata", 0); // TODO - closeWindow, "userdata"); // A test of the array building stuff. push_lua(L, "@ ( { = $ $ % $widget !required } )", skang, THINGASM, skang, "wibble", "It's wibbly!", 1, "'edit', 'The wibblinator:', 1, 1, 10, 50", 1, 0); diff --git a/src/libraries/winFang.c b/src/libraries/winFang.c index dc5188a..0d1622d 100644 --- a/src/libraries/winFang.c +++ b/src/libraries/winFang.c @@ -199,6 +199,16 @@ void winFangShow(winFang *win) evas_object_show(win->hand[i]); } +void widgetHide(Widget *wid) +{ + evas_object_hide(wid->obj); +} + +void widgetShow(Widget *wid) +{ + evas_object_show(wid->obj); +} + winFang *winFangAdd(winFang *parent, int x, int y, int w, int h, char *title, char *name, EPhysics_World *world) { winFang *result; diff --git a/src/libraries/winFang.h b/src/libraries/winFang.h index bae3082..f3f4170 100644 --- a/src/libraries/winFang.h +++ b/src/libraries/winFang.h @@ -94,6 +94,8 @@ void HamrTime(void *elm_main, char *domain); winFang *winFangAdd(winFang *parent, int x, int y, int w, int h, char *title, char *name, EPhysics_World *world); void winFangHide(winFang *win); void winFangShow(winFang *win); +void widgetHide(Widget *wid); +void widgetShow(Widget *wid); void winFangCalcMinSize(winFang *win); void winFangDel(winFang *win); -- cgit v1.1