bwidgets/inc/basic_widgets/w/feat/focus_handler_impl.hpp
Andrea Blankenstijn a19d2ea6bd - mark as const every single read only variable.
- mark as const every pointer that can be const.
- in implementation mark const args passed by value that are meant to be read-only.
- wrap in a lambda complex initializations of (const) values.
- argument passing:
  - pass by value arguments of cheap-to-copy types or meant to be copied
    anyway.
  - pass by (const) reference args not meant to outlive called
    function scope and not cheap-to-copy.
  - pass (const) pointers to (const) args when null is a valid option
    and pointed data aren't expected to outlive function scope.
  - use string_view for non-owned strings (not meant to outlive function
    scope).
  - use span for collection types like vector and arrays.
  - fancy pointers passing:
    - pass by value if a reference will be held:
    - pass by const reference if a reference _may_ be hell.
    - when no references are meant to be held:
        - dereference the pointer to pass the pointed data by reference
          if null is not an option.
        - pass the underlying raw pointer if null is an option.
… and random subtle changes and fixes here and there that I forgot to mention.
2021-08-22 00:57:55 +02:00

32 lines
725 B
C++

#ifndef BWIDGETS_FOCUS_HANDLER_IMPL_HPP
#define BWIDGETS_FOCUS_HANDLER_IMPL_HPP
#include <basic_widgets/w/feat/focus_handler.hpp>
namespace bwidgets
{
class FocusHandlerImpl : public virtual FocusHandler
{
bool _has_focus {false};
std::function<void(bool)> _focus_handler {[](auto) {}};
public:
void focus(const bool _focus) override
{
if (_has_focus != _focus) _focus_handler(_has_focus = _focus);
}
bool focus() override
{
return _has_focus;
}
void focus_handler(decltype(_focus_handler) handler) final
{
_focus_handler = std::move(handler);
}
};
}
#endif