bwidgets/inc/basic_widgets/w/base/input.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

52 lines
2 KiB
C++

#ifndef BWIDGETS_INPUT_HPP
#define BWIDGETS_INPUT_HPP
#include <basic_widgets/core/type/concepts.hpp>
#include <basic_widgets/w/base/widget.hpp>
#include <basic_widgets/w/feat/font_handler.hpp>
#include <basic_widgets/w/feat/keyboard_handler.hpp>
#include <basic_widgets/w/feat/mouse_handler.hpp>
namespace bwidgets
{
template<typename T>
class Input : public virtual Widget,
public virtual FontHandler,
public virtual KeyboardHandler,
public virtual MouseHandler
{
protected:
using Widget::Widget;
public:
static const int default_border_width = 3;
inline static const Color default_color_bg = {200, 200, 200, SDL_ALPHA_OPAQUE};
inline static const Color default_color_bg_focused = {255, 255, 255,
SDL_ALPHA_OPAQUE};
static const int default_float_precision = 2;
static const int default_min_width = 1;
int border_width = default_border_width;
Color color_bg_default = default_color_bg;
Color color_bg_focused = default_color_bg_focused;
int float_precision = default_float_precision;
int input_min_width = default_min_width;
char input_width_unit = 'W';
T value {};
virtual void color_fg(Color c) = 0;
[[nodiscard]] virtual auto input_text() const -> std::string_view = 0;
virtual void input_text(std::string txt) = 0;
[[nodiscard]] virtual auto is_valid_input(std::string_view) const noexcept
-> bool = 0;
[[nodiscard]] virtual auto process_value(T x) const noexcept -> T = 0;
[[nodiscard]] virtual auto value_from_string(std::string_view s) const noexcept
-> T = 0;
[[nodiscard]] virtual auto value_to_string(T value) const noexcept
-> std::string = 0;
};
}
#endif