Cthulhu  0.2.10
Cthulhu compiler collection
panel.hpp
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-3.0-only
2 #pragma once
3 
4 #include "imgui.h"
5 
6 #include "editor/utils/utils.hpp"
7 
8 #include <string>
9 
10 namespace ed
11 {
12  class ScopeID
13  {
14  CTX_NOCOPY(ScopeID);
15  CTX_NOMOVE(ScopeID);
16  public:
17  ScopeID(const void *ptr) { ImGui::PushID(ptr); }
18  ScopeID(int i) { ImGui::PushID(i); }
19  ScopeID(const char *str) { ImGui::PushID(str); }
20  ~ScopeID() { ImGui::PopID(); }
21  };
22 
24  {
25  std::string name;
26 
27  virtual void draw_content() { }
28 
29  protected:
30  bool visible = true;
31  bool enabled = true;
32  std::string disabled_reason;
33  ImGuiWindowFlags flags = ImGuiWindowFlags_None;
34 
35  void set_enabled(bool value) { enabled = value; }
36  void disable(std::string_view reason) { enabled = false; disabled_reason = reason; }
37 
38  public:
39  IEditorPanel(std::string_view name);
40 
41  virtual ~IEditorPanel() = default;
42 
43  virtual void update() { }
44 
45  // draw the panel inside its own window
46  virtual bool draw_window();
47 
48  // draw only the content of the panel
49  void draw();
50 
51  // draw a menu item that toggles the visibility of the panel
52  virtual bool menu_item(const char *shortcut = nullptr);
53 
54  const char *get_title() const { return name.c_str(); }
55  bool is_visible() const { return visible; }
56  bool is_enabled() const { return enabled; }
57  };
58 
60  {
61  std::string name;
62  bool seperator = true; // if true use a seperator, otherwise use a nested menu
63  std::vector<ed::IEditorPanel*> panels;
64  };
65 
66  struct menu_t
67  {
68  std::string name;
69  std::vector<ed::IEditorPanel*> header;
70  std::vector<menu_section_t> sections;
71  };
72 
75 
76  // draw the content with a SeperatorText(get_title()) before it
77  void draw_seperated(IEditorPanel& panel, const char *title = nullptr);
78 
79  // draw the content with wrapped in a collapsing header
80  bool draw_collapsing(IEditorPanel& panel, const char *title = nullptr, ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_None);
81 }
virtual void update()
Definition: panel.hpp:43
virtual bool draw_window()
Definition: panel.cpp:13
virtual bool menu_item(const char *shortcut=nullptr)
Definition: panel.cpp:32
virtual ~IEditorPanel()=default
ImGuiWindowFlags flags
Definition: panel.hpp:33
bool is_visible() const
Definition: panel.hpp:55
const char * get_title() const
Definition: panel.hpp:54
void disable(std::string_view reason)
Definition: panel.hpp:36
void set_enabled(bool value)
Definition: panel.hpp:35
std::string disabled_reason
Definition: panel.hpp:32
IEditorPanel(std::string_view name)
Definition: panel.cpp:8
void draw()
Definition: panel.cpp:26
bool is_enabled() const
Definition: panel.hpp:56
ScopeID(const char *str)
Definition: panel.hpp:19
ScopeID(const void *ptr)
Definition: panel.hpp:17
ScopeID(int i)
Definition: panel.hpp:18
~ScopeID()
Definition: panel.hpp:20
Definition: compile.hpp:13
IEditorPanel * create_implot_demo_panel()
IEditorPanel * create_imgui_demo_panel()
bool draw_collapsing(IEditorPanel &panel, const char *title=nullptr, ImGuiTreeNodeFlags flags=ImGuiTreeNodeFlags_None)
Definition: panel.cpp:49
void draw_seperated(IEditorPanel &panel, const char *title=nullptr)
Definition: panel.cpp:42
std::vector< ed::IEditorPanel * > panels
Definition: panel.hpp:63
std::string name
Definition: panel.hpp:61
std::string name
Definition: panel.hpp:68
std::vector< ed::IEditorPanel * > header
Definition: panel.hpp:69
std::vector< menu_section_t > sections
Definition: panel.hpp:70