From 93f03f5f2ed915b37d64088123bcfdf301a25153 Mon Sep 17 00:00:00 2001 From: Torsten Dreyer Date: Wed, 15 Apr 2015 10:41:31 +0200 Subject: [PATCH] property browser: group radio-button elements This allows to better render bool properties --- src/Network/http/PropertyUriHandler.cxx | 34 ++++++++++++++----------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/Network/http/PropertyUriHandler.cxx b/src/Network/http/PropertyUriHandler.cxx index 74d4eaf2b..0d1849ad1 100644 --- a/src/Network/http/PropertyUriHandler.cxx +++ b/src/Network/http/PropertyUriHandler.cxx @@ -149,6 +149,23 @@ DOMElement * createHeader( const string & prefix, const string & propertyPath ) return root; } +static DOMNode * createLabeledRadioButton( const char * label, const std::string & name, bool checked ) +{ + DOMNode * root = new DOMNode("span"); + root->setAttribute( "class", "radiobutton-container" ); + + root->addChild( new DOMNode("span"))->addChild( new DOMTextElement(label) ); + DOMNode * radio = root->addChild(new DOMNode( "input" )) + ->setAttribute( "type", "radio" ) + ->setAttribute( "name", name ) + ->setAttribute( "value", label ); + + if( checked ) + radio->setAttribute( "checked", "checked" ); + + return root; +} + static DOMElement * renderPropertyValueElement( SGPropertyNode_ptr node ) { string value = node->getStringValue(); @@ -161,21 +178,8 @@ static DOMElement * renderPropertyValueElement( SGPropertyNode_ptr node ) if( node->getType() == simgear::props::BOOL ) { root = new DOMNode( "span" ); - root->addChild( new DOMNode("span"))->addChild( new DOMTextElement("true") ); - DOMNode * radio = root->addChild(new DOMNode( "input" )) - ->setAttribute( "type", "radio" ) - ->setAttribute( "name", node->getDisplayName() ) - ->setAttribute( "value", "true" ); - if( node->getBoolValue() ) - radio->setAttribute( "checked", "checked" ); - - root->addChild( new DOMNode("span"))->addChild( new DOMTextElement("false") ); - radio = root->addChild(new DOMNode( "input" )) - ->setAttribute( "type", "radio" ) - ->setAttribute( "name", node->getDisplayName() ) - ->setAttribute( "value", "false" ); - if( !node->getBoolValue() ) - radio->setAttribute( "checked", "checked" ); + root->addChild( createLabeledRadioButton( "true", node->getDisplayName(), node->getBoolValue() )); + root->addChild( createLabeledRadioButton( "false", node->getDisplayName(), !node->getBoolValue() )); } else if( len < 60 ) { root = new DOMNode( "input" ); -- 2.39.5