/*
* Libpdraw: A Versitile GUI for use with a primitive drawing system!
* Copyright (C) 2022 Rebekah Rowe
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include "glez/color.hpp"
#include "input.hpp"
#include
#include
#include
#include
#include
#pragma once
namespace ui {
template
class Var;
using Enum = std::vector;
using TreeMap = std::vector;
using CommandArgs = std::vector;
class BaseVar {
public:
enum class Type {
kBool,
kInt,
kFloat,
kKey,
kEnum,
kString,
kColor,
kFont
};
public:
BaseVar(Type, TreeMap, std::string_view _gui_name);
const Type type;
const TreeMap gui_map;
const std::string command_name;
const std::string_view gui_name;
virtual void Call(std::ostream&, CommandArgs) = 0;
virtual std::string GetString() = 0; // Used by cfg mgr and gui
virtual void SetString(std::string_view) = 0;
virtual void SetDefault() = 0;
private:
static inline std::vector list;
public:
static inline const auto& GetList() { return list; }
};
template
class Var;
template <>
class Var : public BaseVar {
public:
Var(TreeMap, std::string_view, bool _defaults);
std::string GetString() final;
void SetString(std::string_view) final;
void Call(std::ostream&, CommandArgs) final;
void SetDefault() final;
operator bool() const { return this->value; }
bool operator==(bool v) const { return this->value == v; }
Var& operator=(bool v);
private:
bool value;
public:
const bool defaults;
std::function Callback;
};
template <>
class Var : public BaseVar {
public:
Var(TreeMap, std::string_view, int _defaults, int min, int max);
Var(TreeMap, std::string_view, int _defaults, int max = 100);
std::string GetString() override;
void SetString(std::string_view) override;
void Call(std::ostream&, CommandArgs) override;
void SetDefault() final;
operator int() const { return this->value; }
bool operator==(int v) const { return this->value == v; }
Var& operator=(int v);
protected:
int value;
public:
const int defaults, min, max;
std::function Callback;
};
template <>
class Var : public BaseVar {
public:
Var(TreeMap, std::string_view, float _defaults);
Var(TreeMap, std::string_view, float _defaults, float max);
Var(TreeMap, std::string_view, float _defaults, float min, float max);
std::string GetString() final;
void SetString(std::string_view) final;
void Call(std::ostream&, CommandArgs) final;
void SetDefault() final;
operator float() const { return this->value; }
bool operator==(float v) const { return this->value == v; }
Var& operator=(float v);
private:
float value;
public:
const float defaults, min, max;
std::function Callback;
};
template <>
class Var : public Var {
public:
Var(TreeMap, std::string_view name, int _defaults, Enum _enum);
std::string GetString() final;
void SetString(std::string_view) final;
void Call(std::ostream&, CommandArgs) final;
operator int() const { return this->value; }
bool operator==(int v) const { return this->value == v; }
using Var::operator=;
public:
const std::vector internal_enum;
};
template <>
class Var : public BaseVar {
public:
Var(TreeMap, std::string_view, std::string_view _defaults);
Var(TreeMap, std::string_view, std::string_view _defaults, float max);
Var(TreeMap, std::string_view, std::string_view _defaults, float min, float max);
std::string GetString() final;
void SetString(std::string_view) final;
void Call(std::ostream&, CommandArgs) final;
void SetDefault() final;
operator std::string_view() const { return this->value; }
operator const std::string&() const { return this->value; }
operator std::string() const { return this->value; }
bool operator==(std::string_view v) const { return std::string_view(this->value) == v; }
bool operator==(const std::string& v) const { return this->value == v; }
Var& operator=(std::string_view v) { return *this = std::string(v); }
Var& operator=(std::string v);
private:
std::string value;
public:
const std::string_view defaults;
const int min, max;
std::function Callback;
};
template <>
class Var : public BaseVar {
public:
Var(TreeMap, std::string_view, CatKey _defaults);
std::string GetString() final;
void SetString(std::string_view) final;
void Call(std::ostream&, CommandArgs) final;
void SetDefault() final;
operator bool() const;
operator CatKey() const { return this->value; }
bool operator==(CatKey v) const { return this->value == v; }
Var& operator=(CatKey v);
private:
CatKey value;
public:
const CatKey defaults;
std::function Callback;
};
} // namespace ui