File ImguiItem.h
File List > src > UI > ImguiItem.h
Go to the documentation of this file
#pragma once
#include "ImGui/imgui.h"
#include "Parameters.h"
#include <iostream>
#include <optional>
#include <functional>
#include <type_traits>
#include <cstdarg>
#include "macros.h"
enum ImItemType
{
NONE_INP,
TEXT_INP,
FLOAT_INP,
INT_INP,
RGB_INP,
RGBA_INP,
VEC2_INP,
VEC3_INP,
VEC4_INP,
BUTTON_INP,
BOOL_INP,
SELECT_INP,
IMAGE_OUTP,
TEXT_OUTP,
VIEWPORT_OUTP
};
class ImguiItem
{
private:
public:
ImguiItem();
ImguiItem(ImItemType type, const std::string& name);
virtual ~ImguiItem();
public:
mutable bool using_size = false;
mutable bool fixed_size = false;
mutable bool show_tag_name = false;
ImVec2 uitm_size;
public:
mutable bool is_activated = false;
public:
ImItemType uitm_type = NONE_INP;
mutable std::string uitm_name = "";
mutable std::string notagname = "";
mutable int uitm_id = -1;
public:
void Rename(const std::string& name) const;
std::string GetTagName()const;
void EnableTagName() const;
void DisableTagName() const;
const char* GetCharName() const { return uitm_name.c_str(); }
public:
virtual void RenderItem() const { DEBUG("no render function overrided"); return; }
virtual Parameters* GetPara() { DEBUG(uitm_name + " is not a paraInp"); return nullptr; }
mutable std::function<void(void)> ButtonFunc = [] {};
virtual void CallButtonFunc() const { DEBUG(uitm_name + " is not a button"); return; }
mutable bool is_button_pressed;
virtual void SetArgsList(int length, ...) const { DEBUG(uitm_name + " is not a text"); return; }
virtual void SetArgsList(int length, float* f1) const { DEBUG(uitm_name + " is not a text"); return; }
virtual void ResetUV(const ImVec2& min, const ImVec2& max) { DEBUG(uitm_name + " is not a viewport"); return; }
virtual void ResetSize(const ImVec2& size) { DEBUG(uitm_name + " is not a viewport"); return; }
virtual void ResetBufferID(int id) { DEBUG(uitm_name + " is not a viewport"); return; }
};
#include "operator.h"
namespace Item {
inline bool is_inside(const ImVec2 size, const ImVec2 mouse_pos) {
const ImVec2 window_pos = ImGui::GetWindowPos() - ImGui::GetMainViewport()->Pos;
return window_pos < mouse_pos && mouse_pos < window_pos + size;
}
}
#include <type_traits>
template<typename T>
concept ImguiItemType = std::is_base_of_v<ImguiItem, T>;