File size: 7,426 Bytes
17f5b5c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
// Generated with ImRAD 0.9
// visit https://github.com/tpecholt/imrad
#include "ui_error_box.h"
#include <IconsFontAwesome6.h>
ErrorBox errorBox;
std::string WordWrap(const std::string& str, float multilineWidth)
{
float textSize = 0;
std::string tmpStr = "";
std::string finalStr = "";
int curChr = 0;
while (curChr < str.size()) {
if (str[curChr] == '\n') {
finalStr += tmpStr + "\n";
tmpStr = "";
}
else
tmpStr += str[curChr];
textSize = ImGui::CalcTextSize(tmpStr.c_str()).x;
if (textSize > multilineWidth) {
int lastSpace = (int)tmpStr.size() - 1;
while (tmpStr[lastSpace] != ' ' && lastSpace > 0)
lastSpace--;
if (lastSpace == 0)
lastSpace = (int)tmpStr.size() - 2;
finalStr += tmpStr.substr(0, lastSpace + 1) + "\n";
if (lastSpace + 1 > tmpStr.size())
tmpStr = "";
else
tmpStr = tmpStr.substr(lastSpace + 1);
}
curChr++;
}
if (tmpStr.size() > 0)
finalStr += tmpStr;
return finalStr;
};
int TreeNode(const std::string& str, size_t& i, int level, bool skip)
{
struct ScopeGuard {
ScopeGuard(std::function<void()> f) : func(f) {}
~ScopeGuard() { func(); }
std::function<void()> func;
};
for (int n = 0; i < str.size(); ++n)
{
ImGui::PushID(n);
ScopeGuard g([] { ImGui::PopID(); });
size_t j = str.find("\n", i);
int nlevel = 0;
std::string label;
if (j == std::string::npos) {
label = str.substr(i);
i = str.size();
}
else {
label = str.substr(i, j - i);
i = j + 1;
for (nlevel = 0; i < str.size() && str[i] == '\t'; ++i)
++nlevel;
}
if (nlevel > level) {
bool open = true;
if (!skip) {
//auto clr = ImGui::ColorConvertFloat4ToU32(ImGui::GetStyleColorVec4(ImGuiCol_ButtonHovered));
ImGui::PushStyleColor(ImGuiCol_Text, !level ? 0xff600000 : 0xff000000);
open = ImGui::TreeNodeEx(label.c_str(), ImGuiTreeNodeFlags_DefaultOpen);
ImGui::PopStyleColor();
}
nlevel = TreeNode(str, i, nlevel, skip || !open);
if (!skip && open)
ImGui::TreePop();
return nlevel;
}
else {
if (!skip) {
ImVec2 pad = ImGui::GetStyle().FramePadding;
if (!level) {
ImGui::Bullet();
ImGui::SameLine(0, pad.x * 3);
}
else {
ImGui::Text(" ");
ImGui::SameLine(0, pad.x * 3);
}
float w = ImGui::GetContentRegionAvail().x - pad.x;
label = WordWrap(label, w);
ImGui::Selectable(label.c_str(), false);
}
if (nlevel < level)
return nlevel;
}
}
return 0;
}
//-----------------------------------------------------------
void ErrorBox::OpenPopup(std::function<void(ImRad::ModalResult)> clb)
{
callback = clb;
modalResult = ImRad::None;
auto *ioUserData = (ImRad::IOUserData *)ImGui::GetIO().UserData;
ioUserData->dimBgRatio = 1.f;
ImGui::OpenPopup(ID);
Init();
}
void ErrorBox::ClosePopup(ImRad::ModalResult mr)
{
modalResult = mr;
auto *ioUserData = (ImRad::IOUserData *)ImGui::GetIO().UserData;
ioUserData->dimBgRatio = 0.f;
}
void ErrorBox::Init()
{
// TODO: Add your code here
}
void ErrorBox::Draw()
{
/// @style Dark
/// @unit px
/// @begin TopWindow
auto* ioUserData = (ImRad::IOUserData*)ImGui::GetIO().UserData;
ID = ImGui::GetID("###ErrorBox");
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, { 10, 10 });
ImGui::SetNextWindowSize({ 640, 480 }, ImGuiCond_FirstUseEver); //{ 640, 480 }
ImGui::SetNextWindowSizeConstraints({ 0, 0 }, { FLT_MAX, FLT_MAX });
bool tmpOpen = true;
if (ImGui::BeginPopupModal(ImRad::Format("{}###ErrorBox", title).c_str(), &tmpOpen, ImGuiWindowFlags_NoCollapse))
{
if (ioUserData->activeActivity != "")
ImRad::RenderDimmedBackground(ioUserData->WorkRect(), ioUserData->dimBgRatio);
if (modalResult != ImRad::None)
{
ImGui::CloseCurrentPopup();
if (modalResult != ImRad::Cancel)
callback(modalResult);
}
if (ImGui::Shortcut(ImGuiKey_Escape))
ClosePopup();
/// @separator
// TODO: Add Draw calls of dependent popup windows here
/// @begin Text
vb1.BeginLayout();
ImRad::Spacing(1);
ImGui::PushStyleColor(ImGuiCol_Text, 0xff0099ff);
ImGui::TextUnformatted(ImRad::Format(" {} ", ICON_FA_CIRCLE_EXCLAMATION).c_str());
vb1.AddSize(1, ImRad::VBox::ItemSize);
ImGui::PopStyleColor();
/// @end Text
/// @begin Text
ImGui::SameLine(0, 1 * ImGui::GetStyle().ItemSpacing.x);
ImGui::PushTextWrapPos(0);
ImGui::TextUnformatted(ImRad::Format("{}", message).c_str());
ImGui::PopTextWrapPos();
vb1.UpdateSize(0, ImRad::VBox::ItemSize);
/// @end Text
/// @begin Child
ImRad::Spacing(3);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, { 0, 4 });
ImGui::PushStyleColor(ImGuiCol_ChildBg, 0xffc0c0c0);
ImGui::BeginChild("child1", { -1, vb1.GetSize() }, ImGuiChildFlags_Borders | ImGuiChildFlags_AlwaysUseWindowPadding | ImGuiChildFlags_NavFlattened, ImGuiWindowFlags_NoSavedSettings);
{
/// @separator
/// @begin CustomWidget
CustomWidget_Draw({ -1, -1 });
/// @end CustomWidget
/// @separator
ImGui::EndChild();
}
ImGui::PopStyleColor();
ImGui::PopStyleVar();
vb1.AddSize(4, ImRad::VBox::Stretch(1));
/// @end Child
/// @begin Spacer
hb3.BeginLayout();
ImRad::Spacing(1);
ImRad::Dummy({ hb3.GetSize(), 0 });
vb1.AddSize(2, ImRad::VBox::ItemSize);
hb3.AddSize(0, ImRad::HBox::Stretch(1));
/// @end Spacer
/// @begin Button
ImGui::SameLine(0, 1 * ImGui::GetStyle().ItemSpacing.x);
if (ImGui::Button("OK", { 100, 30 }))
{
ClosePopup(ImRad::Ok);
}
vb1.UpdateSize(0, 30);
hb3.AddSize(1, 100);
if (ImGui::IsWindowAppearing())
ImGui::SetKeyboardFocusHere(-1);
/// @end Button
/// @begin Spacer
ImGui::SameLine(0, 1 * ImGui::GetStyle().ItemSpacing.x);
ImRad::Dummy({ hb3.GetSize(), 0 });
vb1.UpdateSize(0, ImRad::VBox::ItemSize);
hb3.AddSize(1, ImRad::HBox::Stretch(1));
/// @end Spacer
/// @separator
ImGui::EndPopup();
}
ImGui::PopStyleVar();
/// @end TopWindow
}
void ErrorBox::ResetLayout()
{
// ImGui::GetCurrentWindow()->HiddenFramesCannotSkipItems = 2;
vb1.Reset();
hb3.Reset();
}
void ErrorBox::CustomWidget_Draw(const ImRad::CustomWidgetArgs& args)
{
size_t i = 0;
ImGui::PushItemFlag(ImGuiItemFlags_NoNav, true);
TreeNode(error, i, 0, false);
ImGui::PopItemFlag();
}
|