MxEngine
Layout.h
1 // Copyright(c) 2019 - 2020, #Momo
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met :
6 //
7 // 1. Redistributions of source code must retain the above copyright notice, this
8 // list of conditions and the following disclaimer.
9 //
10 // 2. Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and /or other materials provided with the distribution.
13 //
14 // 3. Neither the name of the copyright holder nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 // DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 // OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 #pragma once
30 
31 #include "Utilities/ImGui/ImGuiBase.h"
32 #include "Core/Application/Application.h"
33 
34 namespace MxEngine::GUI
35 {
40  struct Indent
41  {
45  float indent;
46 
50  inline Indent(float indent)
51  : indent(indent)
52  {
53  ImGui::Indent(indent);
54  }
55 
59  inline ~Indent()
60  {
61  ImGui::Unindent(indent);
62  }
63  };
64 
65  // GUI_TREE_NODE is a special macro to create tree nodes with offset all code of node must be places after its name as argument, i.e. GUI_TREE_NODE(NAME, CODE);
66  #define GUI_TREE_NODE(name, ...) if(ImGui::CollapsingHeader(name)) { GUI::Indent _(5.0f); __VA_ARGS__; }
67  #define SCOPE_TREE_NODE(name) if (!ImGui::CollapsingHeader(name)) return; GUI::Indent _(5.0f)
68 
76  inline bool InputIntOnClick(const char* title, int* v, const char* buttonText = "apply")
77  {
78  ImGui::PushID(title);
79  ImGui::AlignTextToFramePadding();
80  ImGui::Text(title);
81  ImGui::SameLine();
82  ImGui::InputInt("", v);
83  ImGui::SameLine();
84  bool result = ImGui::Button(buttonText);
85  ImGui::PopID();
86  return result;
87  }
88 
96  inline bool InputFloatOnClick(const char* title, float* v, const char* buttonText = "apply")
97  {
98  ImGui::PushID(title);
99  ImGui::AlignTextToFramePadding();
100  ImGui::Text(title);
101  ImGui::SameLine();
102  ImGui::InputFloat("", v);
103  ImGui::SameLine();
104  bool result = ImGui::Button(buttonText);
105  ImGui::PopID();
106  return result;
107  }
108 
117  inline bool InputTextOnClick(const char* text, MxString& str, size_t sizeRequired, const char* buttonText = "apply")
118  {
119  str.resize(sizeRequired, '\0');
120  ImGui::PushID((void*)&str);
121  if (text != nullptr)
122  {
123  ImGui::AlignTextToFramePadding();
124  ImGui::Text(text);
125  ImGui::SameLine();
126  }
127  ImGui::InputText("", str.data(), sizeRequired);
128  ImGui::SameLine();
129  bool result = ImGui::Button(buttonText);
130  ImGui::PopID();
131 
132  while (result && str.size() > 0 && str.back() == '\0')
133  str.pop_back(); // remove extra null terminators from string
134 
135  return result;
136  }
137 }
Definition: ComponentEditor.cpp:35
bool InputIntOnClick(const char *title, int *v, const char *buttonText="apply")
Definition: Layout.h:76
float indent
Definition: Layout.h:45
Indent(float indent)
Definition: Layout.h:50
Definition: Layout.h:40
bool InputFloatOnClick(const char *title, float *v, const char *buttonText="apply")
Definition: Layout.h:96
bool InputTextOnClick(const char *text, MxString &str, size_t sizeRequired, const char *buttonText="apply")
Definition: Layout.h:117
~Indent()
Definition: Layout.h:59