bwidgets/inc/basic_widgets/w/base/input.hpp

52 lines
2 KiB
C++
Raw Normal View History

2021-08-06 14:22:56 +02:00
#ifndef BWIDGETS_INPUT_HPP
#define BWIDGETS_INPUT_HPP
2021-06-11 13:30:33 +02:00
#include <basic_widgets/core/type/concepts.hpp>
2021-08-17 18:00:27 +02:00
#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>
2021-06-16 13:50:34 +02:00
2021-08-06 14:22:56 +02:00
namespace bwidgets
2021-06-11 13:30:33 +02:00
{
2021-07-10 19:55:53 +02:00
template<typename T>
2021-08-17 18:00:27 +02:00
class Input : public virtual Widget,
public virtual FontHandler,
public virtual KeyboardHandler,
public virtual MouseHandler
2021-07-10 19:55:53 +02:00
{
protected:
2021-08-17 18:00:27 +02:00
using Widget::Widget;
public:
2021-08-08 14:30:56 +02:00
static const int default_border_width = 3;
2021-08-06 14:22:56 +02:00
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};
2021-08-08 14:30:56 +02:00
static const int default_float_precision = 2;
static const int default_min_width = 1;
2021-08-06 14:22:56 +02:00
2021-08-08 14:30:56 +02:00
int border_width = default_border_width;
Color color_bg_default = default_color_bg;
2021-08-06 14:22:56 +02:00
Color color_bg_focused = default_color_bg_focused;
2021-08-08 14:30:56 +02:00
int float_precision = default_float_precision;
int input_min_width = default_min_width;
2021-08-06 14:22:56 +02:00
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;
2021-07-10 19:55:53 +02:00
};
}
2021-06-11 13:30:33 +02:00
#endif