|
|
#include "node_window.h" |
|
|
#include "node_container.h" |
|
|
#include "stx.h" |
|
|
#include "imrad.h" |
|
|
#include "cppgen.h" |
|
|
#include "binding_input.h" |
|
|
#include "binding_eval.h" |
|
|
#include "ui_message_box.h" |
|
|
#include <algorithm> |
|
|
#include <array> |
|
|
|
|
|
|
|
|
|
|
|
TopWindow::TopWindow(UIContext& ctx) |
|
|
: kind(Kind(ctx.kind)) |
|
|
{ |
|
|
if (kind == Activity) { |
|
|
title = "MyActivity"; |
|
|
size_x = 400; |
|
|
size_y = 700; |
|
|
} |
|
|
else { |
|
|
size_x = 640; |
|
|
size_y = 480; |
|
|
} |
|
|
|
|
|
kind.add("Main Window (GLFW)", MainWindow); |
|
|
kind.add$(Window); |
|
|
kind.add$(Popup); |
|
|
kind.add$(ModalPopup); |
|
|
kind.add("Activity (Android)", Activity); |
|
|
|
|
|
flags.add$(ImGuiWindowFlags_AlwaysAutoResize); |
|
|
flags.add$(ImGuiWindowFlags_AlwaysHorizontalScrollbar); |
|
|
flags.add$(ImGuiWindowFlags_AlwaysVerticalScrollbar); |
|
|
flags.add$(ImGuiWindowFlags_MenuBar); |
|
|
flags.add$(ImGuiWindowFlags_NoBackground); |
|
|
flags.add$(ImGuiWindowFlags_NoCollapse); |
|
|
flags.add$(ImGuiWindowFlags_NoDocking); |
|
|
flags.add$(ImGuiWindowFlags_NoFocusOnAppearing); |
|
|
flags.add$(ImGuiWindowFlags_NoMove); |
|
|
flags.add$(ImGuiWindowFlags_NoNavInputs); |
|
|
flags.add$(ImGuiWindowFlags_NoNavFocus); |
|
|
flags.add$(ImGuiWindowFlags_NoResize); |
|
|
flags.add$(ImGuiWindowFlags_NoSavedSettings); |
|
|
flags.add$(ImGuiWindowFlags_NoScrollbar); |
|
|
flags.add$(ImGuiWindowFlags_NoScrollWithMouse); |
|
|
flags.add$(ImGuiWindowFlags_NoTitleBar); |
|
|
|
|
|
placement.add$(None); |
|
|
placement.add$(Left); |
|
|
placement.add$(Right); |
|
|
placement.add$(Top); |
|
|
placement.add$(Bottom); |
|
|
placement.add$(Center); |
|
|
placement.add$(Maximize); |
|
|
} |
|
|
|
|
|
void TopWindow::Draw(UIContext& ctx) |
|
|
{ |
|
|
ctx.unit = ctx.unit == "px" ? "" : ctx.unit; |
|
|
ctx.root = this; |
|
|
ctx.isAutoSize = flags & ImGuiWindowFlags_AlwaysAutoResize; |
|
|
ctx.prevLayoutHash = ctx.layoutHash; |
|
|
ctx.layoutHash = ctx.isAutoSize; |
|
|
bool dimAll = ctx.activePopups.size(); |
|
|
ctx.activePopups.clear(); |
|
|
ctx.parents = { this }; |
|
|
ctx.hovered = nullptr; |
|
|
ctx.snapParent = nullptr; |
|
|
ctx.kind = kind; |
|
|
ctx.contextMenus.clear(); |
|
|
|
|
|
std::string cap = title.value(); |
|
|
cap += "###TopWindow" + std::to_string((size_t)this); |
|
|
int fl = ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoSavedSettings; |
|
|
if (ctx.mode != UIContext::NormalSelection) |
|
|
fl |= ImGuiWindowFlags_NoResize; |
|
|
if (kind == MainWindow) |
|
|
fl |= ImGuiWindowFlags_NoCollapse; |
|
|
else if (kind == Popup) |
|
|
fl |= ImGuiWindowFlags_NoTitleBar; |
|
|
else if (kind == Activity) |
|
|
fl |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse; |
|
|
fl |= flags; |
|
|
|
|
|
if (style_font.has_value()) |
|
|
ImGui::PushFont(ImRad::GetFontByName(style_font.eval(ctx))); |
|
|
if (style_padding.has_value()) |
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, style_padding.eval_px(ctx)); |
|
|
if (style_spacing.has_value()) |
|
|
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, style_spacing.eval_px(ctx)); |
|
|
if (style_innerSpacing.has_value()) |
|
|
ImGui::PushStyleVar(ImGuiStyleVar_ItemInnerSpacing, style_innerSpacing.eval_px(ctx)); |
|
|
if (style_borderSize.has_value()) |
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, style_borderSize.eval_px(ctx)); |
|
|
if (style_rounding.has_value()) |
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, style_rounding.eval_px(ctx)); |
|
|
if (style_scrollbarSize.has_value()) |
|
|
ImGui::PushStyleVar(ImGuiStyleVar_ScrollbarSize, style_scrollbarSize.eval_px(ctx)); |
|
|
if (!style_bg.empty()) |
|
|
ImGui::PushStyleColor(ImGuiCol_WindowBg, style_bg.eval(ImGuiCol_WindowBg, ctx)); |
|
|
if (!style_menuBg.empty()) |
|
|
ImGui::PushStyleColor(ImGuiCol_MenuBarBg, style_menuBg.eval(ImGuiCol_MenuBarBg, ctx)); |
|
|
|
|
|
ImGui::SetNextWindowScroll({ 0, 0 }); |
|
|
ImGui::SetNextWindowPos(ctx.designAreaMin + ImVec2{ 20, 20 }); |
|
|
|
|
|
if (kind == MainWindow && placement == Maximize) |
|
|
{ |
|
|
ImGui::SetNextWindowSize(ctx.designAreaMax - ctx.designAreaMin - ImVec2{ 40, 40 }); |
|
|
} |
|
|
else if (fl & ImGuiWindowFlags_AlwaysAutoResize) |
|
|
{ |
|
|
|
|
|
ImGui::SetNextWindowSizeConstraints({ 30, 30 }, { FLT_MAX, FLT_MAX }); |
|
|
} |
|
|
else |
|
|
{ |
|
|
float w = size_x.eval_px(ImGuiAxis_X, ctx); |
|
|
if (!w) |
|
|
w = 640; |
|
|
float h = size_y.eval_px(ImGuiAxis_Y, ctx); |
|
|
if (!h) |
|
|
h = 480; |
|
|
ImGui::SetNextWindowSize({ w, h }); |
|
|
w = minSize_x.eval_px(ImGuiAxis_X, ctx); |
|
|
h = minSize_y.eval_px(ImGuiAxis_Y, ctx); |
|
|
ImGui::SetNextWindowSizeConstraints({ w, h }, { FLT_MAX, FLT_MAX }); |
|
|
} |
|
|
|
|
|
if (style_titlePadding.has_value()) |
|
|
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, style_titlePadding.eval_px(ctx)); |
|
|
|
|
|
bool tmp; |
|
|
ImGui::Begin(cap.c_str(), &tmp, fl); |
|
|
|
|
|
if (style_titlePadding.has_value()) |
|
|
ImGui::PopStyleVar(); |
|
|
|
|
|
ImGui::SetWindowFontScale(ctx.zoomFactor); |
|
|
|
|
|
ctx.rootWin = ImGui::FindWindowByName(cap.c_str()); |
|
|
assert(ctx.rootWin); |
|
|
for (int i = 0; i < 4; ++i) |
|
|
{ |
|
|
if (ImGui::GetActiveID() == ImGui::GetWindowResizeCornerID(ctx.rootWin, i) || |
|
|
ImGui::GetActiveID() == ImGui::GetWindowResizeBorderID(ctx.rootWin, (ImGuiDir)i)) |
|
|
ctx.beingResized = true; |
|
|
} |
|
|
if (ctx.beingResized && ImGui::IsMouseReleased(ImGuiMouseButton_Left)) { |
|
|
ctx.beingResized = false; |
|
|
ImGui::GetIO().MouseReleased[ImGuiMouseButton_Left] = false; |
|
|
} |
|
|
if (ctx.beingResized) |
|
|
ctx.selected = { this }; |
|
|
|
|
|
if (placement == Left) |
|
|
ImRad::RenderFilledWindowCorners(ImDrawFlags_RoundCornersLeft); |
|
|
else if (placement == Right) |
|
|
ImRad::RenderFilledWindowCorners(ImDrawFlags_RoundCornersRight); |
|
|
else if (placement == Top) |
|
|
ImRad::RenderFilledWindowCorners(ImDrawFlags_RoundCornersTop); |
|
|
else if (placement == Bottom) |
|
|
ImRad::RenderFilledWindowCorners(ImDrawFlags_RoundCornersBottom); |
|
|
|
|
|
ImGui::GetCurrentContext()->NavHighlightItemUnderNav = true; |
|
|
ImGui::GetCurrentContext()->NavCursorVisible = false; |
|
|
if (dimAll) |
|
|
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 0.2f); |
|
|
|
|
|
for (size_t i = 0; i < children.size(); ++i) |
|
|
children[i]->Draw(ctx); |
|
|
|
|
|
if (dimAll) |
|
|
ImGui::PopStyleVar(); |
|
|
ImGui::GetCurrentContext()->NavCursorVisible = true; |
|
|
ImGui::GetCurrentContext()->NavHighlightItemUnderNav = false; |
|
|
|
|
|
for (size_t i = 0; i < children.size(); ++i) |
|
|
children[i]->DrawTools(ctx); |
|
|
|
|
|
|
|
|
auto pad = ImGui::GetStyle().WindowPadding - ImVec2(3+1, 3); |
|
|
auto mi = ImGui::GetWindowContentRegionMin() - pad; |
|
|
auto ma = ImGui::GetWindowContentRegionMax() + pad; |
|
|
cached_pos = ImGui::GetWindowPos() + mi; |
|
|
cached_size = ma - mi; |
|
|
|
|
|
if (!ImGui::GetTopMostAndVisiblePopupModal() && ctx.activePopups.size() && |
|
|
ImGui::IsKeyPressed(ImGuiKey_Escape)) |
|
|
{ |
|
|
ctx.selected = { this }; |
|
|
} |
|
|
bool allowed = !ImGui::GetTopMostAndVisiblePopupModal() && ctx.activePopups.empty(); |
|
|
if (allowed && ctx.mode == UIContext::NormalSelection) |
|
|
{ |
|
|
if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) |
|
|
{ |
|
|
if (stx::count(ctx.selected, ctx.hovered)) |
|
|
ctx.selStart.x = FLT_MAX; |
|
|
else |
|
|
ctx.selStart = ctx.selEnd = ImGui::GetMousePos(); |
|
|
} |
|
|
if (ImGui::IsMouseDragging(ImGuiMouseButton_Left) && |
|
|
!ctx.beingResized && |
|
|
ctx.selStart.x != FLT_MAX && |
|
|
(!ImGui::IsWindowFocused(ImGuiFocusedFlags_AnyWindow) || ImGui::IsWindowFocused())) |
|
|
{ |
|
|
ctx.mode = UIContext::RectSelection; |
|
|
ctx.selEnd = ImGui::GetMousePos(); |
|
|
} |
|
|
} |
|
|
if (ctx.mode == UIContext::NormalSelection && |
|
|
ImGui::IsMouseReleased(ImGuiMouseButton_Left) && |
|
|
ImRect(ctx.designAreaMin, ctx.designAreaMax).Contains(ImGui::GetMousePos()) && |
|
|
(ImGui::IsWindowHovered() || |
|
|
(!ImGui::GetTopMostAndVisiblePopupModal() && !ImGui::IsAnyItemHovered() && !ImGui::IsWindowHovered(ImGuiHoveredFlags_AnyWindow)) |
|
|
)) |
|
|
{ |
|
|
if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl) || ImGui::IsKeyDown(ImGuiKey_RightCtrl)) |
|
|
; |
|
|
else |
|
|
ctx.selected = { this }; |
|
|
ImGui::GetIO().MouseReleased[ImGuiMouseButton_Left] = false; |
|
|
} |
|
|
if (ctx.mode == UIContext::RectSelection) |
|
|
{ |
|
|
if (ImGui::IsMouseDown(ImGuiMouseButton_Left)) |
|
|
ctx.selEnd = ImGui::GetMousePos(); |
|
|
else { |
|
|
ImVec2 a{ std::min(ctx.selStart.x, ctx.selEnd.x), std::min(ctx.selStart.y, ctx.selEnd.y) }; |
|
|
ImVec2 b{ std::max(ctx.selStart.x, ctx.selEnd.x), std::max(ctx.selStart.y, ctx.selEnd.y) }; |
|
|
auto sel = FindInRect(ImRect(a, b)); |
|
|
stx::erase(sel, this); |
|
|
if (sel.size()) { |
|
|
if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl) || ImGui::IsKeyDown(ImGuiKey_RightCtrl)) { |
|
|
for (auto s : sel) |
|
|
if (!stx::count(ctx.selected, s)) |
|
|
ctx.selected.push_back(s); |
|
|
} |
|
|
else |
|
|
ctx.selected = sel; |
|
|
} |
|
|
ctx.mode = UIContext::NormalSelection; |
|
|
} |
|
|
} |
|
|
if (allowed && ctx.mode == UIContext::PickPoint && |
|
|
!ctx.snapParent && |
|
|
ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows)) |
|
|
{ |
|
|
ctx.snapParent = this; |
|
|
ctx.snapIndex = children.size(); |
|
|
} |
|
|
|
|
|
if ((ctx.mode == UIContext::SnapInsert || ctx.mode == UIContext::SnapMove) && |
|
|
!ctx.snapParent && ImGui::IsWindowHovered()) |
|
|
{ |
|
|
DrawSnap(ctx); |
|
|
} |
|
|
if (ctx.snapParent && ctx.snapIndex == -1) |
|
|
{ |
|
|
ctx.snapParent = nullptr; |
|
|
} |
|
|
if (ctx.mode == UIContext::PickPoint && ctx.snapParent == this) |
|
|
{ |
|
|
DrawInteriorRect(ctx); |
|
|
} |
|
|
if (ctx.mode == UIContext::RectSelection) |
|
|
{ |
|
|
ImDrawList* dl = ImGui::GetForegroundDrawList(); |
|
|
ImVec2 a{ std::min(ctx.selStart.x, ctx.selEnd.x), std::min(ctx.selStart.y, ctx.selEnd.y) }; |
|
|
ImVec2 b{ std::max(ctx.selStart.x, ctx.selEnd.x), std::max(ctx.selStart.y, ctx.selEnd.y) }; |
|
|
dl->PushClipRect(ctx.designAreaMin, ctx.designAreaMax); |
|
|
dl->AddRectFilled(a, b, ctx.colors[UIContext::Hovered]); |
|
|
dl->PopClipRect(); |
|
|
} |
|
|
|
|
|
ImGui::End(); |
|
|
|
|
|
if (!style_bg.empty()) |
|
|
ImGui::PopStyleColor(); |
|
|
if (!style_menuBg.empty()) |
|
|
ImGui::PopStyleColor(); |
|
|
if (style_scrollbarSize.has_value()) |
|
|
ImGui::PopStyleVar(); |
|
|
if (style_rounding.has_value()) |
|
|
ImGui::PopStyleVar(); |
|
|
if (style_borderSize.has_value()) |
|
|
ImGui::PopStyleVar(); |
|
|
if (style_spacing.has_value()) |
|
|
ImGui::PopStyleVar(); |
|
|
if (style_innerSpacing.has_value()) |
|
|
ImGui::PopStyleVar(); |
|
|
if (style_padding.has_value()) |
|
|
ImGui::PopStyleVar(); |
|
|
if (style_font.has_value()) |
|
|
ImGui::PopFont(); |
|
|
} |
|
|
|
|
|
void TopWindow::Export(std::ostream& os, UIContext& ctx) |
|
|
{ |
|
|
ctx.varCounter = 1; |
|
|
ctx.parents = { this }; |
|
|
ctx.kind = kind; |
|
|
ctx.errors.clear(); |
|
|
ctx.unit = ctx.unit == "px" ? "" : ctx.unit; |
|
|
|
|
|
ctx.codeGen->RemovePrefixedVars(std::string(ctx.codeGen->HBOX_NAME)); |
|
|
ctx.codeGen->RemovePrefixedVars(std::string(ctx.codeGen->VBOX_NAME)); |
|
|
RenameFieldVars(CUR_ITEM_SYMBOL, std::string(ctx.codeGen->CUR_ITEM_VAR_NAME)); |
|
|
|
|
|
|
|
|
if (userCodeBefore != "") |
|
|
os << userCodeBefore << "\n"; |
|
|
|
|
|
|
|
|
bindable<std::string> titleId = title; |
|
|
if (titleId.access()->find("##") == std::string::npos) |
|
|
*titleId.access() += "###" + ctx.codeGen->GetName(); |
|
|
std::string tit = titleId.to_arg(); |
|
|
bool hasMB = children.size() && dynamic_cast<MenuBar*>(children[0].get()); |
|
|
bool autoSize = flags & ImGuiWindowFlags_AlwaysAutoResize; |
|
|
|
|
|
os << ctx.ind << "/// @begin TopWindow\n"; |
|
|
os << ctx.ind << "auto* ioUserData = (ImRad::IOUserData*)ImGui::GetIO().UserData;\n"; |
|
|
|
|
|
if (ctx.unit == "dp") |
|
|
{ |
|
|
os << ctx.ind << "const float dp = ioUserData->dpiScale;\n"; |
|
|
} |
|
|
|
|
|
if (kind == Popup || kind == ModalPopup) |
|
|
{ |
|
|
os << ctx.ind << "ID = ImGui::GetID(\"###" << ctx.codeGen->GetName() << "\");\n"; |
|
|
} |
|
|
else if (kind == Activity) |
|
|
{ |
|
|
if (initialActivity) |
|
|
{ |
|
|
os << ctx.ind << "if (ioUserData->activeActivity == \"\")\n"; |
|
|
ctx.ind_up(); |
|
|
os << ctx.ind << "Open();\n"; |
|
|
ctx.ind_down(); |
|
|
} |
|
|
os << ctx.ind << "if (ioUserData->activeActivity != \"" << ctx.codeGen->GetName() << "\")\n"; |
|
|
ctx.ind_up(); |
|
|
os << ctx.ind << "return;\n"; |
|
|
ctx.ind_down(); |
|
|
} |
|
|
|
|
|
if (!style_font.empty()) |
|
|
{ |
|
|
os << ctx.ind << "ImGui::PushFont(" << style_font.to_arg() << ");\n"; |
|
|
} |
|
|
if (!style_bg.empty()) |
|
|
{ |
|
|
os << ctx.ind << "ImGui::PushStyleColor(" << |
|
|
((kind == Popup || kind == ModalPopup) ? "ImGuiCol_PopupBg" : "ImGuiCol_WindowBg") << |
|
|
", " << style_bg.to_arg() << ");\n"; |
|
|
} |
|
|
if (!style_menuBg.empty()) |
|
|
{ |
|
|
os << ctx.ind << "ImGui::PushStyleColor(ImGuiCol_MenuBarBg, " << style_menuBg.to_arg() << ");\n"; |
|
|
} |
|
|
if (style_padding.has_value()) |
|
|
{ |
|
|
os << ctx.ind << "ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, " |
|
|
<< style_padding.to_arg(ctx.unit) << ");\n"; |
|
|
} |
|
|
if (style_spacing.has_value()) |
|
|
{ |
|
|
os << ctx.ind << "ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, " |
|
|
<< style_spacing.to_arg(ctx.unit) << ");\n"; |
|
|
} |
|
|
if (style_innerSpacing.has_value()) |
|
|
{ |
|
|
os << ctx.ind << "ImGui::PushStyleVar(ImGuiStyleVar_ItemInnerSpacing, " |
|
|
<< style_innerSpacing.to_arg(ctx.unit) << ");\n"; |
|
|
} |
|
|
if (style_rounding.has_value()) |
|
|
{ |
|
|
os << ctx.ind << "ImGui::PushStyleVar("; |
|
|
|
|
|
os << (kind == Popup ? "ImGuiStyleVar_PopupRounding" : "ImGuiStyleVar_WindowRounding"); |
|
|
os << ", " << style_rounding.to_arg(ctx.unit) << ");\n"; |
|
|
} |
|
|
if (style_borderSize.has_value() && kind != Activity && kind != MainWindow) |
|
|
{ |
|
|
os << ctx.ind << "ImGui::PushStyleVar("; |
|
|
os << ((kind == Popup || kind == ModalPopup) ? "ImGuiStyleVar_PopupBorderSize" : "ImGuiStyleVar_WindowBorderSize"); |
|
|
os << ", " << style_borderSize.to_arg(ctx.unit) << ");\n"; |
|
|
} |
|
|
if (style_scrollbarSize.has_value()) |
|
|
{ |
|
|
os << ctx.ind << "ImGui::PushStyleVar(ImGuiStyleVar_ScrollbarSize, " |
|
|
<< style_scrollbarSize.to_arg(ctx.unit) << ");\n"; |
|
|
} |
|
|
|
|
|
if (kind == MainWindow) |
|
|
{ |
|
|
os << ctx.ind << "ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0);\n"; |
|
|
os << ctx.ind << "glfwSetWindowTitle(window, " << title.to_arg() << ");\n"; |
|
|
os << ctx.ind << "ImGui::SetNextWindowPos({ 0, 0 });\n"; |
|
|
if (!autoSize) |
|
|
{ |
|
|
os << ctx.ind << "int tmpWidth, tmpHeight;\n"; |
|
|
os << ctx.ind << "glfwGetWindowSize(window, &tmpWidth, &tmpHeight);\n"; |
|
|
os << ctx.ind << "ImGui::SetNextWindowSize({ (float)tmpWidth, (float)tmpHeight });\n"; |
|
|
} |
|
|
|
|
|
auto fl = flags; |
|
|
fl |= ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoSavedSettings; |
|
|
os << ctx.ind << "bool tmpOpen;\n"; |
|
|
os << ctx.ind << "if (ImGui::Begin(\"###" << ctx.codeGen->GetName() << "\", &tmpOpen, " << fl.to_arg() << "))\n"; |
|
|
os << ctx.ind << "{\n"; |
|
|
ctx.ind_up(); |
|
|
|
|
|
if (autoSize) |
|
|
{ |
|
|
os << ctx.ind << "if (ImGui::IsWindowAppearing())\n" << ctx.ind << "{\n"; |
|
|
ctx.ind_up(); |
|
|
|
|
|
os << ctx.ind << "ImGui::GetStyle().DisplaySafeAreaPadding = { 0, 0 };\n"; |
|
|
os << ctx.ind << "glfwSetWindowAttrib(window, GLFW_RESIZABLE, false);\n"; |
|
|
os << ctx.ind << "glfwSetWindowAttrib(window, GLFW_DECORATED, " |
|
|
<< std::boolalpha << !(flags & ImGuiWindowFlags_NoTitleBar) << ");\n"; |
|
|
ctx.ind_down(); |
|
|
os << ctx.ind << "}\n"; |
|
|
|
|
|
|
|
|
os << ctx.ind << "else\n" << ctx.ind << "{\n"; |
|
|
ctx.ind_up(); |
|
|
os << ctx.ind << "ImVec2 size = ImGui::GetCurrentWindow()->SizeFull;\n"; |
|
|
os << ctx.ind << "glfwSetWindowSize(window, (int)size.x, (int)size.y);\n"; |
|
|
ctx.ind_down(); |
|
|
os << ctx.ind << "}\n"; |
|
|
} |
|
|
else |
|
|
{ |
|
|
os << ctx.ind << "if (ImGui::IsWindowAppearing())\n" << ctx.ind << "{\n"; |
|
|
ctx.ind_up(); |
|
|
if (placement == Maximize) |
|
|
os << ctx.ind << "glfwMaximizeWindow(window);\n"; |
|
|
else |
|
|
os << ctx.ind << "glfwSetWindowSize(window, " << size_x.to_arg(ctx.unit) |
|
|
<< ", " << size_y.to_arg(ctx.unit) << ");\n"; |
|
|
|
|
|
os << ctx.ind << "glfwSetWindowSizeLimits(window, " << |
|
|
minSize_x.to_arg(ctx.unit) << ", " << minSize_y.to_arg(ctx.unit) << |
|
|
", GLFW_DONT_CARE, GLFW_DONT_CARE);\n"; |
|
|
|
|
|
os << ctx.ind << "glfwSetWindowAttrib(window, GLFW_RESIZABLE, " |
|
|
<< std::boolalpha << !(flags & ImGuiWindowFlags_NoResize) << ");\n"; |
|
|
os << ctx.ind << "glfwSetWindowAttrib(window, GLFW_DECORATED, " |
|
|
<< std::boolalpha << !(flags & ImGuiWindowFlags_NoTitleBar) << ");\n"; |
|
|
ctx.ind_down(); |
|
|
os << ctx.ind << "}\n"; |
|
|
} |
|
|
} |
|
|
else if (kind == Activity) |
|
|
{ |
|
|
os << ctx.ind << "ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0);\n"; |
|
|
os << ctx.ind << "ImGui::SetNextWindowPos(ioUserData->WorkRect().Min);\n"; |
|
|
os << ctx.ind << "ImGui::SetNextWindowSize(ioUserData->WorkRect().GetSize());"; |
|
|
|
|
|
os << " //{ " << size_x.to_arg(ctx.unit) << ", " << size_y.to_arg(ctx.unit) << " }\n"; |
|
|
auto fl = flags; |
|
|
fl |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings; |
|
|
os << ctx.ind << "bool tmpOpen;\n"; |
|
|
os << ctx.ind << "if (ImGui::Begin(\"###" << ctx.codeGen->GetName() << "\", &tmpOpen, " << fl.to_arg() << "))\n"; |
|
|
os << ctx.ind << "{\n"; |
|
|
ctx.ind_up(); |
|
|
|
|
|
if (!onBackButton.empty()) { |
|
|
os << ctx.ind << "if (ImGui::IsKeyPressed(ImGuiKey_AppBack))\n"; |
|
|
ctx.ind_up(); |
|
|
os << ctx.ind << onBackButton.to_arg() << "();\n"; |
|
|
ctx.ind_down(); |
|
|
} |
|
|
} |
|
|
else if (kind == Window) |
|
|
{ |
|
|
|
|
|
if (placement == Left || placement == Top) |
|
|
{ |
|
|
os << ctx.ind << "ImGui::SetNextWindowPos(ioUserData->WorkRect().Min);"; |
|
|
os << (placement == Left ? " //Left\n" : " //Top\n"); |
|
|
} |
|
|
else if (placement == Right || placement == Bottom) |
|
|
{ |
|
|
os << ctx.ind << "ImGui::SetNextWindowPos(ioUserData->WorkRect().Max, 0, { 1, 1 });"; |
|
|
os << (placement == Right ? " //Right\n" : " //Bottom\n"); |
|
|
} |
|
|
|
|
|
|
|
|
os << ctx.ind << "ImGui::SetNextWindowSize({ "; |
|
|
|
|
|
if (placement == Top || placement == Bottom) |
|
|
os << "ioUserData->WorkRect().GetWidth()"; |
|
|
else if (autoSize) |
|
|
os << "0"; |
|
|
else |
|
|
os << size_x.to_arg(ctx.unit); |
|
|
|
|
|
os << ", "; |
|
|
|
|
|
if (placement == Left || placement == Right) |
|
|
os << "ioUserData->WorkRect().GetHeight()"; |
|
|
else if (autoSize) |
|
|
os << "0"; |
|
|
else |
|
|
os << size_y.to_arg(ctx.unit); |
|
|
|
|
|
os << " }"; |
|
|
if (!autoSize && placement != Left && placement != Right && placement != Top && placement != Bottom) |
|
|
os << ", ImGuiCond_FirstUseEver"; |
|
|
os << ");"; |
|
|
|
|
|
os << " //{ " << size_x.to_arg(ctx.unit) << ", " << size_y.to_arg(ctx.unit) << " }\n"; |
|
|
|
|
|
if (!autoSize) |
|
|
{ |
|
|
os << ctx.ind << "ImGui::SetNextWindowSizeConstraints({ " << |
|
|
minSize_x.to_arg(ctx.unit) << ", " << minSize_y.to_arg(ctx.unit) << |
|
|
" }, { FLT_MAX, FLT_MAX });\n"; |
|
|
} |
|
|
|
|
|
if (style_titlePadding.has_value()) |
|
|
{ |
|
|
os << ctx.ind << "ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, " << |
|
|
style_titlePadding.to_arg(ctx.unit) << ");\n"; |
|
|
} |
|
|
os << ctx.ind << "if (isOpen && ImGui::Begin(" << tit << ", &isOpen, " << flags.to_arg() << "))\n"; |
|
|
os << ctx.ind << "{\n"; |
|
|
ctx.ind_up(); |
|
|
if (style_titlePadding.has_value()) |
|
|
{ |
|
|
os << ctx.ind << "ImGui::PopStyleVar();\n"; |
|
|
os << ctx.ind << "ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImGui::GetStyle().FramePadding);\n"; |
|
|
} |
|
|
} |
|
|
else if (kind == Popup || kind == ModalPopup) |
|
|
{ |
|
|
if (placement == Left || placement == Top) |
|
|
{ |
|
|
os << ctx.ind << "ImGui::SetNextWindowPos("; |
|
|
if (animate) |
|
|
os << "{ ioUserData->WorkRect().Min.x + animPos.x, ioUserData->WorkRect().Min.y + animPos.y }"; |
|
|
else |
|
|
os << "ioUserData->WorkRect().Min"; |
|
|
os << "); " << (placement == Left ? " //Left\n" : " //Top\n"); |
|
|
} |
|
|
else if (placement == Right || placement == Bottom) |
|
|
{ |
|
|
os << ctx.ind << "ImGui::SetNextWindowPos("; |
|
|
if (animate) |
|
|
os << "{ ioUserData->WorkRect().Max.x - animPos.x, ioUserData->WorkRect().Max.y - animPos.y }, 0, { 1, 1 }"; |
|
|
else |
|
|
os << "ioUserData->WorkRect().Max, 0, { 1, 1 }"; |
|
|
os << "); " << (placement == Right ? " //Right\n" : " //Bottom\n"); |
|
|
} |
|
|
else if (placement == Center) |
|
|
{ |
|
|
os << ctx.ind << "ImGui::SetNextWindowPos("; |
|
|
if (animate) |
|
|
os << "{ ioUserData->WorkRect().GetCenter().x, ioUserData->WorkRect().GetCenter().y + animPos.y }, 0, { 0.5f, 0.5f }"; |
|
|
else |
|
|
os << "ioUserData->WorkRect().GetCenter(), 0, { 0.5f, 0.5f }"; |
|
|
os << "); //Center\n"; |
|
|
} |
|
|
|
|
|
|
|
|
os << ctx.ind << "ImGui::SetNextWindowSize({ "; |
|
|
|
|
|
if (placement == Top || placement == Bottom) |
|
|
os << "ioUserData->WorkRect().GetWidth()"; |
|
|
else if (autoSize) |
|
|
os << "0"; |
|
|
else |
|
|
os << size_x.to_arg(ctx.unit); |
|
|
|
|
|
os << ", "; |
|
|
|
|
|
if (placement == Left || placement == Right) |
|
|
os << "ioUserData->WorkRect().GetHeight()"; |
|
|
else if (autoSize) |
|
|
os << "0"; |
|
|
else |
|
|
os << size_y.to_arg(ctx.unit); |
|
|
|
|
|
os << " }"; |
|
|
if (!autoSize && placement != Left && placement != Right && placement != Top && placement != Bottom) |
|
|
os << ", ImGuiCond_FirstUseEver"; |
|
|
os << ");"; |
|
|
|
|
|
os << " //{ " << size_x.to_arg(ctx.unit) << ", " << size_y.to_arg(ctx.unit) << " }\n"; |
|
|
|
|
|
if (!autoSize) |
|
|
{ |
|
|
os << ctx.ind << "ImGui::SetNextWindowSizeConstraints({ " << |
|
|
minSize_x.to_arg(ctx.unit) << ", " << minSize_y.to_arg(ctx.unit) << |
|
|
" }, { FLT_MAX, FLT_MAX });\n"; |
|
|
} |
|
|
|
|
|
|
|
|
if (kind == ModalPopup) |
|
|
{ |
|
|
if (style_titlePadding.has_value()) |
|
|
{ |
|
|
os << ctx.ind << "ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, " << |
|
|
style_titlePadding.to_arg(ctx.unit) << ");\n"; |
|
|
} |
|
|
os << ctx.ind << "bool tmpOpen = true;\n"; |
|
|
os << ctx.ind << "if (ImGui::BeginPopupModal(" << tit << ", &tmpOpen, " << flags.to_arg() << "))\n"; |
|
|
os << ctx.ind << "{\n"; |
|
|
ctx.ind_up(); |
|
|
if (style_titlePadding.has_value()) |
|
|
{ |
|
|
os << ctx.ind << "ImGui::PopStyleVar();\n"; |
|
|
os << ctx.ind << "ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImGui::GetStyle().FramePadding);\n"; |
|
|
} |
|
|
} |
|
|
else |
|
|
{ |
|
|
os << ctx.ind << "if (ImGui::BeginPopup(" << tit << ", " << flags.to_arg() << "))\n"; |
|
|
os << ctx.ind << "{\n"; |
|
|
ctx.ind_up(); |
|
|
} |
|
|
|
|
|
|
|
|
if (animate) |
|
|
{ |
|
|
os << ctx.ind << "animator.Tick();\n"; |
|
|
if (placement == Left || placement == Right || placement == Top || placement == Bottom) |
|
|
{ |
|
|
os << ctx.ind << "if (!ImRad::MoveWhenDragging("; |
|
|
if (placement == Left) |
|
|
os << "ImGuiDir_Left"; |
|
|
else if (placement == Right) |
|
|
os << "ImGuiDir_Right"; |
|
|
else if (placement == Top) |
|
|
os << "ImGuiDir_Up"; |
|
|
else if (placement == Bottom) |
|
|
os << "ImGuiDir_Down"; |
|
|
os << ", animPos, ioUserData->dimBgRatio))\n"; |
|
|
ctx.ind_up(); |
|
|
os << ctx.ind << "ClosePopup();\n"; |
|
|
ctx.ind_down(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!onBackButton.empty()) |
|
|
{ |
|
|
os << ctx.ind << "if (ImGui::IsKeyPressed(ImGuiKey_AppBack))\n"; |
|
|
ctx.ind_up(); |
|
|
os << ctx.ind << onBackButton.to_arg() << "();\n"; |
|
|
ctx.ind_down(); |
|
|
} |
|
|
|
|
|
|
|
|
if (kind == ModalPopup) |
|
|
{ |
|
|
os << ctx.ind << "if (ioUserData->activeActivity != \"\")\n"; |
|
|
ctx.ind_up(); |
|
|
os << ctx.ind << "ImRad::RenderDimmedBackground(ioUserData->WorkRect(), ioUserData->dimBgRatio);\n"; |
|
|
ctx.ind_down(); |
|
|
} |
|
|
if (style_rounding && |
|
|
(placement == Left || placement == Right || placement == Top || placement == Bottom)) |
|
|
{ |
|
|
os << ctx.ind << "ImRad::RenderFilledWindowCorners(ImDrawFlags_RoundCorners"; |
|
|
if (placement == Left) |
|
|
os << "Left"; |
|
|
else if (placement == Right) |
|
|
os << "Right"; |
|
|
else if (placement == Top) |
|
|
os << "Top"; |
|
|
else if (placement == Bottom) |
|
|
os << "Bottom"; |
|
|
os << ");\n"; |
|
|
} |
|
|
|
|
|
|
|
|
os << ctx.ind << "if (modalResult != ImRad::None"; |
|
|
if (animate) |
|
|
os << " && animator.IsDone()"; |
|
|
os << ")\n"; |
|
|
os << ctx.ind << "{\n"; |
|
|
ctx.ind_up(); |
|
|
os << ctx.ind << "ImGui::CloseCurrentPopup();\n"; |
|
|
|
|
|
|
|
|
if (kind == ModalPopup) |
|
|
{ |
|
|
os << ctx.ind << "if (modalResult != ImRad::Cancel)\n"; |
|
|
ctx.ind_up(); |
|
|
os << ctx.ind << "callback(modalResult);\n"; |
|
|
ctx.ind_down(); |
|
|
} |
|
|
ctx.ind_down(); |
|
|
os << ctx.ind << "}\n"; |
|
|
|
|
|
if (closeOnEscape) |
|
|
{ |
|
|
os << ctx.ind << "if (ImGui::Shortcut(ImGuiKey_Escape))\n"; |
|
|
ctx.ind_up(); |
|
|
os << ctx.ind << "ClosePopup();\n"; |
|
|
ctx.ind_down(); |
|
|
} |
|
|
} |
|
|
|
|
|
if (!onWindowAppearing.empty()) |
|
|
{ |
|
|
os << ctx.ind << "if (ImGui::IsWindowAppearing())\n"; |
|
|
ctx.ind_up(); |
|
|
os << ctx.ind << onWindowAppearing.to_arg() << "();\n"; |
|
|
ctx.ind_down(); |
|
|
} |
|
|
|
|
|
os << ctx.ind << "/// @separator\n\n"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (children.empty() || children[0]->userCodeBefore.empty()) |
|
|
os << ctx.ind << "// TODO: Add Draw calls of dependent popup windows here\n\n"; |
|
|
|
|
|
for (const auto& ch : children) |
|
|
ch->Export(os, ctx); |
|
|
|
|
|
os << ctx.ind << "/// @separator\n"; |
|
|
|
|
|
if (kind == Popup || kind == ModalPopup) |
|
|
{ |
|
|
os << ctx.ind << "ImGui::EndPopup();\n"; |
|
|
ctx.ind_down(); |
|
|
os << ctx.ind << "}\n"; |
|
|
} |
|
|
else |
|
|
{ |
|
|
os << ctx.ind << "ImGui::End();\n"; |
|
|
ctx.ind_down(); |
|
|
os << ctx.ind << "}\n"; |
|
|
} |
|
|
|
|
|
if (style_titlePadding.has_value() && (kind == Window || kind == ModalPopup)) |
|
|
os << ctx.ind << "ImGui::PopStyleVar();\n"; |
|
|
if (style_scrollbarSize.has_value()) |
|
|
os << ctx.ind << "ImGui::PopStyleVar();\n"; |
|
|
if (style_borderSize.has_value() || kind == Activity || kind == MainWindow) |
|
|
os << ctx.ind << "ImGui::PopStyleVar();\n"; |
|
|
if (style_rounding.has_value()) |
|
|
os << ctx.ind << "ImGui::PopStyleVar();\n"; |
|
|
if (style_spacing.has_value()) |
|
|
os << ctx.ind << "ImGui::PopStyleVar();\n"; |
|
|
if (style_innerSpacing.has_value()) |
|
|
os << ctx.ind << "ImGui::PopStyleVar();\n"; |
|
|
if (style_padding.has_value()) |
|
|
os << ctx.ind << "ImGui::PopStyleVar();\n"; |
|
|
if (!style_bg.empty()) |
|
|
os << ctx.ind << "ImGui::PopStyleColor();\n"; |
|
|
if (!style_menuBg.empty()) |
|
|
os << ctx.ind << "ImGui::PopStyleColor();\n"; |
|
|
if (!style_font.empty()) |
|
|
os << ctx.ind << "ImGui::PopFont();\n"; |
|
|
|
|
|
os << ctx.ind << "/// @end TopWindow\n"; |
|
|
|
|
|
if (userCodeAfter != "") |
|
|
os << userCodeAfter << "\n"; |
|
|
|
|
|
RenameFieldVars(std::string(ctx.codeGen->CUR_ITEM_VAR_NAME), CUR_ITEM_SYMBOL); |
|
|
} |
|
|
|
|
|
void TopWindow::Import(cpp::stmt_iterator& sit, UIContext& ctx) |
|
|
{ |
|
|
ctx.errors.clear(); |
|
|
bool tmpCreateDeps = ctx.createVars; |
|
|
ctx.createVars = false; |
|
|
ctx.importState = 2; |
|
|
ctx.userCode = ""; |
|
|
ctx.root = this; |
|
|
ctx.parents = { this }; |
|
|
ctx.kind = kind = Window; |
|
|
bool hasGlfw = false; |
|
|
bool windowAppearingBlock = false; |
|
|
|
|
|
while (sit != cpp::stmt_iterator()) |
|
|
{ |
|
|
bool parseCommentSize = false; |
|
|
bool parseCommentPos = false; |
|
|
|
|
|
if (sit->kind == cpp::Comment && !sit->line.compare(0, 20, "/// @begin TopWindow")) |
|
|
{ |
|
|
ctx.importState = 1; |
|
|
sit.enable_parsing(true); |
|
|
userCodeBefore = ctx.userCode; |
|
|
ctx.userCode = ""; |
|
|
} |
|
|
else if (sit->kind == cpp::Comment && !sit->line.compare(0, 11, "/// @begin ")) |
|
|
{ |
|
|
ctx.importState = 1; |
|
|
sit.enable_parsing(true); |
|
|
std::string type = sit->line.substr(11); |
|
|
if (auto node = Widget::Create(type, ctx)) |
|
|
{ |
|
|
children.push_back(std::move(node)); |
|
|
children.back()->Import(++sit, ctx); |
|
|
ctx.importState = 2; |
|
|
ctx.userCode = ""; |
|
|
sit.enable_parsing(false); |
|
|
} |
|
|
} |
|
|
else if (sit->kind == cpp::Comment && !sit->line.compare(0, 18, "/// @end TopWindow")) |
|
|
{ |
|
|
ctx.importState = 3; |
|
|
ctx.userCode = ""; |
|
|
sit.enable_parsing(false); |
|
|
} |
|
|
else if (sit->kind == cpp::Comment && !sit->line.compare(0, 14, "/// @separator")) |
|
|
{ |
|
|
if (ctx.importState == 1) { |
|
|
ctx.importState = 2; |
|
|
ctx.userCode = ""; |
|
|
sit.enable_parsing(false); |
|
|
} |
|
|
else { |
|
|
if (!children.empty()) |
|
|
children.back()->userCodeAfter = ctx.userCode; |
|
|
else |
|
|
userCodeMid = ctx.userCode; |
|
|
ctx.userCode = ""; |
|
|
ctx.importState = 1; |
|
|
sit.enable_parsing(true); |
|
|
} |
|
|
} |
|
|
else if ((ctx.importState == 2 || ctx.importState == 3) && |
|
|
(sit->kind != cpp::Comment || sit->line.compare(0, 5, "/// @"))) |
|
|
{ |
|
|
if (ctx.importState == 3 && sit->line.size() && sit->line.back() == '}') { |
|
|
sit.base().stream().putback('}'); |
|
|
sit.enable_parsing(true); |
|
|
break; |
|
|
} |
|
|
if (ctx.userCode != "") |
|
|
ctx.userCode += "\n"; |
|
|
ctx.userCode += sit->line; |
|
|
} |
|
|
else if (sit->kind == cpp::IfStmt && sit->cond == "ioUserData->activeActivity==\"\"") |
|
|
{ |
|
|
initialActivity = true; |
|
|
} |
|
|
else if (sit->kind == cpp::IfCallBlock && sit->callee == "ImGui::IsWindowAppearing") |
|
|
{ |
|
|
windowAppearingBlock = true; |
|
|
} |
|
|
else if (sit->kind == cpp::Other && sit->line == "else" && |
|
|
sit->level == ctx.importLevel + 1) |
|
|
{ |
|
|
windowAppearingBlock = false; |
|
|
} |
|
|
else if (sit->kind == cpp::CallExpr && sit->callee == "ImGui::PushFont") |
|
|
{ |
|
|
if (sit->params.size()) |
|
|
style_font.set_from_arg(sit->params[0]); |
|
|
} |
|
|
else if (sit->kind == cpp::CallExpr && sit->callee == "ImGui::PushStyleColor") |
|
|
{ |
|
|
if (sit->params[0] == "ImGuiCol_WindowBg" || sit->params[0] == "ImGuiCol_PopupBg") |
|
|
style_bg.set_from_arg(sit->params[1]); |
|
|
else if (sit->params[0] == "ImGuiCol_MenuBarBg") |
|
|
style_menuBg.set_from_arg(sit->params[1]); |
|
|
} |
|
|
else if (sit->kind == cpp::CallExpr && sit->callee == "ImGui::PushStyleVar" && sit->params.size() == 2) |
|
|
{ |
|
|
if (sit->params[0] == "ImGuiStyleVar_WindowPadding") |
|
|
style_padding.set_from_arg(sit->params[1]); |
|
|
else if (sit->params[0] == "ImGuiStyleVar_ItemSpacing") |
|
|
style_spacing.set_from_arg(sit->params[1]); |
|
|
else if (sit->params[0] == "ImGuiStyleVar_ItemInnerSpacing") |
|
|
style_innerSpacing.set_from_arg(sit->params[1]); |
|
|
else if (sit->params[0] == "ImGuiStyleVar_WindowRounding" || sit->params[0] == "ImGuiStyleVar_PopupRounding") |
|
|
style_rounding.set_from_arg(sit->params[1]); |
|
|
else if (sit->params[0] == "ImGuiStyleVar_WindowBorderSize" || sit->params[0] == "ImGuiStyleVar_PopupBorderSize") |
|
|
style_borderSize.set_from_arg(sit->params[1]); |
|
|
else if (sit->params[0] == "ImGuiStyleVar_ScrollbarSize") |
|
|
style_scrollbarSize.set_from_arg(sit->params[1]); |
|
|
else if (sit->params[0] == "ImGuiStyleVar_FramePadding" && style_titlePadding.empty()) |
|
|
style_titlePadding.set_from_arg(sit->params[1]); |
|
|
} |
|
|
else if (sit->kind == cpp::CallExpr && sit->callee == "ImGui::SetNextWindowPos") |
|
|
{ |
|
|
parseCommentPos = true; |
|
|
animate = sit->line.find("animPos") != std::string::npos; |
|
|
} |
|
|
else if (sit->kind == cpp::CallExpr && sit->callee == "ImGui::SetNextWindowSize") |
|
|
{ |
|
|
parseCommentSize = true; |
|
|
if (sit->params.size()) |
|
|
{ |
|
|
auto size = cpp::parse_size(sit->params[0]); |
|
|
size_x.set_from_arg(size.first); |
|
|
size_y.set_from_arg(size.second); |
|
|
} |
|
|
} |
|
|
else if (sit->kind == cpp::CallExpr && sit->callee == "ImGui::SetNextWindowSizeConstraints") |
|
|
{ |
|
|
if (sit->params.size()) |
|
|
{ |
|
|
auto size = cpp::parse_size(sit->params[0]); |
|
|
minSize_x.set_from_arg(size.first); |
|
|
minSize_y.set_from_arg(size.second); |
|
|
} |
|
|
} |
|
|
else if (sit->kind == cpp::CallExpr && sit->callee == "glfwSetWindowTitle") |
|
|
{ |
|
|
hasGlfw = true; |
|
|
if (sit->params.size() >= 2) |
|
|
title.set_from_arg(sit->params[1]); |
|
|
} |
|
|
else if (sit->kind == cpp::CallExpr && sit->callee == "glfwSetWindowSize" && |
|
|
windowAppearingBlock) |
|
|
{ |
|
|
hasGlfw = true; |
|
|
if (sit->params.size() >= 3) { |
|
|
size_x.set_from_arg(sit->params[1]); |
|
|
size_y.set_from_arg(sit->params[2]); |
|
|
} |
|
|
} |
|
|
else if (sit->kind == cpp::CallExpr && sit->callee == "glfwSetWindowSizeLimits" && |
|
|
windowAppearingBlock) |
|
|
{ |
|
|
hasGlfw = true; |
|
|
if (sit->params.size() >= 3) { |
|
|
minSize_x.set_from_arg(sit->params[1]); |
|
|
minSize_y.set_from_arg(sit->params[2]); |
|
|
} |
|
|
} |
|
|
else if (sit->kind == cpp::CallExpr && sit->callee == "glfwMaximizeWindow") |
|
|
{ |
|
|
hasGlfw = true; |
|
|
placement = Maximize; |
|
|
} |
|
|
else if (sit->kind == cpp::CallExpr && sit->callee == "glfwSetWindowAttrib" |
|
|
&& sit->params.size() >= 3) |
|
|
{ |
|
|
hasGlfw = true; |
|
|
if (sit->params[1] == "GLFW_RESIZABLE") { |
|
|
bool resizable = sit->params[2] != "false"; |
|
|
if (!resizable && !(flags & ImGuiWindowFlags_AlwaysAutoResize)) |
|
|
flags |= ImGuiWindowFlags_NoResize; |
|
|
} |
|
|
else if (sit->params[1] == "GLFW_DECORATED") { |
|
|
bool decorated = sit->params[2] != "false"; |
|
|
if (!decorated) |
|
|
flags |= ImGuiWindowFlags_NoTitleBar; |
|
|
} |
|
|
} |
|
|
else if (sit->kind == cpp::IfCallThenCall && sit->cond == "ImGui::IsKeyPressed(ImGuiKey_AppBack)") |
|
|
{ |
|
|
onBackButton.set_from_arg(sit->callee2); |
|
|
} |
|
|
else if (sit->kind == cpp::IfCallThenCall && sit->cond == "ImGui::Shortcut(ImGuiKey_Escape)" && |
|
|
sit->callee2 == "ClosePopup") |
|
|
{ |
|
|
closeOnEscape = true; |
|
|
} |
|
|
else if (sit->kind == cpp::IfCallThenCall && sit->callee == "ImGui::IsWindowAppearing") |
|
|
{ |
|
|
if (sit->params.empty() && sit->params2.empty()) |
|
|
onWindowAppearing.set_from_arg(sit->callee2); |
|
|
} |
|
|
else if ((sit->kind == cpp::IfCallBlock || sit->kind == cpp::CallExpr) && |
|
|
sit->callee == "ImGui::BeginPopupModal") |
|
|
{ |
|
|
ctx.kind = kind = ModalPopup; |
|
|
title.set_from_arg(sit->params[0]); |
|
|
size_t i = title.access()->rfind("###"); |
|
|
if (i != std::string::npos) |
|
|
title.access()->resize(i); |
|
|
|
|
|
if (sit->params.size() >= 3) { |
|
|
if (!flags.set_from_arg(sit->params[2])) |
|
|
PushError(ctx, "unrecognized flag in \"" + sit->params[2] + "\""); |
|
|
} |
|
|
} |
|
|
else if ((sit->kind == cpp::IfCallBlock || sit->kind == cpp::CallExpr) && |
|
|
sit->callee == "ImGui::BeginPopup") |
|
|
{ |
|
|
ctx.kind = kind = Popup; |
|
|
title.set_from_arg(sit->params[0]); |
|
|
size_t i = title.access()->rfind("###"); |
|
|
if (i != std::string::npos) |
|
|
title.access()->resize(i); |
|
|
|
|
|
if (sit->params.size() >= 2) { |
|
|
if (!flags.set_from_arg(sit->params[1])) |
|
|
PushError(ctx, "unrecognized flag in \"" + sit->params[1] + "\""); |
|
|
} |
|
|
} |
|
|
else if (sit->kind == cpp::IfCallBlock && sit->callee == "isOpen&&ImGui::Begin") |
|
|
{ |
|
|
ctx.kind = kind = Window; |
|
|
title.set_from_arg(sit->params[0]); |
|
|
size_t i = title.access()->rfind("###"); |
|
|
if (i != std::string::npos) |
|
|
title.access()->resize(i); |
|
|
|
|
|
if (sit->params.size() >= 3) { |
|
|
if (!flags.set_from_arg(sit->params[2])) |
|
|
PushError(ctx, "unrecognized flag in \"" + sit->params[2] + "\""); |
|
|
} |
|
|
} |
|
|
else if (sit->kind == cpp::IfCallBlock && sit->callee == "ImGui::Begin") |
|
|
{ |
|
|
ctx.importLevel = sit->level; |
|
|
if (sit->params.size() >= 3) { |
|
|
if (!flags.set_from_arg(sit->params[2])) |
|
|
PushError(ctx, "unrecognized flag in \"" + sit->params[2] + "\""); |
|
|
} |
|
|
|
|
|
if (hasGlfw) { |
|
|
ctx.kind = kind = MainWindow; |
|
|
|
|
|
TopWindow def(ctx); |
|
|
size_x = def.size_x; |
|
|
size_y = def.size_y; |
|
|
flags &= ~(ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoSavedSettings); |
|
|
} |
|
|
else { |
|
|
ctx.kind = kind = Activity; |
|
|
placement = None; |
|
|
flags &= ~(ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings); |
|
|
} |
|
|
} |
|
|
|
|
|
++sit; |
|
|
|
|
|
if (sit->kind == cpp::Comment && parseCommentSize) |
|
|
{ |
|
|
auto size = cpp::parse_size(sit->line.substr(2)); |
|
|
size_x.set_from_arg(size.first); |
|
|
size_y.set_from_arg(size.second); |
|
|
} |
|
|
else if (sit->kind == cpp::Comment && parseCommentPos) |
|
|
{ |
|
|
if (sit->line == "//Left") |
|
|
placement = Left; |
|
|
else if (sit->line == "//Right") |
|
|
placement = Right; |
|
|
else if (sit->line == "//Top") |
|
|
placement = Top; |
|
|
else if (sit->line == "//Bottom") |
|
|
placement = Bottom; |
|
|
else if (sit->line == "//Center") |
|
|
placement = Center; |
|
|
else if (sit->line == "//Maximize") |
|
|
placement = Maximize; |
|
|
} |
|
|
} |
|
|
|
|
|
userCodeAfter = ctx.userCode; |
|
|
ctx.createVars = tmpCreateDeps; |
|
|
RenameFieldVars(std::string(ctx.codeGen->CUR_ITEM_VAR_NAME), CUR_ITEM_SYMBOL); |
|
|
} |
|
|
|
|
|
void TopWindow::TreeUI(UIContext& ctx) |
|
|
{ |
|
|
static const char* NAMES[]{ "MainWindow", "Window", "Popup", "ModalPopup", "Activity" }; |
|
|
|
|
|
ctx.parents = { this }; |
|
|
std::string str = ctx.codeGen->GetName(); |
|
|
bool selected = stx::count(ctx.selected, this) || ctx.snapParent == this; |
|
|
if (selected) |
|
|
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyle().Colors[ImGuiCol_ButtonHovered]); |
|
|
ImGui::SetNextItemOpen(true, ImGuiCond_Always); |
|
|
if (ImGui::TreeNodeEx(str.c_str(), ImGuiTreeNodeFlags_SpanAllColumns)) |
|
|
{ |
|
|
if (selected) |
|
|
ImGui::PopStyleColor(); |
|
|
bool activated = ImGui::IsItemClicked(); |
|
|
ImGui::SameLine(0, 0); |
|
|
ImGui::TextDisabled(" : %s", NAMES[kind]); |
|
|
if (activated) |
|
|
{ |
|
|
if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl) || ImGui::IsKeyDown(ImGuiKey_RightCtrl)) |
|
|
; |
|
|
else |
|
|
ctx.selected = { this }; |
|
|
} |
|
|
for (const auto& ch : children) |
|
|
ch->TreeUI(ctx); |
|
|
|
|
|
ImGui::TreePop(); |
|
|
} |
|
|
else { |
|
|
if (selected) |
|
|
ImGui::PopStyleColor(); |
|
|
ImGui::SameLine(0, 0); |
|
|
ImGui::TextDisabled(" : %s", NAMES[kind]); |
|
|
} |
|
|
} |
|
|
|
|
|
std::vector<UINode::Prop> |
|
|
TopWindow::Properties() |
|
|
{ |
|
|
return { |
|
|
{ "appearance.bg", &style_bg }, |
|
|
{ "appearance.menuBg", &style_menuBg }, |
|
|
{ "appearance.padding", &style_padding }, |
|
|
{ "appearance.titlePadding", &style_titlePadding }, |
|
|
{ "appearance.rounding", &style_rounding }, |
|
|
{ "appearance.borderSize", &style_borderSize }, |
|
|
{ "appearance.scrollbarSize", &style_scrollbarSize }, |
|
|
{ "appearance.spacing", &style_spacing }, |
|
|
{ "appearance.innerSpacing", &style_innerSpacing }, |
|
|
{ "appearance.font", &style_font }, |
|
|
{ "behavior.flags", nullptr }, |
|
|
{ "behavior.kind", nullptr }, |
|
|
{ "behavior.title", &title, true }, |
|
|
{ "behavior.closeOnEscape", &closeOnEscape }, |
|
|
{ "behavior.initialActivity", &initialActivity }, |
|
|
{ "behavior.animate", &animate }, |
|
|
{ "layout.size.size", nullptr }, |
|
|
{ "layout.size.size_x", &size_x }, |
|
|
{ "layout.size.size_y", &size_y }, |
|
|
{ "layout.minSize.size", nullptr }, |
|
|
{ "layout.minSize.size_x", &minSize_x }, |
|
|
{ "layout.minSize.size_y", &minSize_y }, |
|
|
{ "layout.placement", &placement }, |
|
|
}; |
|
|
} |
|
|
|
|
|
bool TopWindow::PropertyUI(int i, UIContext& ctx) |
|
|
{ |
|
|
bool changed = false; |
|
|
int fl = 0; |
|
|
switch (i) |
|
|
{ |
|
|
case 0: |
|
|
{ |
|
|
ImGui::Text("bg"); |
|
|
ImGui::TableNextColumn(); |
|
|
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight()); |
|
|
int clr = (kind == Popup || kind == ModalPopup) ? ImGuiCol_PopupBg : ImGuiCol_WindowBg; |
|
|
changed = InputBindable(&style_bg, clr, ctx); |
|
|
ImGui::SameLine(0, 0); |
|
|
changed |= BindingButton("bg", &style_bg, ctx); |
|
|
break; |
|
|
} |
|
|
case 1: |
|
|
ImGui::Text("menuBarBg"); |
|
|
ImGui::TableNextColumn(); |
|
|
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight()); |
|
|
changed = InputBindable(&style_menuBg, ImGuiCol_MenuBarBg, ctx); |
|
|
ImGui::SameLine(0, 0); |
|
|
changed |= BindingButton("menuBarBg", &style_menuBg, ctx); |
|
|
break; |
|
|
case 2: |
|
|
{ |
|
|
ImGui::Text("padding"); |
|
|
ImGui::TableNextColumn(); |
|
|
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight()); |
|
|
changed = InputDirectVal(&style_padding, ctx); |
|
|
break; |
|
|
} |
|
|
case 3: |
|
|
{ |
|
|
ImGui::Text("titlePadding"); |
|
|
ImGui::TableNextColumn(); |
|
|
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight()); |
|
|
changed = InputDirectVal(&style_titlePadding, ctx); |
|
|
break; |
|
|
} |
|
|
case 4: |
|
|
{ |
|
|
ImGui::Text("rounding"); |
|
|
ImGui::TableNextColumn(); |
|
|
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight()); |
|
|
changed = InputDirectVal(&style_rounding, ctx); |
|
|
break; |
|
|
} |
|
|
case 5: |
|
|
{ |
|
|
ImGui::Text("borderSize"); |
|
|
ImGui::TableNextColumn(); |
|
|
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight()); |
|
|
changed = InputDirectVal(&style_borderSize, ctx); |
|
|
break; |
|
|
} |
|
|
case 6: |
|
|
{ |
|
|
ImGui::Text("scrollbarSize"); |
|
|
ImGui::TableNextColumn(); |
|
|
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight()); |
|
|
changed = InputDirectVal(&style_scrollbarSize, ctx); |
|
|
break; |
|
|
} |
|
|
case 7: |
|
|
{ |
|
|
ImGui::Text("spacing"); |
|
|
ImGui::TableNextColumn(); |
|
|
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight()); |
|
|
changed = InputDirectVal(&style_spacing, ctx); |
|
|
break; |
|
|
} |
|
|
case 8: |
|
|
{ |
|
|
ImGui::Text("innerSpacing"); |
|
|
ImGui::TableNextColumn(); |
|
|
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight()); |
|
|
changed = InputDirectVal(&style_innerSpacing, ctx); |
|
|
break; |
|
|
} |
|
|
case 9: |
|
|
ImGui::Text("font"); |
|
|
ImGui::TableNextColumn(); |
|
|
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight()); |
|
|
changed = InputBindable(&style_font, ctx); |
|
|
ImGui::SameLine(0, 0); |
|
|
changed |= BindingButton("font", &style_font, ctx); |
|
|
break; |
|
|
case 10: |
|
|
{ |
|
|
ImGui::Text("kind"); |
|
|
ImGui::TableNextColumn(); |
|
|
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight()); |
|
|
fl = kind != Defaults().kind ? InputDirectVal_Modified : 0; |
|
|
changed = InputDirectValEnum(&kind, fl, ctx); |
|
|
break; |
|
|
} |
|
|
case 11: |
|
|
{ |
|
|
bool hasAutoResize = flags & ImGuiWindowFlags_AlwaysAutoResize; |
|
|
bool hasMB = children.size() && dynamic_cast<MenuBar*>(children[0].get()); |
|
|
changed = InputDirectValFlags("flags", &flags, Defaults().flags, ctx); |
|
|
if (changed) |
|
|
{ |
|
|
bool flagsMB = flags & ImGuiWindowFlags_MenuBar; |
|
|
if (flagsMB && !hasMB) |
|
|
children.insert(children.begin(), std::make_unique<MenuBar>(ctx)); |
|
|
else if (!flagsMB && hasMB) |
|
|
children.erase(children.begin()); |
|
|
|
|
|
} |
|
|
break; |
|
|
} |
|
|
case 12: |
|
|
ImGui::Text("title"); |
|
|
ImGui::TableNextColumn(); |
|
|
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight()); |
|
|
changed = InputBindable(&title, 0, ctx); |
|
|
ImGui::SameLine(0, 0); |
|
|
changed |= BindingButton("title", &title, ctx); |
|
|
break; |
|
|
case 13: |
|
|
ImGui::BeginDisabled(kind != Popup && kind != ModalPopup); |
|
|
ImGui::Text("closeOnEscape"); |
|
|
ImGui::TableNextColumn(); |
|
|
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight()); |
|
|
fl = closeOnEscape != Defaults().closeOnEscape ? InputDirectVal_Modified : 0; |
|
|
changed = InputDirectVal(&closeOnEscape, fl, ctx); |
|
|
ImGui::EndDisabled(); |
|
|
break; |
|
|
case 14: |
|
|
ImGui::BeginDisabled(kind != Activity); |
|
|
ImGui::Text("initialActivity"); |
|
|
ImGui::TableNextColumn(); |
|
|
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight()); |
|
|
fl = initialActivity != Defaults().initialActivity ? InputDirectVal_Modified : 0; |
|
|
changed = InputDirectVal(&initialActivity, fl, ctx); |
|
|
ImGui::EndDisabled(); |
|
|
break; |
|
|
case 15: |
|
|
ImGui::BeginDisabled(kind != Popup && kind != ModalPopup); |
|
|
ImGui::Text("animate"); |
|
|
ImGui::TableNextColumn(); |
|
|
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight()); |
|
|
fl = animate != Defaults().animate ? InputDirectVal_Modified : 0; |
|
|
changed = InputDirectVal(&animate, fl, ctx); |
|
|
ImGui::EndDisabled(); |
|
|
break; |
|
|
case 16: |
|
|
ImGui::BeginDisabled((flags & ImGuiWindowFlags_AlwaysAutoResize) || placement == Maximize); |
|
|
ImGui::Text(kind == Activity ? "designSize" : "size"); |
|
|
ImGui::TableNextColumn(); |
|
|
fl = size_x != Defaults().size_x || size_y != Defaults().size_y; |
|
|
ImGui::PushFont(!ImRad::IsCurrentItemDisabled() && fl ? |
|
|
ctx.pgbFont : ctx.pgFont); |
|
|
ImGui::TextUnformatted((size_x.to_arg("") + ", " + size_y.to_arg("")).c_str()); |
|
|
ImGui::PopFont(); |
|
|
ImGui::EndDisabled(); |
|
|
break; |
|
|
case 17: |
|
|
ImGui::BeginDisabled((flags & ImGuiWindowFlags_AlwaysAutoResize) || placement == Maximize); |
|
|
ImGui::Text("size_x"); |
|
|
ImGui::TableNextColumn(); |
|
|
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight()); |
|
|
fl = size_x != Defaults().size_x ? InputBindable_Modified : 0; |
|
|
changed = InputBindable(&size_x, fl, ctx); |
|
|
ImGui::SameLine(0, 0); |
|
|
changed |= BindingButton("size_x", &size_x, ctx); |
|
|
ImGui::EndDisabled(); |
|
|
break; |
|
|
case 18: |
|
|
ImGui::BeginDisabled((flags & ImGuiWindowFlags_AlwaysAutoResize) || placement == Maximize); |
|
|
ImGui::Text("size_y"); |
|
|
ImGui::TableNextColumn(); |
|
|
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight()); |
|
|
fl = size_y != Defaults().size_y ? InputBindable_Modified : 0; |
|
|
changed = InputBindable(&size_y, fl, ctx); |
|
|
ImGui::SameLine(0, 0); |
|
|
changed |= BindingButton("size_y", &size_y, ctx); |
|
|
ImGui::EndDisabled(); |
|
|
break; |
|
|
case 19: |
|
|
ImGui::BeginDisabled((flags & ImGuiWindowFlags_AlwaysAutoResize) || kind == Activity); |
|
|
ImGui::Text("minimumSize"); |
|
|
ImGui::TableNextColumn(); |
|
|
fl = minSize_x != Defaults().minSize_x || minSize_y != Defaults().minSize_y; |
|
|
ImGui::PushFont(!ImRad::IsCurrentItemDisabled() && fl ? |
|
|
ctx.pgbFont : ctx.pgFont); |
|
|
ImGui::TextUnformatted((minSize_x.to_arg("") + ", " + minSize_y.to_arg("")).c_str()); |
|
|
ImGui::PopFont(); |
|
|
ImGui::EndDisabled(); |
|
|
break; |
|
|
case 20: |
|
|
ImGui::BeginDisabled((flags & ImGuiWindowFlags_AlwaysAutoResize) || kind == Activity); |
|
|
ImGui::Text("size_x"); |
|
|
ImGui::TableNextColumn(); |
|
|
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight()); |
|
|
fl = minSize_x != Defaults().minSize_x ? InputBindable_Modified : 0; |
|
|
changed = InputBindable(&minSize_x, fl, ctx); |
|
|
ImGui::SameLine(0, 0); |
|
|
changed |= BindingButton("minSize_x", &minSize_x, ctx); |
|
|
ImGui::EndDisabled(); |
|
|
break; |
|
|
case 21: |
|
|
ImGui::BeginDisabled((flags & ImGuiWindowFlags_AlwaysAutoResize) || kind == Activity); |
|
|
ImGui::Text("size_y"); |
|
|
ImGui::TableNextColumn(); |
|
|
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight()); |
|
|
fl = minSize_y != Defaults().minSize_y ? InputBindable_Modified : 0; |
|
|
changed = InputBindable(&minSize_y, fl, ctx); |
|
|
ImGui::SameLine(0, 0); |
|
|
changed |= BindingButton("minSize_y", &minSize_y, ctx); |
|
|
ImGui::EndDisabled(); |
|
|
break; |
|
|
case 22: |
|
|
{ |
|
|
ImGui::BeginDisabled(kind == Activity); |
|
|
ImGui::Text("placement"); |
|
|
ImGui::TableNextColumn(); |
|
|
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight()); |
|
|
|
|
|
placement.clear(); |
|
|
placement.add("None", None); |
|
|
if (kind == Popup || kind == ModalPopup || kind == Window) { |
|
|
placement.add$(Left); |
|
|
placement.add$(Right); |
|
|
placement.add$(Top); |
|
|
placement.add$(Bottom); |
|
|
} |
|
|
if (kind == Popup || kind == ModalPopup) |
|
|
placement.add$(Center); |
|
|
if (kind == MainWindow) |
|
|
placement.add$(Maximize); |
|
|
|
|
|
if (placement.get_id() == "") { |
|
|
|
|
|
changed = true; |
|
|
placement = None; |
|
|
} |
|
|
fl = placement != Defaults().placement ? InputDirectVal_Modified : 0; |
|
|
changed = InputDirectValEnum(&placement, fl, ctx); |
|
|
ImGui::EndDisabled(); |
|
|
break; |
|
|
} |
|
|
default: |
|
|
return false; |
|
|
} |
|
|
return changed; |
|
|
} |
|
|
|
|
|
std::vector<UINode::Prop> |
|
|
TopWindow::Events() |
|
|
{ |
|
|
return { |
|
|
{ "window.appearing", &onWindowAppearing }, |
|
|
{ "window.backButton", &onBackButton }, |
|
|
}; |
|
|
} |
|
|
|
|
|
bool TopWindow::EventUI(int i, UIContext& ctx) |
|
|
{ |
|
|
bool changed = false; |
|
|
switch (i) |
|
|
{ |
|
|
case 0: |
|
|
ImGui::Text("Appearing"); |
|
|
ImGui::TableNextColumn(); |
|
|
ImGui::SetNextItemWidth(-1); |
|
|
changed = InputEvent("Window_Appearing", &onWindowAppearing, 0, ctx); |
|
|
break; |
|
|
case 1: |
|
|
ImGui::Text("BackButton"); |
|
|
ImGui::TableNextColumn(); |
|
|
ImGui::SetNextItemWidth(-1); |
|
|
changed = InputEvent("Window_BackButton", &onBackButton, 0, ctx); |
|
|
break; |
|
|
} |
|
|
return changed; |
|
|
} |
|
|
|