Chira Engine
A customizable MIT-licensed game engine.
IPanel.cpp
1 #include "IPanel.h"
2 
3 using namespace chira;
4 
5 IPanel::IPanel(std::string title_, bool startVisible, ImVec2 windowSize, bool enforceSize)
6  : title(std::move(title_))
7  , visible(startVisible)
8  , activatedThisFrame(startVisible)
9  , nextWindowSize(windowSize)
10  , windowSizeCondition(enforceSize ? ImGuiCond_Always : ImGuiCond_FirstUseEver)
11  , flags(0) {}
12 
13 void IPanel::render() {
14  if (this->visible) {
15  ImGui::SetNextWindowSize(this->nextWindowSize, this->windowSizeCondition);
16  this->preRenderContents();
17  if (ImGui::Begin(this->title.c_str(), &this->visible, this->flags)) {
18  this->renderContents();
19  }
20  ImGui::End();
21  this->postRenderContents();
22 
23  if (this->activatedThisFrame)
24  this->activatedThisFrame = false;
25  }
26 }
27 
28 std::string_view IPanel::getTitle() const {
29  return this->title;
30 }
31 
32 void IPanel::setTitle(const std::string& newTitle) {
33  this->title = newTitle;
34 }
35 
36 bool IPanel::isVisible() const {
37  return this->visible;
38 }
39 
40 void IPanel::setVisible(bool visible_) {
41  if (visible_)
42  this->activatedThisFrame = true;
43  this->visible = visible_;
44 }
45 
46 bool IPanel::wasActivatedThisFrame() const {
47  return this->activatedThisFrame;
48 }
49 
50 glm::vec2 IPanel::getWindowSize() const {
51  return {this->nextWindowSize.x, this->nextWindowSize.y};
52 }
53 
54 ImGuiWindowFlags& IPanel::getWindowFlags() {
55  return this->flags;
56 }
57 
58 void IPanel::setWindowSize(glm::vec2 size) {
59  this->nextWindowSize.x = size.x;
60  this->nextWindowSize.y = size.y;
61 }