cwUi.h/cpp : Added shell for functions createFromFile(), createFromText().

This commit is contained in:
kevin.larke 2020-03-25 11:35:37 -04:00
parent e4328c950b
commit 9d1170b1eb
4 changed files with 78 additions and 7 deletions

View File

@ -1,6 +1,7 @@
# To Do # To Do
- UI needs a special UUID (not kInvalidId) to specify the 'root' UI element. See note in cwUi._createFromObj()
- Look at 'BUG' warnings in cwNumericConvert.h. - Look at 'BUG' warnings in cwNumericConvert.h.
- cwObject must be able to parse without dynamic memory allocation into a fixed buffer - cwObject must be able to parse without dynamic memory allocation into a fixed buffer
- cwObject must be able to be composed without dynamic memory allocation or from a fixed buffer. - cwObject must be able to be composed without dynamic memory allocation or from a fixed buffer.

View File

@ -8,6 +8,7 @@
#include "cwUi.h" #include "cwUi.h"
#include "cwText.h" #include "cwText.h"
#include "cwNumericConvert.h" #include "cwNumericConvert.h"
#include "cwObject.h"
namespace cw namespace cw
{ {
@ -174,6 +175,32 @@ namespace cw
} }
rc_t _createFromObj( ui_t* p, object_t* o, unsigned parentUuId )
{
rc_t rc = kOkRC;
object_t* pid;
// BUG BUG BUG - if kInvalidId is used both to indicate a NULL valid
// and the root object then there is no way to override the parent
// that is coded into the file with the root object. A special
// rootId needs to be created.
if((pid = o->find("parent",false)) != nullptr && parentUuId == kInvalidId )
{
// get the parent JS id from the cfg object
// get the parent uuid from the JS id (verify that there is no ambiguity)
// delete the 'parent' pair
}
// form the msg string
// send the msg string
return rc;
}
ele_t* _parse_value_msg( ui_t* p, value_t& valueRef, const char* msg ) ele_t* _parse_value_msg( ui_t* p, value_t& valueRef, const char* msg )
{ {
rc_t rc = kOkRC; rc_t rc = kOkRC;
@ -428,6 +455,50 @@ const char* cw::ui::findElementJsId( handle_t h, unsigned uuId )
} }
cw::rc_t cw::ui::createFromFile( handle_t h, const char* fn, unsigned parentUuId)
{
ui_t* p = _handleToPtr(h);
rc_t rc = kOkRC;
object_t* o = nullptr;
if((rc = objectFromFile( fn, o )) != kOkRC )
goto errLabel;
if((rc = _createFromObj( p, o, parentUuId )) != kOkRC )
goto errLabel;
errLabel:
if(rc != kOkRC )
rc = cwLogError(rc,"UI from configuration the file '%s' failed.", cwStringNullGuard(fn));
if( o != nullptr )
o->free();
return rc;
}
cw::rc_t cw::ui::createFromText( handle_t h, const char* text, unsigned parentUuId)
{
ui_t* p = _handleToPtr(h);
rc_t rc = kOkRC;
object_t* o = nullptr;
if((rc = objectFromString( text, o )) != kOkRC )
goto errLabel;
if((rc = _createFromObj( p, o, parentUuId )) != kOkRC )
goto errLabel;
errLabel:
if(rc != kOkRC )
rc = cwLogError(rc,"UI from configuration the string '%s' failed.", cwStringNullGuard(text));
if( o != nullptr )
o->free();
return rc;
}
cw::rc_t cw::ui::createDiv( handle_t h, unsigned& uuIdRef, unsigned parentUuId, const char* jsId, unsigned appId, const char* clas, const char* title ) cw::rc_t cw::ui::createDiv( handle_t h, unsigned& uuIdRef, unsigned parentUuId, const char* jsId, unsigned appId, const char* clas, const char* title )
{ return _createOneEle( _handleToPtr(h), uuIdRef, "div", parentUuId, jsId, appId, clas, title ); } { return _createOneEle( _handleToPtr(h), uuIdRef, "div", parentUuId, jsId, appId, clas, title ); }

2
cwUi.h
View File

@ -71,6 +71,8 @@ namespace cw
unsigned findElementUuId( handle_t h, unsigned parentUuId, unsigned appId ); unsigned findElementUuId( handle_t h, unsigned parentUuId, unsigned appId );
const char* findElementJsId( handle_t h, unsigned uuId ); const char* findElementJsId( handle_t h, unsigned uuId );
rc_t createFromFile( handle_t h, const char* fn, unsigned parentUuId=kInvalidId);
rc_t createFromText( handle_t h, const char* text, unsigned parentUuId=kInvalidId);
rc_t createDiv( handle_t h, unsigned& uuIdRef, unsigned parentUuId, const char* jsId, unsigned appId, const char* clas, const char* title ); rc_t createDiv( handle_t h, unsigned& uuIdRef, unsigned parentUuId, const char* jsId, unsigned appId, const char* clas, const char* title );
rc_t createTitle( handle_t h, unsigned& uuIdRef, unsigned parentUuId, const char* jsId, unsigned appId, const char* clas, const char* title ); rc_t createTitle( handle_t h, unsigned& uuIdRef, unsigned parentUuId, const char* jsId, unsigned appId, const char* clas, const char* title );
rc_t createButton( handle_t h, unsigned& uuIdRef, unsigned parentUuId, const char* jsId, unsigned appId, const char* clas, const char* title ); rc_t createButton( handle_t h, unsigned& uuIdRef, unsigned parentUuId, const char* jsId, unsigned appId, const char* clas, const char* title );

View File

@ -8,9 +8,6 @@
button:{ id:myBtnId, title:"Push Me" }, button:{ id:myBtnId, title:"Push Me" },
check:{ id:myCheckId, title:"Check Me" }, check:{ id:myCheckId, title:"Check Me" },
select:{ id:mySelectId, title:"Selector", values: [ myId0:"Option 0", myId2:"Option 1", myId3:"Option 3" ] }
}
} }
} }