Cthulhu  0.2.10
Cthulhu compiler collection
panel.cpp
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-3.0-only
2 #include "stdafx.hpp"
3 
5 
6 using namespace ed;
7 
8 IEditorPanel::IEditorPanel(std::string_view name)
9  : name(name)
10  , visible(false)
11 { }
12 
14 {
15  if (!visible) return false;
16 
17  if (ImGui::Begin(get_title(), &visible))
18  {
19  draw_content();
20  }
21  ImGui::End();
22 
23  return visible;
24 }
25 
27 {
28  ScopeID id(this);
29  draw_content();
30 }
31 
32 bool IEditorPanel::menu_item(const char *shortcut)
33 {
34  bool result = ImGui::MenuItem(get_title(), shortcut, &visible, enabled);
35  if (!enabled && !disabled_reason.empty())
36  {
37  ImGui::SetItemTooltip("%s", disabled_reason.c_str());
38  }
39  return result;
40 }
41 
42 void ed::draw_seperated(IEditorPanel& panel, const char *title)
43 {
44  const char *name = title ? title : panel.get_title();
45  ImGui::SeparatorText(name);
46  panel.draw();
47 }
48 
49 bool ed::draw_collapsing(IEditorPanel& panel, const char *title, ImGuiTreeNodeFlags flags)
50 {
51  const char *name = title ? title : panel.get_title();
52  bool result = ImGui::CollapsingHeader(name, flags);
53 
54  if (result)
55  {
56  panel.draw();
57  }
58 
59  return result;
60 }
virtual bool draw_window()
Definition: panel.cpp:13
virtual bool menu_item(const char *shortcut=nullptr)
Definition: panel.cpp:32
const char * get_title() const
Definition: panel.hpp:54
std::string disabled_reason
Definition: panel.hpp:32
IEditorPanel(std::string_view name)
Definition: panel.cpp:8
void draw()
Definition: panel.cpp:26
Definition: compile.hpp:13
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