Last active
July 25, 2021 16:43
-
-
Save anaselli/9d14bcc313ec669a1c2cb48b4937f588 to your computer and use it in GitHub Desktop.
Example of Libyui Check Box Frame with AutoEnable property
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Copyright (c) 2021 Angelo Naselli <[email protected]> | |
Permission is hereby granted, free of charge, to any person obtaining | |
a copy of this software and associated documentation files (the | |
"Software"), to deal in the Software without restriction, including | |
without limitation the rights to use, copy, modify, merge, publish, | |
distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be | |
included in all copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | |
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | |
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | |
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR | |
THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
*/ | |
// CheckBoxFrame example with AutoEnable property usage. | |
// | |
// Compile with: | |
// | |
// g++ -I/usr/include/yui -lyui CheckBoxFrame.cc -o CheckBoxFrame | |
#define YUILogComponent "example" | |
#include <yui/YUILog.h> | |
#include <yui/YUI.h> | |
#include <yui/YWidgetFactory.h> | |
#include <yui/YDialog.h> | |
#include <yui/YLayoutBox.h> | |
#include <yui/YCheckBoxFrame.h> | |
#include <yui/YSelectionBox.h> | |
#include <yui/YLabel.h> | |
#include <yui/YPushButton.h> | |
#include <yui/YAlignment.h> | |
#include <yui/YEvent.h> | |
int main( int argc, char **argv ) | |
{ | |
YUILog::setLogFileName( "/tmp/libyui-examples.log" ); | |
YUILog::enableDebugLogging(); | |
YDialog * dialog = YUI::widgetFactory()->createPopupDialog(); | |
YLayoutBox * vbox = YUI::widgetFactory()->createVBox( dialog ); | |
YLayoutBox * hbox = YUI::widgetFactory()->createHBox( vbox ); | |
hbox->setWeight( YD_VERT, 1 ); | |
// create a disabled check box frame | |
YCheckBoxFrame *fr = YUI::widgetFactory()->createCheckBoxFrame( hbox, "List 1", false ); | |
// create an enabled check box frame | |
YCheckBoxFrame *fr1 = YUI::widgetFactory()->createCheckBoxFrame( hbox, "List 2", true ); | |
YSelectionBox * list1 = YUI::widgetFactory()->createSelectionBox( fr, "&List 1 content" ); | |
YItemCollection items; | |
items.push_back( new YItem( "Item 1" ) ); | |
items.push_back( new YItem( "Item 2" ) ); | |
items.push_back( new YItem( "Item 3" ) ); | |
items.push_back( new YItem( "Item 4" ) ); | |
items.push_back( new YItem( "Item 5" ) ); | |
items.push_back( new YItem( "Item 6" ) ); | |
list1->addItems( items ); | |
YSelectionBox * list2 = YUI::widgetFactory()->createSelectionBox( fr1, "&List 2 content" ); | |
YItemCollection items1; | |
items1.push_back( new YItem( "Item 10" ) ); | |
items1.push_back( new YItem( "Item 20" ) ); | |
items1.push_back( new YItem( "Item 30" ) ); | |
items1.push_back( new YItem( "Item 40" ) ); | |
items1.push_back( new YItem( "Item 50" ) ); | |
items1.push_back( new YItem( "Item 60" ) ); | |
list2->addItems( items1 ); | |
hbox = YUI::widgetFactory()->createHBox( vbox ); | |
YPushButton * InvertButton = YUI::widgetFactory()->createPushButton( hbox, "&Invert Auto Enable" ); | |
YLabel* invVal1 = YUI::widgetFactory()->createLabel( hbox, fr->invertAutoEnable() ? "List 1 - INV" : "List 1 - NOR"); | |
YLabel* invVal2 = YUI::widgetFactory()->createLabel( hbox, fr1->invertAutoEnable() ? "List 2 - INV" : "List 2 - NOR"); | |
YUI::widgetFactory()->createHSpacing( hbox, 0.1 ); | |
YPushButton * AutoEnableButton = YUI::widgetFactory()->createPushButton( hbox, "&Change Auto Enable value" ); | |
YLabel* autoVal1 = YUI::widgetFactory()->createLabel( hbox, fr->autoEnable() ? "List 1 - ENA" : "List 1 - DIS"); | |
YLabel* autoVal2 = YUI::widgetFactory()->createLabel( hbox, fr1->autoEnable() ? "List 2 - ENA" : "List 2 - DIS"); | |
YUI::widgetFactory()->createVSpacing( vbox, 0.3 ); | |
YAlignment * rightAlignment = YUI::widgetFactory()->createRight( vbox ); | |
YPushButton * closeButton = YUI::widgetFactory()->createPushButton( rightAlignment, "&Close" ); | |
// | |
// Event loop | |
// | |
while ( true ) | |
{ | |
YEvent * event = dialog->waitForEvent(); | |
if ( event ) | |
{ | |
if ( event->eventType() == YEvent::CancelEvent ) // window manager "close window" button | |
break; // leave event loop | |
YWidget * widget = event->widget(); | |
if ( widget == closeButton ) | |
break; // leave event loop | |
else if ( widget == InvertButton ) | |
{ | |
fr->setInvertAutoEnable(!fr->invertAutoEnable()); | |
fr1->setInvertAutoEnable(!fr1->invertAutoEnable()); | |
invVal1->setValue( fr->invertAutoEnable() ? "List 1 - INV" : "List 1 - NOR"); | |
invVal2->setValue( fr1->invertAutoEnable() ? "List 2 - INV" : "List 2 - NOR"); | |
} | |
else if ( widget == AutoEnableButton) | |
{ | |
fr->setAutoEnable(!fr->autoEnable()); | |
fr1->setAutoEnable(!fr1->autoEnable()); | |
autoVal1->setValue( fr->autoEnable() ? "List 1 - ENA" : "List 1 - DIS"); | |
autoVal2->setValue( fr1->autoEnable() ? "List 2 - ENA" : "List 2 - DIS"); | |
} | |
} | |
} | |
dialog->destroy(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment