3#include <klib/base_types.hpp>
9template <
typename Type>
10using Callback = std::move_only_function<bool(Type
const& new_value)>;
16 [[nodiscard]]
virtual auto type_name() const -> std::string_view = 0;
17 [[nodiscard]] virtual auto
as_string() const -> std::string_view = 0;
18 virtual auto
assign(std::string_view input) ->
bool = 0;
22template <typename Type>
32 template <std::convertible_to<Type> T>
34 set_value(std::move(t));
38 set_value(std::move(t));
42 [[nodiscard]]
auto type_name() const -> std::string_view final {
return Parser::type_name(); }
44 [[nodiscard]]
auto as_string() const -> std::string_view final {
return m_as_string; }
49 auto assign(std::string_view
const input) ->
bool final {
51 if (!Parser::parse(input, value)) {
return false; }
52 return set_value(std::move(value));
55 [[nodiscard]]
auto get_value() const -> Type const& {
return m_value; }
56 [[nodiscard]]
auto get_value() -> Type& {
return m_value; }
61 if (m_on_set && !m_on_set(value)) {
return false; }
62 m_value = std::move(value);
63 m_as_string = Parser::to_string(m_value);
70 explicit(std::same_as<bool, Type>)
operator Type
const&()
const {
return m_value; }
74 std::string m_as_string{};
Interface for concrete Tweakables.
Definition tweakable.hpp:14
virtual auto assign(std::string_view input) -> bool=0
virtual auto type_name() const -> std::string_view=0
virtual auto as_string() const -> std::string_view=0
Tweakable wrapper over a Type value.
Definition tweakable.hpp:23
auto as_string() const -> std::string_view final
Definition tweakable.hpp:44
auto get_value() const -> Type const &
Definition tweakable.hpp:55
auto set_value(Type value) -> bool
Set value and invoke OnChange (if not null).
Definition tweakable.hpp:60
auto operator=(Type t) -> Tweakable &
Definition tweakable.hpp:37
tweak::Callback< Type > Callback
Setter hook callback.
Definition tweakable.hpp:28
auto get_value() -> Type &
Definition tweakable.hpp:56
auto assign(std::string_view const input) -> bool final
Parse input into value and assign if successful.
Definition tweakable.hpp:49
auto type_name() const -> std::string_view final
Definition tweakable.hpp:42
void on_set(Callback callback)
Install setter hook callback.
Definition tweakable.hpp:68
std::move_only_function< bool(Type const &new_value)> Callback
Definition tweakable.hpp:10
Definition animation.hpp:8
Customization point. Specialize this type for custom Tweakable template types.
Definition parser.hpp:22