Skip to content

Commit

Permalink
libcore: Added a utility for converting FlagOp arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Jul 27, 2016
1 parent 2929ccc commit 7d551c7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions doomsday/sdk/libcore/include/de/libcore.h
Expand Up @@ -505,6 +505,13 @@ enum FlagOp {
ReplaceFlags = 2 ///< Specified flags become the new set of flags, replacing all previous flags.
};

struct FlagOpArg {
FlagOp op;
inline FlagOpArg(FlagOp op) : op(op) {}
inline FlagOpArg(bool set) : op(set? SetFlags : UnsetFlags) {}
inline operator FlagOp () const { return op; }
};

template <typename FlagsType, typename FlagsCompatibleType>
void applyFlagOperation(FlagsType &flags, FlagsCompatibleType const &newFlags, FlagOp operation) {
switch (operation) {
Expand Down
2 changes: 1 addition & 1 deletion doomsday/sdk/libcore/include/de/widgets/widget.h
Expand Up @@ -161,7 +161,7 @@ class DENG2_PUBLIC Widget
* @param behavior Flags to modify.
* @param operation Operation to perform on the flags.
*/
void setBehavior(Behaviors behavior, FlagOp operation = SetFlags);
void setBehavior(Behaviors behavior, FlagOpArg operation = SetFlags);

/**
* Clears one or more behavior flags.
Expand Down
4 changes: 2 additions & 2 deletions doomsday/sdk/libcore/src/widgets/widget.cpp
Expand Up @@ -329,10 +329,10 @@ bool Widget::hasFamilyBehavior(Behavior const &flags) const

void Widget::show(bool doShow)
{
setBehavior(Hidden, doShow? UnsetFlags : SetFlags);
setBehavior(Hidden, !doShow);
}

void Widget::setBehavior(Behaviors behavior, FlagOp operation)
void Widget::setBehavior(Behaviors behavior, FlagOpArg operation)
{
applyFlagOperation(d->behavior, behavior, operation);
}
Expand Down

0 comments on commit 7d551c7

Please sign in to comment.