From f381a44c3c2c48bf189a3e7398244bd6d7e7af94 Mon Sep 17 00:00:00 2001 From: kevin Date: Wed, 29 Dec 2021 21:43:56 -0500 Subject: [PATCH] cwUI.h/cpp,ui.js,ui.css : Added 'corrupt' message. --- cwUi.cpp | 46 +++++++++++++++++++++++++++++++++----- cwUiDecls.h | 1 + html/preset_sel/css/ui.css | 4 ++++ html/preset_sel/js/ui.js | 9 ++++++++ html/uiTest/css/ui.css | 8 +++++-- html/uiTest/js/ui.js | 18 +++++++++++++++ 6 files changed, 79 insertions(+), 7 deletions(-) diff --git a/cwUi.cpp b/cwUi.cpp index e8e1511..db1bb27 100644 --- a/cwUi.cpp +++ b/cwUi.cpp @@ -783,10 +783,7 @@ namespace cw case 'd': if((rc = string_to_number(s,valueRef.u.d)) == kOkRC ) - { valueRef.tid = kDoubleTId; - printf("value:%f\n",valueRef.u.d); - } break; case 's': @@ -811,6 +808,36 @@ namespace cw return ele; } + ele_t* _parse_corrupt_msg( ui_t* p, const char* msg ) + { + ele_t* ele = nullptr; + unsigned eleUuId = kInvalidId; + + if( msg == nullptr ) + { + cwLogWarning("Empty 'corrupt' message received from UI."); + return nullptr; + } + + // + if( sscanf(msg, "corrupt %i ",&eleUuId) != 1 ) + { + cwLogError(kSyntaxErrorRC,"Invalid 'corrupt' message from UI: '%s'.", msg ); + goto errLabel; + } + + // locate the element record + if((ele = _uuIdToEle( p, eleUuId )) == nullptr ) + { + cwLogError(kInvalidIdRC,"UI message elment not found."); + goto errLabel; + } + + errLabel: + + return ele; + } + ele_t* _parse_click_msg( ui_t* p, const char* msg ) { ele_t* ele = nullptr; @@ -912,6 +939,7 @@ namespace cw { kConnectOpId, "connect" }, { kInitOpId, "init" }, { kValueOpId, "value" }, + { kCorruptOpId, "corrupt" }, { kClickOpId, "click" }, { kSelectOpId, "select" }, { kEchoOpId, "echo" }, @@ -935,7 +963,7 @@ namespace cw if( p->sendCbFunc != nullptr ) { const char* mFmt = "{ \"op\":\"%s\", \"uuId\":%i, \"value\":%s }"; - const int mbufN = 128; + const int mbufN = 512; char vbuf[vbufN]; char mbuf[mbufN]; @@ -1182,6 +1210,14 @@ cw::rc_t cw::ui::onReceive( handle_t h, unsigned wsSessId, const void* msg, unsi } break; + case kCorruptOpId: + if((ele = _parse_corrupt_msg(p, (const char*)msg )) == nullptr ) + cwLogError(kOpFailRC,"UI 'corrupt' message parse failed."); + else + p->uiCbFunc( p->uiCbArg, wsSessId, opId, ele->logical_parent->appId, ele->uuId, ele->appId, ele->chanId, &value ); + break; + + case kClickOpId: if((ele = _parse_click_msg(p, (const char*)msg )) == nullptr ) cwLogError(kOpFailRC,"UI 'click' message parse failed."); @@ -1512,7 +1548,7 @@ cw::rc_t cw::ui::setLogLine( handle_t h, unsigned uuId, const char* text ) s[sn-1] = 0; - printf("%s %s\n",text,s); + //printf("%s %s\n",text,s); rc = sendValueString(h,uuId,s); diff --git a/cwUiDecls.h b/cwUiDecls.h index 12fd8b8..963d159 100644 --- a/cwUiDecls.h +++ b/cwUiDecls.h @@ -17,6 +17,7 @@ namespace cw kConnectOpId, // A new remote user interface was connected kInitOpId, // A remote user interface instance was created and is available. It needs to be updated with the current state of the UI from the server. kValueOpId, // The value of a remote user interface control changed. Send this value to the application engine. + kCorruptOpId, // The value of the remote user interface is invalid or corrupt. kClickOpId, // A element on a remote user interface was clicked. kSelectOpId, // An element on a remote user interface was is 'selected' or 'deselected'. kEchoOpId, // A remote user interface is requesting an application engine value. The the current value of a ui element must be sent to the remote UI. diff --git a/html/preset_sel/css/ui.css b/html/preset_sel/css/ui.css index 1652448..7c98619 100644 --- a/html/preset_sel/css/ui.css +++ b/html/preset_sel/css/ui.css @@ -139,6 +139,10 @@ label { background-color: PowderBlue; } +.uiStringDisp { + width: 100%; +} + .uiSelected { border: 1px solid blue; } diff --git a/html/preset_sel/js/ui.js b/html/preset_sel/js/ui.js index 6b9de29..b704c51 100644 --- a/html/preset_sel/js/ui.js +++ b/html/preset_sel/js/ui.js @@ -232,6 +232,11 @@ function ui_send_value( ele, typeId, value ) ws_send("value " + ele.id + " " + typeId + " : " + value) } +function ui_send_corrupt_state( ele ) +{ + ws_send("corrupt " + ele.id) +} + function ui_send_bool_value( ele, value ) { ui_send_value(ele,'b',value); } function ui_send_int_value( ele, value ) { ui_send_value(ele,'i',value); } function ui_send_float_value( ele, value ) { ui_send_value(ele,'d',value); } @@ -621,7 +626,10 @@ function _ui_send_number( ele ) val = Number.parseFloat(ele.value) if( !(ele.minValue<=val && val<=ele.maxValue)) + { ele.style.borderColor = "red" + ui_send_corrupt_state(ele) + } else { ele.style.borderColor = "" @@ -755,6 +763,7 @@ function ui_create_number_display( parent_ele, d ) } return ele; + } function ui_create_text_display( parent_ele, d ) diff --git a/html/uiTest/css/ui.css b/html/uiTest/css/ui.css index aa44187..7c98619 100644 --- a/html/uiTest/css/ui.css +++ b/html/uiTest/css/ui.css @@ -139,6 +139,10 @@ label { background-color: PowderBlue; } -.uiSelected { - border: 1px solid red; +.uiStringDisp { + width: 100%; +} + +.uiSelected { + border: 1px solid blue; } diff --git a/html/uiTest/js/ui.js b/html/uiTest/js/ui.js index c377c58..01d26f1 100644 --- a/html/uiTest/js/ui.js +++ b/html/uiTest/js/ui.js @@ -232,6 +232,11 @@ function ui_send_value( ele, typeId, value ) ws_send("value " + ele.id + " " + typeId + " : " + value) } +function ui_send_corrupt_state( ele ) +{ + ws_send("corrupt " + ele.id) +} + function ui_send_bool_value( ele, value ) { ui_send_value(ele,'b',value); } function ui_send_int_value( ele, value ) { ui_send_value(ele,'i',value); } function ui_send_float_value( ele, value ) { ui_send_value(ele,'f',value); } @@ -304,6 +309,11 @@ function ui_create_ele( parent_ele, ele_type, d, dfltClassName ) else ele.className = dfltClassName; + if(d.hasOwnProperty('addClassName') ) + { + ele.className += " " + d.addClassName + } + if(d.hasOwnProperty('appId')) ele.appId = d.appId; else @@ -312,11 +322,16 @@ function ui_create_ele( parent_ele, ele_type, d, dfltClassName ) if( d.hasOwnProperty('clickable') ) ui_set_clickable( ele, d.clickable ); + if( d.hasOwnProperty('enable') ) + ui_set_enable( ele, d.enable ) + //console.log("Created: " + ele_type + " parent:" + d.parentUuId + " id:" + ele.id + " appId:" + ele.appId) parent_ele.appendChild(ele); + + } return ele } @@ -604,7 +619,10 @@ function _ui_send_number( ele ) val = Number.parseFloat(ele.value) if( !(ele.minValue<=val && val<=ele.maxValue)) + { ele.style.borderColor = "red" + ui_send_corrupt_state(ele) + } else { ele.style.borderColor = ""