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

59 lines
2.5 KiB
C++
Raw Permalink 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-27 01:21:25 +02:00
char input_width_unit = 'W'; // char used as unit for text length computation.
2021-08-06 14:22:56 +02:00
T value {};
2021-08-23 23:50:14 +02:00
// Get the current displayed string.
[[nodiscard]] virtual auto input_text() const -> std::string_view = 0;
2021-08-23 23:50:14 +02:00
// Set displayed string
virtual void input_text(std::string) = 0;
virtual void input_text_color(Color) = 0;
2021-08-27 01:21:25 +02:00
// Check if a character is allowed to be inputted. String are used because we
// could have multibytes characters to represent using 8bits chars.
[[nodiscard]] virtual auto is_valid_input(std::string_view) const noexcept
2021-08-23 23:50:14 +02:00
-> bool = 0;
// Process a value for instance to modify it before saving it.
[[nodiscard]] virtual auto process_value(T) const noexcept -> T = 0;
// Get string representation to be shown of the stored value.
[[nodiscard]] virtual auto value_from_string(std::string_view) const noexcept
-> T = 0;
// Parse a string to get its representation in T type of input value memory.
[[nodiscard]] virtual auto value_to_string(T) const noexcept -> std::string = 0;
2021-07-10 19:55:53 +02:00
};
}
2021-06-11 13:30:33 +02:00
#endif