I am experimenting a bit with exactly how much is (user-wise, anyways)
conveniently implementable with C+11 variadic templates and a strict
construction/destruction pattern. In addition I use this project for a
playground for other techniques, such as designing everything through
composition and mixins, as well as the occasional functor, for maximum
flexibility. Repository: https://github.com/lycantrophe/Curses-- [1]
So far so good, but all currently implemented widgets have been very
basic and only wrapped around the Widget class. What I am having trouble
with is the "ButtonGroup" widget.
This widget is, as the name suggests, a group wrapper for the Button
class that handles things such as a common return value, behaving like
an external entity towards user code and, most importantly, being
responsible for handling input and focus switch between the buttons in
the group it governs.
What I am trying to accomplish is being able to forward a set of
arguments to the individual, underlying buttons. These parameters
include text value (the string to be displayed), individual return
values and individual anchors. Things like border style and behaviour in
regard to focus toggle will of course be shared between all buttons.
Some code to clarify:
template< typename Return >
class ButtonGroup {
ButtonGroup();
ButtonGroup( const Anchor
template< typename Action, typename... Args >
ButtonGroup(
const std::initializer_list< std::string >& texts,
const std::initializer_list< Action >& actions,
const std::initializer_list< Anchor >& anchors,
const Args
Return trigger();
void redraw();
private:
std::vector< Button< Return > > buttons;
typename std::vector< Button< Return > >::iterator current;
};
Return is the return value from the buttons (typically true/false, but
can be anything). Action is a template as it requires a functor, whereas
bool is treated as a special case (simply creates a functor for you).
This did not work; both gcc and clang/llvm were unable to properly
deduce my use of initializer lists (from the ButtonGroup( const Anchor
to provide me with a vector, array or whatever suitable structure
that holds:
[ Button( "OK", true, Anchor( 0, 0 ), Button( "Cancel", false, Anchor(
0, 3 ) ) ], from here on [ Button, Button... ].
Sending the arguments in a structured matter, such as grouping all
strings, all return-values and all anchors would be fine as well. Now,
it is NOT acceptable to take the actual Buttons (or pointers, for that
matter) as arguments during construction as this would require double
construction and, as you probably see from the other construction code,
defeats the purpose of this style.
Are there any ways I can try to accomplish this? Any other criticism
will be welcome as well.