From f121997d53f772c67c55f0153d22fde735dbb9ef Mon Sep 17 00:00:00 2001 From: "kevin.larke" Date: Mon, 27 Apr 2020 12:31:10 -0400 Subject: [PATCH] cwUi.cpp,ui.js,ui.css,ui.cfg : Added row,col,panel div aliases. --- cwUi.cpp | 33 +++++++++++++++++++------ html/uiTest/css/ui.css | 13 +++++++--- html/uiTest/js/ui.js | 56 ++++++++++++++++++++++++++++++++++-------- html/uiTest/ui.cfg | 6 ++--- 4 files changed, 83 insertions(+), 25 deletions(-) diff --git a/cwUi.cpp b/cwUi.cpp index e327d56..f88e0f3 100644 --- a/cwUi.cpp +++ b/cwUi.cpp @@ -371,11 +371,13 @@ namespace cw // rc_t _createEleFromRsrsc( ui_t* p, ele_t* parentEle, const char* eleType, const object_t* srcObj, unsigned wsSessId ) { - rc_t rc = kOkRC; - object_t* co = nullptr; - ele_t* ele = nullptr; - char* eleName = nullptr; - object_t* o = srcObj->duplicate(); // duplicate the rsrc object so that we can modify it. + rc_t rc = kOkRC; + object_t* co = nullptr; + ele_t* ele = nullptr; + char* eleName = nullptr; + object_t* o = srcObj->duplicate(); // duplicate the rsrc object so that we can modify it. + const char* divAliasA[] = { "row","col","panel",nullptr }; + bool divAliasFl = false; if( !o->is_dict() ) return cwLogError(kSyntaxErrorRC,"All ui element resource records must be dictionaries."); @@ -401,12 +403,14 @@ namespace cw goto errLabel; } + // insert the UuId node if( o->insertPair("uuId",ele->uuId) == nullptr ) { rc = cwLogError(kOpFailRC,"The 'uuid' node insertion failed on UI element '%s'.",cwStringNullGuard(eleName)); goto errLabel; } + // Insert the appId node if( ele->appId != kInvalidId ) { if( o->insertPair("appId",ele->appId) == nullptr ) @@ -416,39 +420,52 @@ namespace cw } } + // Insert the parentId node if( o->insertPair("parentUuId",parentEle->uuId) == nullptr ) { rc = cwLogError(kOpFailRC,"The 'parentUuId' node insertion failed on UI element '%s'.",cwStringNullGuard(eleName)); goto errLabel; } - + + // Insert the 'op':'create' operation node if( o->insertPair("op","create") == nullptr ) { rc = cwLogError(kOpFailRC,"The 'op' node insertion failed on UI element '%s'.",cwStringNullGuard(eleName)); goto errLabel; } + // Insert the 'type':'' node if( o->insertPair("type",eleType) == nullptr ) { rc = cwLogError(kOpFailRC,"The 'eleType' node insertion failed on UI element '%s'.",cwStringNullGuard(eleName)); goto errLabel; } + // Convert the object to a JSON string if( o->to_string(p->buf,p->bufN) >= p->bufN ) { rc = cwLogError(kOpFailRC,"Conversion to JSON string failed on UI element '%s'.",cwStringNullGuard(eleName)); goto errLabel; } + // Send the JSON msg to the browser if((rc = _websockSend( p, wsSessId, p->buf )) != kOkRC ) { rc = cwLogError(rc,"The creation request send failed on UI element '%s'.", cwStringNullGuard(eleName)); goto errLabel; } - + + // is this element a 'div' alias? + for(unsigned i=0; divAliasA[i]!=nullptr; ++i) + if( textCompare(divAliasA[i],eleType) == 0 ) + { + divAliasFl = true; + break; + } + // if this element has a list of children then create them here - if( co != nullptr || textCompare(eleType,"div")==0 ) + if( co != nullptr || divAliasFl ) { // Note that 'div's need not have an explicit 'children' node. // Any child node of a 'div' with a dictionary as a value is a child control. diff --git a/html/uiTest/css/ui.css b/html/uiTest/css/ui.css index 9e383e5..39294f5 100644 --- a/html/uiTest/css/ui.css +++ b/html/uiTest/css/ui.css @@ -54,14 +54,21 @@ label { width: 50px; } -.panel { +.uiPanel { background-color: LightBlue; } -.row { - + +.uiRow { display: flex; flex-direction: row; align-items: center; background-color: LightBlue; } +.uiRow { + display: flex; + flex-direction: column; + align-items: center; + background-color: LightBlue; +} + diff --git a/html/uiTest/js/ui.js b/html/uiTest/js/ui.js index a0a7e52..eecde03 100644 --- a/html/uiTest/js/ui.js +++ b/html/uiTest/js/ui.js @@ -320,16 +320,6 @@ function ui_create_ctl( parent_ele, ele_type, label, d, dfltEleClassName ) return ui_create_ele( div_ele, ele_type, d, dfltEleClassName ); } -function ui_set_class_name( ele, d, dfltClassName ) -{ - if( d.hasOwnProperty("className") ) - ele.className = d.className; - else - ele.className = dfltClassName - - return ele -} - function ui_create_div( parent_ele, d ) { var div_ele = ui_create_ele( parent_ele, "div", d, "uiDiv" ); @@ -350,6 +340,40 @@ function ui_create_div( parent_ele, d ) return div_ele; } +function ui_create_panel_div( parent_ele, d ) +{ + d.type = "div" + var div_ele = ui_create_div( parent_ele, d ); + + if( !d.hasOwnProperty('className') ) + div_ele.className = "uiPanel" + + return div_ele +} + +function ui_create_row_div( parent_ele, d ) +{ + d.type = "div" + var div_ele = ui_create_div( parent_ele, d ); + + if( !d.hasOwnProperty('className') ) + div_ele.className = "uiPanel" + + return div_ele +} + +function ui_create_col_div( parent_ele, d ) +{ + d.type = "div" + var div_ele = ui_create_div( parent_ele, d ); + + if( !d.hasOwnProperty('className') ) + div_ele.className = "uiPanel" + + return div_ele +} + + function ui_create_title( parent_ele, d ) { return ui_create_ele( parent_ele, "label", d, "uiTitle" ); @@ -570,6 +594,18 @@ function ui_create( d ) ele = ui_create_div( parent_ele, d ) break; + case "panel": + ele = ui_create_panel_div( parent_ele, d ) + break; + + case "row": + ele = ui_create_row_div( parent_ele, d ) + break; + + case "col": + ele = ui_create_col_div( parent_ele, d ) + break; + case "title": ele = ui_create_title( parent_ele, d ) break; diff --git a/html/uiTest/ui.cfg b/html/uiTest/ui.cfg index e758fd4..d3fdc1e 100644 --- a/html/uiTest/ui.cfg +++ b/html/uiTest/ui.cfg @@ -3,14 +3,12 @@ parent: "uiDivId" - div: { + panel: { name: "panelDivId", - className: "panel", title: "My resource based panel", - div: { - className: "row", + row: { button:{ name: myBtn1Id, title:"Push Me" }, check:{ name: myCheck1Id, title:"Check Me" }, }