cwUi.h/cpp : Added shell for functions createFromFile(), createFromText().
This commit is contained in:
parent
e4328c950b
commit
9d1170b1eb
@ -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.
|
||||
|
73
cwUi.cpp
73
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 ); }
|
||||
|
||||
|
4
cwUi.h
4
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 );
|
||||
|
@ -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" },
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user