diff --git a/ChangeLog b/ChangeLog index d90344a2..c1d00eda 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,8 @@ 2018-12-15 Markus Gans * Use of the C++11 auto specifier in the program code * Code reduction by using of Range-based for loop + * The example program for video attributes now replaces + the switch statement with a vector of lambda expressions 2018-12-09 Markus Gans * Better handling of the scrollbar maximum diff --git a/examples/term-attributes.cpp b/examples/term-attributes.cpp index e6455a7c..ddb58d4a 100644 --- a/examples/term-attributes.cpp +++ b/examples/term-attributes.cpp @@ -20,6 +20,7 @@ * . * ***********************************************************************/ +#include #include @@ -405,67 +406,32 @@ void AttribDemo::draw() // test alternate character set printAltCharset(); - for (int y = 0; y < int(getParentWidget()->getHeight()) - 7; y++) + std::vector > effect { - setPrintPos (1, 2 + y); + [&] { printDim(); }, + [&] { printNormal(); }, + [&] { printBold(); }, + [&] { printBoldDim(); }, + [&] { printItalic(); }, + [&] { printUnderline(); }, + [&] { printDblUnderline(); }, + [&] { printCrossesOut(); }, + [&] { printBlink(); }, + [&] { printReverse(); }, + [&] { printStandout(); }, + [&] { printInvisible(); }, + [&] { printProtected(); }, + }; + + for (std::size_t y = 0; y < getParentWidget()->getHeight() - 7; y++) + { + setPrintPos (1, 2 + int(y)); if ( ! isMonochron() ) setColor (wc.label_fg, wc.label_bg); - switch (y) - { - case 0: - printDim(); - break; - - case 1: - printNormal(); - break; - - case 2: - printBold(); - break; - - case 3: - printBoldDim(); - break; - - case 4: - printItalic(); - break; - - case 5: - printUnderline(); - break; - - case 6: - printDblUnderline(); - break; - - case 7: - printCrossesOut(); - break; - - case 8: - printBlink(); - break; - - case 9: - printReverse(); - break; - - case 10: - printStandout(); - break; - - case 11: - printInvisible(); - break; - - case 12: - printProtected(); - break; - } + if ( y < effect.size() ) + effect[y](); } if ( ! isMonochron() )