diff --git a/README.md b/README.md index c8336c4..2e86d2b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # 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. - 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. diff --git a/cwUi.cpp b/cwUi.cpp index 7f4166d..09a0c99 100644 --- a/cwUi.cpp +++ b/cwUi.cpp @@ -8,6 +8,7 @@ #include "cwUi.h" #include "cwText.h" #include "cwNumericConvert.h" +#include "cwObject.h" namespace cw { @@ -173,7 +174,33 @@ namespace cw return rc; } - + + 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 ) { rc_t rc = kOkRC; @@ -427,7 +454,51 @@ const char* cw::ui::findElementJsId( handle_t h, unsigned uuId ) return _findEleJsId(p,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 ) { return _createOneEle( _handleToPtr(h), uuIdRef, "div", parentUuId, jsId, appId, clas, title ); } diff --git a/cwUi.h b/cwUi.h index 119fa72..63a3c10 100644 --- a/cwUi.h +++ b/cwUi.h @@ -70,7 +70,9 @@ namespace cw unsigned findElementUuId( handle_t h, unsigned parentUuId, const char* jsId ); unsigned findElementUuId( handle_t h, unsigned parentUuId, unsigned appId ); 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 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 ); diff --git a/html/uiTest/ui.cfg b/html/uiTest/ui.cfg index 967d528..5c19de5 100644 --- a/html/uiTest/ui.cfg +++ b/html/uiTest/ui.cfg @@ -6,11 +6,8 @@ children: { - button:{ id:myBtnId, title:"Push Me" }, - check:{ id:myCheckId, title:"Check Me" }, - select:{ id:mySelectId, title:"Selector", values: [ myId0:"Option 0", myId2:"Option 1", myId3:"Option 3" ] } - - } + button:{ id:myBtnId, title:"Push Me" }, + check:{ id:myCheckId, title:"Check Me" }, } }