cwUI.h/cpp,ui.js,ui.css : Added 'corrupt' message.

This commit is contained in:
kevin 2021-12-29 21:43:56 -05:00
parent d6d3bbd5ed
commit f381a44c3c
6 changed files with 79 additions and 7 deletions

View File

@ -783,10 +783,7 @@ namespace cw
case 'd':
if((rc = string_to_number<double>(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);

View File

@ -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.

View File

@ -139,6 +139,10 @@ label {
background-color: PowderBlue;
}
.uiStringDisp {
width: 100%;
}
.uiSelected {
border: 1px solid blue;
}

View File

@ -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 )

View File

@ -139,6 +139,10 @@ label {
background-color: PowderBlue;
}
.uiSelected {
border: 1px solid red;
.uiStringDisp {
width: 100%;
}
.uiSelected {
border: 1px solid blue;
}

View File

@ -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 = ""