SpiecsEngine
 
Loading...
Searching...
No Matches
TagComponent.cpp
Go to the documentation of this file.
1/**
2* @file TagComponent.cpp.
3* @brief The TagComponent Class Implementation.
4* @author Spices.
5*/
6
7#include "Pchheader.h"
8#include "TagComponent.h"
9
10namespace Spices {
11
12 TagComponent::TagComponent(const std::string& tag)
13 {
14 m_Tags.insert(tag);
15 }
16
18 {
19
20 }
21
23 {
24
25 }
26
27 void TagComponent::RemoveTag(const std::string& tag)
28 {
30
31 assert(m_Tags.size() > 0);
32
33 if (m_Tags.size() == 1)
34 {
35 std::stringstream ss;
36 ss << "Remove tag failed: Entity " << *m_Tags.begin() << " must have at lease one tag.";
37
38 SPICES_CORE_WARN(ss.str())
39
40 return;
41 }
42
43 if (m_Tags.find(tag) == m_Tags.end())
44 {
45 std::stringstream ss;
46 ss << "Remove tag failed: Entity " << *m_Tags.begin() << " do not have tag of " << tag;
47
48 SPICES_CORE_WARN(ss.str())
49
50 return;
51 }
52
53 m_Tags.erase(tag);
54 }
55
56 void TagComponent::Rename(const std::string& tag)
57 {
59
60 assert(m_Tags.size() > 0);
61
62 m_Tags.erase(*m_Tags.begin());
63 m_Tags.insert(tag);
64 }
65
67 {
69
70 std::vector<std::string> tagBuffer(m_Tags.begin(), m_Tags.end());
71
72 ImGui::Spacing();
73 ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2{ 0, 3.0f });
74 float columeWidth = ImGuiH::GetLineItemSize().x * 6.5f;
75
76 {
77 SPICES_PROFILE_ZONEN("TagComponent Tags");
78
79 for(int i = 0; i < tagBuffer.size(); i++)
80 {
81 std::stringstream ss;
82 ss << "Tag[" << i << "]";
83 ImGuiH::DrawPropertyItem(ss.str(), columeWidth, nullptr, [&]() {
84 ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x - ImGuiH::GetLineItemSize().x);
85 char buffer[256] = {};
86 strcpy_s(buffer, sizeof(buffer), tagBuffer[i].c_str());
87 if (ImGui::InputText("##", buffer, sizeof(buffer)))
88 {
89 m_Tags.erase(tagBuffer[i]);
90 m_Tags.insert(std::string(buffer));
91 }
92 ImGui::PopItemWidth();
93 ImGui::SameLine();
94 ImGuiH::DrawResetIcon(false);
95 });
96 }
97 }
98
99 ImGui::PopStyleVar();
100 ImGui::Spacing();
101 }
102}
#define SPICES_PROFILE_ZONEN(...)
#define SPICES_PROFILE_ZONE
void RemoveTag(const std::string &tag)
Remove a tag from this component handled.
virtual void DrawThis() override
This interface defines how to draw this component to property panel.
void Rename(const std::string &tag)
Rename first element in tags.
TagComponent(const std::string &tag)
Constructor Function.
virtual void OnDeSerialize() override
This interface defines how to deserialize.
virtual void OnSerialize() override
This interface defines how to serialize.
TagComponent Class. This class defines the specific behaves of TagComponent.