CoolFace
Datasetpublic

dlxjj/imradv3

sourceHugging Faceupdated 8mo agoView on Hugging Face
0likes262downloads
node_window.cpp1416 linesDownload Raw Back to src
1#include "node_window.h"2#include "node_container.h"3#include "stx.h"4#include "imrad.h"5#include "cppgen.h"6#include "binding_input.h"7#include "binding_eval.h"8#include "ui_message_box.h"9#include <algorithm>10#include <array>11 12//----------------------------------------------------------------------------13 14TopWindow::TopWindow(UIContext& ctx)15    : kind(Kind(ctx.kind))16{17    if (kind == Activity) {18        title = "MyActivity";19        size_x = 400;20        size_y = 700;21    }22    else {23        size_x = 640;24        size_y = 480;25    }26 27    kind.add("Main Window (GLFW)", MainWindow);28    kind.add$(Window);29    kind.add$(Popup);30    kind.add$(ModalPopup);31    kind.add("Activity (Android)", Activity);32 33    flags.add$(ImGuiWindowFlags_AlwaysAutoResize);34    flags.add$(ImGuiWindowFlags_AlwaysHorizontalScrollbar);35    flags.add$(ImGuiWindowFlags_AlwaysVerticalScrollbar);36    flags.add$(ImGuiWindowFlags_MenuBar);37    flags.add$(ImGuiWindowFlags_NoBackground);38    flags.add$(ImGuiWindowFlags_NoCollapse);39    flags.add$(ImGuiWindowFlags_NoDocking);40    flags.add$(ImGuiWindowFlags_NoFocusOnAppearing);41    flags.add$(ImGuiWindowFlags_NoMove);42    flags.add$(ImGuiWindowFlags_NoNavInputs);43    flags.add$(ImGuiWindowFlags_NoNavFocus);44    flags.add$(ImGuiWindowFlags_NoResize);45    flags.add$(ImGuiWindowFlags_NoSavedSettings);46    flags.add$(ImGuiWindowFlags_NoScrollbar);47    flags.add$(ImGuiWindowFlags_NoScrollWithMouse);48    flags.add$(ImGuiWindowFlags_NoTitleBar);49 50    placement.add$(None);51    placement.add$(Left);52    placement.add$(Right);53    placement.add$(Top);54    placement.add$(Bottom);55    placement.add$(Center);56    placement.add$(Maximize);57}58 59void TopWindow::Draw(UIContext& ctx)60{61    ctx.unit = ctx.unit == "px" ? "" : ctx.unit;62    ctx.root = this;63    ctx.isAutoSize = flags & ImGuiWindowFlags_AlwaysAutoResize;64    ctx.prevLayoutHash = ctx.layoutHash;65    ctx.layoutHash = ctx.isAutoSize;66    bool dimAll = ctx.activePopups.size(); //from last frame67    ctx.activePopups.clear();68    ctx.parents = { this };69    ctx.hovered = nullptr;70    ctx.snapParent = nullptr;71    ctx.kind = kind;72    ctx.contextMenus.clear();73 74    std::string cap = title.value();75    cap += "###TopWindow" + std::to_string((size_t)this); //don't clash76    int fl = ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoSavedSettings;77    if (ctx.mode != UIContext::NormalSelection)78        fl |= ImGuiWindowFlags_NoResize; //so that window resizing doesn't interfere with snap79    if (kind == MainWindow)80        fl |= ImGuiWindowFlags_NoCollapse;81    else if (kind == Popup)82        fl |= ImGuiWindowFlags_NoTitleBar;83    else if (kind == Activity) //only allow resizing here to test layout behavior84        fl |= ImGuiWindowFlags_NoTitleBar /*| ImGuiWindowFlags_NoResize*/ | ImGuiWindowFlags_NoCollapse;85    fl |= flags;86 87    if (style_font.has_value())88        ImGui::PushFont(ImRad::GetFontByName(style_font.eval(ctx)));89    if (style_padding.has_value())90        ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, style_padding.eval_px(ctx));91    if (style_spacing.has_value())92        ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, style_spacing.eval_px(ctx));93    if (style_innerSpacing.has_value())94        ImGui::PushStyleVar(ImGuiStyleVar_ItemInnerSpacing, style_innerSpacing.eval_px(ctx));95    if (style_borderSize.has_value())96        ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, style_borderSize.eval_px(ctx));97    if (style_rounding.has_value())98        ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, style_rounding.eval_px(ctx));99    if (style_scrollbarSize.has_value())100        ImGui::PushStyleVar(ImGuiStyleVar_ScrollbarSize, style_scrollbarSize.eval_px(ctx));101    if (!style_bg.empty())102        ImGui::PushStyleColor(ImGuiCol_WindowBg, style_bg.eval(ImGuiCol_WindowBg, ctx));103    if (!style_menuBg.empty())104        ImGui::PushStyleColor(ImGuiCol_MenuBarBg, style_menuBg.eval(ImGuiCol_MenuBarBg, ctx));105 106    ImGui::SetNextWindowScroll({ 0, 0 }); //click on a child causes scrolling which doesn't go back107    ImGui::SetNextWindowPos(ctx.designAreaMin + ImVec2{ 20, 20 }); // , ImGuiCond_Always, { 0.5, 0.5 });108 109    if (kind == MainWindow && placement == Maximize)110    {111        ImGui::SetNextWindowSize(ctx.designAreaMax - ctx.designAreaMin - ImVec2{ 40, 40 });112    }113    else if (fl & ImGuiWindowFlags_AlwaysAutoResize)114    {115        //prevent autosized window to collapse116        ImGui::SetNextWindowSizeConstraints({ 30, 30 }, { FLT_MAX, FLT_MAX });117    }118    else119    {120        float w = size_x.eval_px(ImGuiAxis_X, ctx);121        if (!w)122            w = 640;123        float h = size_y.eval_px(ImGuiAxis_Y, ctx);124        if (!h)125            h = 480;126        ImGui::SetNextWindowSize({ w, h });127        w = minSize_x.eval_px(ImGuiAxis_X, ctx);128        h = minSize_y.eval_px(ImGuiAxis_Y, ctx);129        ImGui::SetNextWindowSizeConstraints({ w, h }, { FLT_MAX, FLT_MAX });130    }131 132    if (style_titlePadding.has_value())133        ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, style_titlePadding.eval_px(ctx));134 135    bool tmp;136    ImGui::Begin(cap.c_str(), &tmp, fl);137 138    if (style_titlePadding.has_value())139        ImGui::PopStyleVar();140 141    ImGui::SetWindowFontScale(ctx.zoomFactor);142 143    ctx.rootWin = ImGui::FindWindowByName(cap.c_str());144    assert(ctx.rootWin);145    for (int i = 0; i < 4; ++i)146    {147        if (ImGui::GetActiveID() == ImGui::GetWindowResizeCornerID(ctx.rootWin, i) ||148            ImGui::GetActiveID() == ImGui::GetWindowResizeBorderID(ctx.rootWin, (ImGuiDir)i))149            ctx.beingResized = true;150    }151    if (ctx.beingResized && ImGui::IsMouseReleased(ImGuiMouseButton_Left)) {152        ctx.beingResized = false;153        ImGui::GetIO().MouseReleased[ImGuiMouseButton_Left] = false; //eat event so random widget won't get selected154    }155    if (ctx.beingResized)156        ctx.selected = { this }; //reset selection so there is no visual noise157 158    if (placement == Left)159        ImRad::RenderFilledWindowCorners(ImDrawFlags_RoundCornersLeft);160    else if (placement == Right)161        ImRad::RenderFilledWindowCorners(ImDrawFlags_RoundCornersRight);162    else if (placement == Top)163        ImRad::RenderFilledWindowCorners(ImDrawFlags_RoundCornersTop);164    else if (placement == Bottom)165        ImRad::RenderFilledWindowCorners(ImDrawFlags_RoundCornersBottom);166 167    ImGui::GetCurrentContext()->NavHighlightItemUnderNav = true;168    ImGui::GetCurrentContext()->NavCursorVisible = false;169    if (dimAll)170        ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 0.2f);171 172    for (size_t i = 0; i < children.size(); ++i)173        children[i]->Draw(ctx);174 175    if (dimAll)176        ImGui::PopStyleVar();177    ImGui::GetCurrentContext()->NavCursorVisible = true;178    ImGui::GetCurrentContext()->NavHighlightItemUnderNav = false;179 180    for (size_t i = 0; i < children.size(); ++i)181        children[i]->DrawTools(ctx);182 183    //use all client area to allow snapping close to the border184    auto pad = ImGui::GetStyle().WindowPadding - ImVec2(3+1, 3);185    auto mi = ImGui::GetWindowContentRegionMin() - pad;186    auto ma = ImGui::GetWindowContentRegionMax() + pad;187    cached_pos = ImGui::GetWindowPos() + mi;188    cached_size = ma - mi;189 190    if (!ImGui::GetTopMostAndVisiblePopupModal() && ctx.activePopups.size() &&191        ImGui::IsKeyPressed(ImGuiKey_Escape))192    {193        ctx.selected = { this };194    }195    bool allowed = !ImGui::GetTopMostAndVisiblePopupModal() && ctx.activePopups.empty();196    if (allowed && ctx.mode == UIContext::NormalSelection)197    {198        if (ImGui::IsMouseClicked(ImGuiMouseButton_Left))199        {200            if (stx::count(ctx.selected, ctx.hovered)) //selected widget might want to do SnapMove instead201                ctx.selStart.x = FLT_MAX;202            else203                ctx.selStart = ctx.selEnd = ImGui::GetMousePos();204        }205        if (ImGui::IsMouseDragging(ImGuiMouseButton_Left) &&206            !ctx.beingResized &&207            ctx.selStart.x != FLT_MAX && //todo: initiate SnapMove, cursor is out of the widget already208            (!ImGui::IsWindowFocused(ImGuiFocusedFlags_AnyWindow) || ImGui::IsWindowFocused())) //no RectSel during docking209        {210            ctx.mode = UIContext::RectSelection;211            ctx.selEnd = ImGui::GetMousePos();212        }213    }214    if (ctx.mode == UIContext::NormalSelection &&215        ImGui::IsMouseReleased(ImGuiMouseButton_Left) &&216        ImRect(ctx.designAreaMin, ctx.designAreaMax).Contains(ImGui::GetMousePos()) &&217        (ImGui::IsWindowHovered() || //includes !GetTopMostAndVisiblePopupModal218        (!ImGui::GetTopMostAndVisiblePopupModal() && !ImGui::IsAnyItemHovered() && !ImGui::IsWindowHovered(ImGuiHoveredFlags_AnyWindow))219        ))220    {221        if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl) || ImGui::IsKeyDown(ImGuiKey_RightCtrl))222            ; //don't participate in group selection223        else224            ctx.selected = { this };225        ImGui::GetIO().MouseReleased[ImGuiMouseButton_Left] = false; //eat event226    }227    if (ctx.mode == UIContext::RectSelection)228    {229        if (ImGui::IsMouseDown(ImGuiMouseButton_Left))230            ctx.selEnd = ImGui::GetMousePos();231        else {232            ImVec2 a{ std::min(ctx.selStart.x, ctx.selEnd.x), std::min(ctx.selStart.y, ctx.selEnd.y) };233            ImVec2 b{ std::max(ctx.selStart.x, ctx.selEnd.x), std::max(ctx.selStart.y, ctx.selEnd.y) };234            auto sel = FindInRect(ImRect(a, b));235            stx::erase(sel, this);236            if (sel.size()) {237                if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl) || ImGui::IsKeyDown(ImGuiKey_RightCtrl)) {238                    for (auto s : sel)239                        if (!stx::count(ctx.selected, s))240                            ctx.selected.push_back(s);241                }242                else243                    ctx.selected = sel;244            }245            ctx.mode = UIContext::NormalSelection; //todo246        }247    }248    if (allowed && ctx.mode == UIContext::PickPoint &&249        !ctx.snapParent &&250        ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows))251    {252        ctx.snapParent = this;253        ctx.snapIndex = children.size();254    }255 256    if ((ctx.mode == UIContext::SnapInsert || ctx.mode == UIContext::SnapMove) &&257        !ctx.snapParent && ImGui::IsWindowHovered())258    {259        DrawSnap(ctx);260    }261    if (ctx.snapParent && ctx.snapIndex == -1)262    {263        ctx.snapParent = nullptr;264    }265    if (ctx.mode == UIContext::PickPoint && ctx.snapParent == this)266    {267        DrawInteriorRect(ctx);268    }269    if (ctx.mode == UIContext::RectSelection)270    {271        ImDrawList* dl = ImGui::GetForegroundDrawList();272        ImVec2 a{ std::min(ctx.selStart.x, ctx.selEnd.x), std::min(ctx.selStart.y, ctx.selEnd.y) };273        ImVec2 b{ std::max(ctx.selStart.x, ctx.selEnd.x), std::max(ctx.selStart.y, ctx.selEnd.y) };274        dl->PushClipRect(ctx.designAreaMin, ctx.designAreaMax);275        dl->AddRectFilled(a, b, ctx.colors[UIContext::Hovered]);276        dl->PopClipRect();277    }278 279    ImGui::End();280 281    if (!style_bg.empty())282        ImGui::PopStyleColor();283    if (!style_menuBg.empty())284        ImGui::PopStyleColor();285    if (style_scrollbarSize.has_value())286        ImGui::PopStyleVar();287    if (style_rounding.has_value())288        ImGui::PopStyleVar();289    if (style_borderSize.has_value())290        ImGui::PopStyleVar();291    if (style_spacing.has_value())292        ImGui::PopStyleVar();293    if (style_innerSpacing.has_value())294        ImGui::PopStyleVar();295    if (style_padding.has_value())296        ImGui::PopStyleVar();297    if (style_font.has_value())298        ImGui::PopFont();299}300 301void TopWindow::Export(std::ostream& os, UIContext& ctx)302{303    ctx.varCounter = 1;304    ctx.parents = { this };305    ctx.kind = kind;306    ctx.errors.clear();307    ctx.unit = ctx.unit == "px" ? "" : ctx.unit;308 309    ctx.codeGen->RemovePrefixedVars(std::string(ctx.codeGen->HBOX_NAME));310    ctx.codeGen->RemovePrefixedVars(std::string(ctx.codeGen->VBOX_NAME));311    RenameFieldVars(CUR_ITEM_SYMBOL, std::string(ctx.codeGen->CUR_ITEM_VAR_NAME));312 313    //todo: put before ///@ params314    if (userCodeBefore != "")315        os << userCodeBefore << "\n";316 317    //provide stable ID when title changes318    bindable<std::string> titleId = title;319    if (titleId.access()->find("##") == std::string::npos)320        *titleId.access() += "###" + ctx.codeGen->GetName();321    std::string tit = titleId.to_arg();322    bool hasMB = children.size() && dynamic_cast<MenuBar*>(children[0].get());323    bool autoSize = flags & ImGuiWindowFlags_AlwaysAutoResize;324 325    os << ctx.ind << "/// @begin TopWindow\n";326    os << ctx.ind << "auto* ioUserData = (ImRad::IOUserData*)ImGui::GetIO().UserData;\n";327 328    if (ctx.unit == "dp")329    {330        os << ctx.ind << "const float dp = ioUserData->dpiScale;\n";331    }332 333    if (kind == Popup || kind == ModalPopup)334    {335        os << ctx.ind << "ID = ImGui::GetID(\"###" << ctx.codeGen->GetName() << "\");\n";336    }337    else if (kind == Activity)338    {339        if (initialActivity)340        {341            os << ctx.ind << "if (ioUserData->activeActivity == \"\")\n";342            ctx.ind_up();343            os << ctx.ind << "Open();\n";344            ctx.ind_down();345        }346        os << ctx.ind << "if (ioUserData->activeActivity != \"" << ctx.codeGen->GetName() << "\")\n";347        ctx.ind_up();348        os << ctx.ind << "return;\n";349        ctx.ind_down();350    }351 352    if (!style_font.empty())353    {354        os << ctx.ind << "ImGui::PushFont(" << style_font.to_arg() << ");\n";355    }356    if (!style_bg.empty())357    {358        os << ctx.ind << "ImGui::PushStyleColor(" <<359            ((kind == Popup || kind == ModalPopup) ? "ImGuiCol_PopupBg" : "ImGuiCol_WindowBg") <<360            ", " << style_bg.to_arg() << ");\n";361    }362    if (!style_menuBg.empty())363    {364        os << ctx.ind << "ImGui::PushStyleColor(ImGuiCol_MenuBarBg, " << style_menuBg.to_arg() << ");\n";365    }366    if (style_padding.has_value())367    {368        os << ctx.ind << "ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, "369            << style_padding.to_arg(ctx.unit) << ");\n";370    }371    if (style_spacing.has_value())372    {373        os << ctx.ind << "ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, "374            << style_spacing.to_arg(ctx.unit) << ");\n";375    }376    if (style_innerSpacing.has_value())377    {378        os << ctx.ind << "ImGui::PushStyleVar(ImGuiStyleVar_ItemInnerSpacing, "379            << style_innerSpacing.to_arg(ctx.unit) << ");\n";380    }381    if (style_rounding.has_value())382    {383        os << ctx.ind << "ImGui::PushStyleVar(";384        //ModalPopup uses WindowRounding385        os << (kind == Popup ? "ImGuiStyleVar_PopupRounding" : "ImGuiStyleVar_WindowRounding");386        os << ", " << style_rounding.to_arg(ctx.unit) << ");\n";387    }388    if (style_borderSize.has_value() && kind != Activity && kind != MainWindow)389    {390        os << ctx.ind << "ImGui::PushStyleVar(";391        os << ((kind == Popup || kind == ModalPopup) ? "ImGuiStyleVar_PopupBorderSize" : "ImGuiStyleVar_WindowBorderSize");392        os << ", " << style_borderSize.to_arg(ctx.unit) << ");\n";393    }394    if (style_scrollbarSize.has_value())395    {396        os << ctx.ind << "ImGui::PushStyleVar(ImGuiStyleVar_ScrollbarSize, "397            << style_scrollbarSize.to_arg(ctx.unit) << ");\n";398    }399 400    if (kind == MainWindow)401    {402        os << ctx.ind << "ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0);\n";403        os << ctx.ind << "glfwSetWindowTitle(window, " << title.to_arg() << ");\n";404        os << ctx.ind << "ImGui::SetNextWindowPos({ 0, 0 });\n";405        if (!autoSize)406        {407            os << ctx.ind << "int tmpWidth, tmpHeight;\n";408            os << ctx.ind << "glfwGetWindowSize(window, &tmpWidth, &tmpHeight);\n";409            os << ctx.ind << "ImGui::SetNextWindowSize({ (float)tmpWidth, (float)tmpHeight });\n";410        }411 412        auto fl = flags;413        fl |= ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoSavedSettings;414        os << ctx.ind << "bool tmpOpen;\n";415        os << ctx.ind << "if (ImGui::Begin(\"###" << ctx.codeGen->GetName() << "\", &tmpOpen, " << fl.to_arg() << "))\n";416        os << ctx.ind << "{\n";417        ctx.ind_up();418 419        if (autoSize)420        {421            os << ctx.ind << "if (ImGui::IsWindowAppearing())\n" << ctx.ind << "{\n";422            ctx.ind_up();423            //to prevent edge at right/bottom border. Not sure why ImGui needs it424            os << ctx.ind << "ImGui::GetStyle().DisplaySafeAreaPadding = { 0, 0 };\n";425            os << ctx.ind << "glfwSetWindowAttrib(window, GLFW_RESIZABLE, false);\n";426            os << ctx.ind << "glfwSetWindowAttrib(window, GLFW_DECORATED, "427                << std::boolalpha << !(flags & ImGuiWindowFlags_NoTitleBar) << ");\n";428            ctx.ind_down();429            os << ctx.ind << "}\n";430            //glfwSetWindowSize only when SizeFull is determined431            //alternatively calculate it from ContentSize + padding432            os << ctx.ind << "else\n" << ctx.ind << "{\n";433            ctx.ind_up();434            os << ctx.ind << "ImVec2 size = ImGui::GetCurrentWindow()->SizeFull;\n";435            os << ctx.ind << "glfwSetWindowSize(window, (int)size.x, (int)size.y);\n";436            ctx.ind_down();437            os << ctx.ind << "}\n";438        }439        else440        {441            os << ctx.ind << "if (ImGui::IsWindowAppearing())\n" << ctx.ind << "{\n";442            ctx.ind_up();443            if (placement == Maximize)444                os << ctx.ind << "glfwMaximizeWindow(window);\n";445            else446                os << ctx.ind << "glfwSetWindowSize(window, " << size_x.to_arg(ctx.unit)447                << ", " << size_y.to_arg(ctx.unit) << ");\n";448 449            os << ctx.ind << "glfwSetWindowSizeLimits(window, " <<450                minSize_x.to_arg(ctx.unit) << ", " << minSize_y.to_arg(ctx.unit) <<451                ", GLFW_DONT_CARE, GLFW_DONT_CARE);\n";452 453            os << ctx.ind << "glfwSetWindowAttrib(window, GLFW_RESIZABLE, "454                << std::boolalpha << !(flags & ImGuiWindowFlags_NoResize) << ");\n";455            os << ctx.ind << "glfwSetWindowAttrib(window, GLFW_DECORATED, "456                << std::boolalpha << !(flags & ImGuiWindowFlags_NoTitleBar) << ");\n";457            ctx.ind_down();458            os << ctx.ind << "}\n";459        }460    }461    else if (kind == Activity)462    {463        os << ctx.ind << "ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0);\n";464        os << ctx.ind << "ImGui::SetNextWindowPos(ioUserData->WorkRect().Min);\n";465        os << ctx.ind << "ImGui::SetNextWindowSize(ioUserData->WorkRect().GetSize());";466        //signal designed size467        os << " //{ " << size_x.to_arg(ctx.unit) << ", " << size_y.to_arg(ctx.unit) << " }\n";468        auto fl = flags;469        fl |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings;470        os << ctx.ind << "bool tmpOpen;\n";471        os << ctx.ind << "if (ImGui::Begin(\"###" << ctx.codeGen->GetName() << "\", &tmpOpen, " << fl.to_arg() << "))\n";472        os << ctx.ind << "{\n";473        ctx.ind_up();474 475        if (!onBackButton.empty()) {476            os << ctx.ind << "if (ImGui::IsKeyPressed(ImGuiKey_AppBack))\n";477            ctx.ind_up();478            os << ctx.ind << onBackButton.to_arg() << "();\n";479            ctx.ind_down();480        }481    }482    else if (kind == Window)483    {484        //pos485        if (placement == Left || placement == Top)486        {487            os << ctx.ind << "ImGui::SetNextWindowPos(ioUserData->WorkRect().Min);";488            os << (placement == Left ? " //Left\n" : " //Top\n");489        }490        else if (placement == Right || placement == Bottom)491        {492            os << ctx.ind << "ImGui::SetNextWindowPos(ioUserData->WorkRect().Max, 0, { 1, 1 });";493            os << (placement == Right ? " //Right\n" : " //Bottom\n");494        }495 496        //size497        os << ctx.ind << "ImGui::SetNextWindowSize({ ";498 499        if (placement == Top || placement == Bottom)500            os << "ioUserData->WorkRect().GetWidth()";501        else if (autoSize)502            os << "0";503        else504            os << size_x.to_arg(ctx.unit);505 506        os << ", ";507 508        if (placement == Left || placement == Right)509            os << "ioUserData->WorkRect().GetHeight()";510        else if (autoSize)511            os << "0";512        else513            os << size_y.to_arg(ctx.unit);514 515        os << " }";516        if (!autoSize && placement != Left && placement != Right && placement != Top && placement != Bottom)517            os << ", ImGuiCond_FirstUseEver";518        os << ");";519        //signal designed size520        os << " //{ " << size_x.to_arg(ctx.unit) << ", " << size_y.to_arg(ctx.unit) << " }\n";521 522        if (!autoSize)523        {524            os << ctx.ind << "ImGui::SetNextWindowSizeConstraints({ " <<525                minSize_x.to_arg(ctx.unit) << ", " << minSize_y.to_arg(ctx.unit) <<526                " }, { FLT_MAX, FLT_MAX });\n";527        }528 529        if (style_titlePadding.has_value())530        {531            os << ctx.ind << "ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, " <<532                style_titlePadding.to_arg(ctx.unit) << ");\n";533        }534        os << ctx.ind << "if (isOpen && ImGui::Begin(" << tit << ", &isOpen, " << flags.to_arg() << "))\n";535        os << ctx.ind << "{\n";536        ctx.ind_up();537        if (style_titlePadding.has_value())538        {539            os << ctx.ind << "ImGui::PopStyleVar();\n";540            os << ctx.ind << "ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImGui::GetStyle().FramePadding);\n";541        }542    }543    else if (kind == Popup || kind == ModalPopup)544    {545        if (placement == Left || placement == Top)546        {547            os << ctx.ind << "ImGui::SetNextWindowPos(";548            if (animate)549                os << "{ ioUserData->WorkRect().Min.x + animPos.x, ioUserData->WorkRect().Min.y + animPos.y }";550            else551                os << "ioUserData->WorkRect().Min";552            os << "); " << (placement == Left ? " //Left\n" : " //Top\n");553        }554        else if (placement == Right || placement == Bottom)555        {556            os << ctx.ind << "ImGui::SetNextWindowPos(";557            if (animate)558                os << "{ ioUserData->WorkRect().Max.x - animPos.x, ioUserData->WorkRect().Max.y - animPos.y }, 0, { 1, 1 }";559            else560                os << "ioUserData->WorkRect().Max, 0, { 1, 1 }";561            os << "); " << (placement == Right ? " //Right\n" : " //Bottom\n");562        }563        else if (placement == Center)564        {565            os << ctx.ind << "ImGui::SetNextWindowPos(";566            if (animate)567                os << "{ ioUserData->WorkRect().GetCenter().x, ioUserData->WorkRect().GetCenter().y + animPos.y }, 0, { 0.5f, 0.5f }";568            else569                os << "ioUserData->WorkRect().GetCenter(), 0, { 0.5f, 0.5f }";570            os << "); //Center\n";571        }572 573        //size574        os << ctx.ind << "ImGui::SetNextWindowSize({ ";575 576        if (placement == Top || placement == Bottom)577            os << "ioUserData->WorkRect().GetWidth()";578        else if (autoSize)579            os << "0";580        else581            os << size_x.to_arg(ctx.unit);582 583        os << ", ";584 585        if (placement == Left || placement == Right)586            os << "ioUserData->WorkRect().GetHeight()";587        else if (autoSize)588            os << "0";589        else590            os << size_y.to_arg(ctx.unit);591 592        os << " }";593        if (!autoSize && placement != Left && placement != Right && placement != Top && placement != Bottom)594            os << ", ImGuiCond_FirstUseEver";595        os << ");";596        //signal designed size597        os << " //{ " << size_x.to_arg(ctx.unit) << ", " << size_y.to_arg(ctx.unit) << " }\n";598 599        if (!autoSize)600        {601            os << ctx.ind << "ImGui::SetNextWindowSizeConstraints({ " <<602                minSize_x.to_arg(ctx.unit) << ", " << minSize_y.to_arg(ctx.unit) <<603                " }, { FLT_MAX, FLT_MAX });\n";604        }605 606        //begin607        if (kind == ModalPopup)608        {609            if (style_titlePadding.has_value())610            {611                os << ctx.ind << "ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, " <<612                    style_titlePadding.to_arg(ctx.unit) << ");\n";613            }614            os << ctx.ind << "bool tmpOpen = true;\n";615            os << ctx.ind << "if (ImGui::BeginPopupModal(" << tit << ", &tmpOpen, " << flags.to_arg() << "))\n";616            os << ctx.ind << "{\n";617            ctx.ind_up();618            if (style_titlePadding.has_value())619            {620                os << ctx.ind << "ImGui::PopStyleVar();\n";621                os << ctx.ind << "ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImGui::GetStyle().FramePadding);\n";622            }623        }624        else625        {626            os << ctx.ind << "if (ImGui::BeginPopup(" << tit << ", " << flags.to_arg() << "))\n";627            os << ctx.ind << "{\n";628            ctx.ind_up();629        }630 631        //animation632        if (animate)633        {634            os << ctx.ind << "animator.Tick();\n";635            if (placement == Left || placement == Right || placement == Top || placement == Bottom)636            {637                os << ctx.ind << "if (!ImRad::MoveWhenDragging(";638                if (placement == Left)639                    os << "ImGuiDir_Left";640                else if (placement == Right)641                    os << "ImGuiDir_Right";642                else if (placement == Top)643                    os << "ImGuiDir_Up";644                else if (placement == Bottom)645                    os << "ImGuiDir_Down";646                os << ", animPos, ioUserData->dimBgRatio))\n";647                ctx.ind_up();648                os << ctx.ind << "ClosePopup();\n";649                ctx.ind_down();650            }651        }652 653        //back button654        if (!onBackButton.empty())655        {656            os << ctx.ind << "if (ImGui::IsKeyPressed(ImGuiKey_AppBack))\n";657            ctx.ind_up();658            os << ctx.ind << onBackButton.to_arg() << "();\n";659            ctx.ind_down();660        }661 662        //rendering663        if (kind == ModalPopup)664        {665            os << ctx.ind << "if (ioUserData->activeActivity != \"\")\n";666            ctx.ind_up();667            os << ctx.ind << "ImRad::RenderDimmedBackground(ioUserData->WorkRect(), ioUserData->dimBgRatio);\n";668            ctx.ind_down();669        }670        if (style_rounding &&671            (placement == Left || placement == Right || placement == Top || placement == Bottom))672        {673            os << ctx.ind << "ImRad::RenderFilledWindowCorners(ImDrawFlags_RoundCorners";674            if (placement == Left)675                os << "Left";676            else if (placement == Right)677                os << "Right";678            else if (placement == Top)679                os << "Top";680            else if (placement == Bottom)681                os << "Bottom";682            os << ");\n";683        }684 685        //CloseCurrentPopup686        os << ctx.ind << "if (modalResult != ImRad::None";687        if (animate)688            os << " && animator.IsDone()";689        os << ")\n";690        os << ctx.ind << "{\n";691        ctx.ind_up();692        os << ctx.ind << "ImGui::CloseCurrentPopup();\n";693        //callback is called after CloseCurrentPopup so it is able to open another dialog694        //without calling Draw from it695        if (kind == ModalPopup)696        {697            os << ctx.ind << "if (modalResult != ImRad::Cancel)\n";698            ctx.ind_up();699            os << ctx.ind << "callback(modalResult);\n";700            ctx.ind_down();701        }702        ctx.ind_down();703        os << ctx.ind << "}\n";704 705        if (closeOnEscape)706        {707            os << ctx.ind << "if (ImGui::Shortcut(ImGuiKey_Escape))\n";708            ctx.ind_up();709            os << ctx.ind << "ClosePopup();\n";710            ctx.ind_down();711        }712    }713 714    if (!onWindowAppearing.empty())715    {716        os << ctx.ind << "if (ImGui::IsWindowAppearing())\n";717        ctx.ind_up();718        os << ctx.ind << onWindowAppearing.to_arg() << "();\n";719        ctx.ind_down();720    }721 722    os << ctx.ind << "/// @separator\n\n";723 724    //at next import comment becomes userCode725    /*if (userCodeMid != "")726        os << userCodeMid << "\n";*/727    if (children.empty() || children[0]->userCodeBefore.empty())728        os << ctx.ind << "// TODO: Add Draw calls of dependent popup windows here\n\n";729 730    for (const auto& ch : children)731        ch->Export(os, ctx);732 733    os << ctx.ind << "/// @separator\n";734 735    if (kind == Popup || kind == ModalPopup)736    {737        os << ctx.ind << "ImGui::EndPopup();\n";738        ctx.ind_down();739        os << ctx.ind << "}\n";740    }741    else742    {743        os << ctx.ind << "ImGui::End();\n";744        ctx.ind_down();745        os << ctx.ind << "}\n";746    }747 748    if (style_titlePadding.has_value() && (kind == Window || kind == ModalPopup))749        os << ctx.ind << "ImGui::PopStyleVar();\n";750    if (style_scrollbarSize.has_value())751        os << ctx.ind << "ImGui::PopStyleVar();\n";752    if (style_borderSize.has_value() || kind == Activity || kind == MainWindow)753        os << ctx.ind << "ImGui::PopStyleVar();\n";754    if (style_rounding.has_value())755        os << ctx.ind << "ImGui::PopStyleVar();\n";756    if (style_spacing.has_value())757        os << ctx.ind << "ImGui::PopStyleVar();\n";758    if (style_innerSpacing.has_value())759        os << ctx.ind << "ImGui::PopStyleVar();\n";760    if (style_padding.has_value())761        os << ctx.ind << "ImGui::PopStyleVar();\n";762    if (!style_bg.empty())763        os << ctx.ind << "ImGui::PopStyleColor();\n";764    if (!style_menuBg.empty())765        os << ctx.ind << "ImGui::PopStyleColor();\n";766    if (!style_font.empty())767        os << ctx.ind << "ImGui::PopFont();\n";768 769    os << ctx.ind << "/// @end TopWindow\n";770 771    if (userCodeAfter != "")772        os << userCodeAfter << "\n";773 774    RenameFieldVars(std::string(ctx.codeGen->CUR_ITEM_VAR_NAME), CUR_ITEM_SYMBOL);775}776 777void TopWindow::Import(cpp::stmt_iterator& sit, UIContext& ctx)778{779    ctx.errors.clear();780    bool tmpCreateDeps = ctx.createVars;781    ctx.createVars = false;782    ctx.importState = 2; //1 - inside TopWindow block, 2 - before TopWindow or outside @begin/end/separator, 3 - after @end TopWindow783    ctx.userCode = "";784    ctx.root = this;785    ctx.parents = { this };786    ctx.kind = kind = Window;787    bool hasGlfw = false;788    bool windowAppearingBlock = false;789 790    while (sit != cpp::stmt_iterator())791    {792        bool parseCommentSize = false;793        bool parseCommentPos = false;794 795        if (sit->kind == cpp::Comment && !sit->line.compare(0, 20, "/// @begin TopWindow"))796        {797            ctx.importState = 1;798            sit.enable_parsing(true);799            userCodeBefore = ctx.userCode;800            ctx.userCode = "";801        }802        else if (sit->kind == cpp::Comment && !sit->line.compare(0, 11, "/// @begin "))803        {804            ctx.importState = 1;805            sit.enable_parsing(true);806            std::string type = sit->line.substr(11);807            if (auto node = Widget::Create(type, ctx))808            {809                children.push_back(std::move(node));810                children.back()->Import(++sit, ctx); //after insertion811                ctx.importState = 2;812                ctx.userCode = "";813                sit.enable_parsing(false);814            }815        }816        else if (sit->kind == cpp::Comment && !sit->line.compare(0, 18, "/// @end TopWindow"))817        {818            ctx.importState = 3;819            ctx.userCode = "";820            sit.enable_parsing(false);821        }822        else if (sit->kind == cpp::Comment && !sit->line.compare(0, 14, "/// @separator"))823        {824            if (ctx.importState == 1) { //separator at begin825                ctx.importState = 2;826                ctx.userCode = "";827                sit.enable_parsing(false);828            }829            else { //separator at end830                if (!children.empty())831                    children.back()->userCodeAfter = ctx.userCode;832                else833                    userCodeMid = ctx.userCode;834                ctx.userCode = "";835                ctx.importState = 1;836                sit.enable_parsing(true);837            }838        }839        else if ((ctx.importState == 2 || ctx.importState == 3) &&840                (sit->kind != cpp::Comment || sit->line.compare(0, 5, "/// @")))841        {842            if (ctx.importState == 3 && sit->line.size() && sit->line.back() == '}') { //reached end of Draw843                sit.base().stream().putback('}');844                sit.enable_parsing(true);845                break;846            }847            if (ctx.userCode != "")848                ctx.userCode += "\n";849            ctx.userCode += sit->line;850        }851        else if (sit->kind == cpp::IfStmt && sit->cond == "ioUserData->activeActivity==\"\"")852        {853            initialActivity = true;854        }855        else if (sit->kind == cpp::IfCallBlock && sit->callee == "ImGui::IsWindowAppearing")856        {857            windowAppearingBlock = true;858        }859        else if (sit->kind == cpp::Other && sit->line == "else" &&860            sit->level == ctx.importLevel + 1)861        {862            windowAppearingBlock = false;863        }864        else if (sit->kind == cpp::CallExpr && sit->callee == "ImGui::PushFont")865        {866            if (sit->params.size())867                style_font.set_from_arg(sit->params[0]);868        }869        else if (sit->kind == cpp::CallExpr && sit->callee == "ImGui::PushStyleColor")870        {871            if (sit->params[0] == "ImGuiCol_WindowBg" || sit->params[0] == "ImGuiCol_PopupBg")872                style_bg.set_from_arg(sit->params[1]);873            else if (sit->params[0] == "ImGuiCol_MenuBarBg")874                style_menuBg.set_from_arg(sit->params[1]);875        }876        else if (sit->kind == cpp::CallExpr && sit->callee == "ImGui::PushStyleVar" && sit->params.size() == 2)877        {878            if (sit->params[0] == "ImGuiStyleVar_WindowPadding")879                style_padding.set_from_arg(sit->params[1]);880            else if (sit->params[0] == "ImGuiStyleVar_ItemSpacing")881                style_spacing.set_from_arg(sit->params[1]);882            else if (sit->params[0] == "ImGuiStyleVar_ItemInnerSpacing")883                style_innerSpacing.set_from_arg(sit->params[1]);884            else if (sit->params[0] == "ImGuiStyleVar_WindowRounding" || sit->params[0] == "ImGuiStyleVar_PopupRounding")885                style_rounding.set_from_arg(sit->params[1]);886            else if (sit->params[0] == "ImGuiStyleVar_WindowBorderSize" || sit->params[0] == "ImGuiStyleVar_PopupBorderSize")887                style_borderSize.set_from_arg(sit->params[1]);888            else if (sit->params[0] == "ImGuiStyleVar_ScrollbarSize")889                style_scrollbarSize.set_from_arg(sit->params[1]);890            else if (sit->params[0] == "ImGuiStyleVar_FramePadding" && style_titlePadding.empty())891                style_titlePadding.set_from_arg(sit->params[1]);892        }893        else if (sit->kind == cpp::CallExpr && sit->callee == "ImGui::SetNextWindowPos")894        {895            parseCommentPos = true;896            animate = sit->line.find("animPos") != std::string::npos;897        }898        else if (sit->kind == cpp::CallExpr && sit->callee == "ImGui::SetNextWindowSize")899        {900            parseCommentSize = true;901            if (sit->params.size())902            {903                auto size = cpp::parse_size(sit->params[0]);904                size_x.set_from_arg(size.first);905                size_y.set_from_arg(size.second);906            }907        }908        else if (sit->kind == cpp::CallExpr && sit->callee == "ImGui::SetNextWindowSizeConstraints")909        {910            if (sit->params.size())911            {912                auto size = cpp::parse_size(sit->params[0]);913                minSize_x.set_from_arg(size.first);914                minSize_y.set_from_arg(size.second);915            }916        }917        else if (sit->kind == cpp::CallExpr && sit->callee == "glfwSetWindowTitle")918        {919            hasGlfw = true;920            if (sit->params.size() >= 2)921                title.set_from_arg(sit->params[1]);922        }923        else if (sit->kind == cpp::CallExpr && sit->callee == "glfwSetWindowSize" &&924            windowAppearingBlock)925        {926            hasGlfw = true;927            if (sit->params.size() >= 3) {928                size_x.set_from_arg(sit->params[1]);929                size_y.set_from_arg(sit->params[2]);930            }931        }932        else if (sit->kind == cpp::CallExpr && sit->callee == "glfwSetWindowSizeLimits" &&933            windowAppearingBlock)934       {935            hasGlfw = true;936            if (sit->params.size() >= 3) {937                minSize_x.set_from_arg(sit->params[1]);938                minSize_y.set_from_arg(sit->params[2]);939            }940        }941        else if (sit->kind == cpp::CallExpr && sit->callee == "glfwMaximizeWindow")942        {943            hasGlfw = true;944            placement = Maximize;945        }946        else if (sit->kind == cpp::CallExpr && sit->callee == "glfwSetWindowAttrib"947            && sit->params.size() >= 3)948        {949            hasGlfw = true;950            if (sit->params[1] == "GLFW_RESIZABLE") {951                bool resizable = sit->params[2] != "false";952                if (!resizable && !(flags & ImGuiWindowFlags_AlwaysAutoResize))953                    flags |= ImGuiWindowFlags_NoResize;954            }955            else if (sit->params[1] == "GLFW_DECORATED") {956                bool decorated = sit->params[2] != "false";957                if (!decorated)958                    flags |= ImGuiWindowFlags_NoTitleBar;959            }960        }961        else if (sit->kind == cpp::IfCallThenCall && sit->cond == "ImGui::IsKeyPressed(ImGuiKey_AppBack)")962        {963            onBackButton.set_from_arg(sit->callee2);964        }965        else if (sit->kind == cpp::IfCallThenCall && sit->cond == "ImGui::Shortcut(ImGuiKey_Escape)" &&966            sit->callee2 == "ClosePopup")967        {968            closeOnEscape = true;969        }970        else if (sit->kind == cpp::IfCallThenCall && sit->callee == "ImGui::IsWindowAppearing")971        {972            if (sit->params.empty() && sit->params2.empty())973                onWindowAppearing.set_from_arg(sit->callee2);974        }975        else if ((sit->kind == cpp::IfCallBlock || sit->kind == cpp::CallExpr) &&976            sit->callee == "ImGui::BeginPopupModal")977        {978            ctx.kind = kind = ModalPopup;979            title.set_from_arg(sit->params[0]);980            size_t i = title.access()->rfind("###");981            if (i != std::string::npos)982                title.access()->resize(i);983 984            if (sit->params.size() >= 3) {985                if (!flags.set_from_arg(sit->params[2]))986                    PushError(ctx, "unrecognized flag in \"" + sit->params[2] + "\"");987            }988        }989        else if ((sit->kind == cpp::IfCallBlock || sit->kind == cpp::CallExpr) &&990            sit->callee == "ImGui::BeginPopup")991        {992            ctx.kind = kind = Popup;993            title.set_from_arg(sit->params[0]);994            size_t i = title.access()->rfind("###");995            if (i != std::string::npos)996                title.access()->resize(i);997 998            if (sit->params.size() >= 2) {999                if (!flags.set_from_arg(sit->params[1]))1000                    PushError(ctx, "unrecognized flag in \"" + sit->params[1] + "\"");1001            }1002        }1003        else if (sit->kind == cpp::IfCallBlock && sit->callee == "isOpen&&ImGui::Begin")1004        {1005            ctx.kind = kind = Window;1006            title.set_from_arg(sit->params[0]);1007            size_t i = title.access()->rfind("###");1008            if (i != std::string::npos)1009                title.access()->resize(i);1010 1011            if (sit->params.size() >= 3) {1012                if (!flags.set_from_arg(sit->params[2]))1013                    PushError(ctx, "unrecognized flag in \"" + sit->params[2] + "\"");1014            }1015        }1016        else if (sit->kind == cpp::IfCallBlock && sit->callee == "ImGui::Begin")1017        {1018            ctx.importLevel = sit->level;1019            if (sit->params.size() >= 3) {1020                if (!flags.set_from_arg(sit->params[2]))1021                    PushError(ctx, "unrecognized flag in \"" + sit->params[2] + "\"");1022            }1023 1024            if (hasGlfw) {1025                ctx.kind = kind = MainWindow;1026                //reset sizes from earlier SetNextWindowSize1027                TopWindow def(ctx);1028                size_x = def.size_x;1029                size_y = def.size_y;1030                flags &= ~(ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoSavedSettings);1031            }1032            else {1033                ctx.kind = kind = Activity;1034                placement = None;1035                flags &= ~(ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings);1036            }1037        }1038 1039        ++sit;1040 1041        if (sit->kind == cpp::Comment && parseCommentSize)1042        {1043            auto size = cpp::parse_size(sit->line.substr(2));1044            size_x.set_from_arg(size.first);1045            size_y.set_from_arg(size.second);1046        }1047        else if (sit->kind == cpp::Comment && parseCommentPos)1048        {1049            if (sit->line == "//Left")1050                placement = Left;1051            else if (sit->line == "//Right")1052                placement = Right;1053            else if (sit->line == "//Top")1054                placement = Top;1055            else if (sit->line == "//Bottom")1056                placement = Bottom;1057            else if (sit->line == "//Center")1058                placement = Center;1059            else if (sit->line == "//Maximize")1060                placement = Maximize;1061        }1062    }1063 1064    userCodeAfter = ctx.userCode;1065    ctx.createVars = tmpCreateDeps;1066    RenameFieldVars(std::string(ctx.codeGen->CUR_ITEM_VAR_NAME), CUR_ITEM_SYMBOL);1067}1068 1069void TopWindow::TreeUI(UIContext& ctx)1070{1071    static const char* NAMES[]{ "MainWindow", "Window", "Popup", "ModalPopup", "Activity" };1072 1073    ctx.parents = { this };1074    std::string str = ctx.codeGen->GetName();1075    bool selected = stx::count(ctx.selected, this) || ctx.snapParent == this;1076    if (selected)1077        ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyle().Colors[ImGuiCol_ButtonHovered]);1078    ImGui::SetNextItemOpen(true, ImGuiCond_Always);1079    if (ImGui::TreeNodeEx(str.c_str(), ImGuiTreeNodeFlags_SpanAllColumns))1080    {1081        if (selected)1082            ImGui::PopStyleColor();1083        bool activated = ImGui::IsItemClicked(); //todo || ImGui::IsItemActivated();1084        ImGui::SameLine(0, 0);1085        ImGui::TextDisabled(" : %s", NAMES[kind]);1086        if (activated)1087        {1088            if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl) || ImGui::IsKeyDown(ImGuiKey_RightCtrl))1089                ; // don't participate in group selection toggle(ctx.selected, this);1090            else1091                ctx.selected = { this };1092        }1093        for (const auto& ch : children)1094            ch->TreeUI(ctx);1095 1096        ImGui::TreePop();1097    }1098    else {1099        if (selected)1100            ImGui::PopStyleColor();1101        ImGui::SameLine(0, 0);1102        ImGui::TextDisabled(" : %s", NAMES[kind]);1103    }1104}1105 1106std::vector<UINode::Prop>1107TopWindow::Properties()1108{1109    return {1110        { "appearance.bg", &style_bg },1111        { "appearance.menuBg", &style_menuBg },1112        { "appearance.padding", &style_padding },1113        { "appearance.titlePadding", &style_titlePadding },1114        { "appearance.rounding", &style_rounding },1115        { "appearance.borderSize", &style_borderSize },1116        { "appearance.scrollbarSize", &style_scrollbarSize },1117        { "appearance.spacing", &style_spacing },1118        { "appearance.innerSpacing", &style_innerSpacing },1119        { "appearance.font", &style_font },1120        { "behavior.flags", nullptr },1121        { "behavior.kind", nullptr },1122        { "behavior.title", &title, true },1123        { "behavior.closeOnEscape", &closeOnEscape },1124        { "behavior.initialActivity", &initialActivity },1125        { "behavior.animate", &animate },1126        { "layout.size.size", nullptr },1127        { "layout.size.size_x", &size_x },1128        { "layout.size.size_y", &size_y },1129        { "layout.minSize.size", nullptr },1130        { "layout.minSize.size_x", &minSize_x },1131        { "layout.minSize.size_y", &minSize_y },1132        { "layout.placement", &placement },1133    };1134}1135 1136bool TopWindow::PropertyUI(int i, UIContext& ctx)1137{1138    bool changed = false;1139    int fl = 0;1140    switch (i)1141    {1142    case 0:1143    {1144        ImGui::Text("bg");1145        ImGui::TableNextColumn();1146        ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());1147        int clr = (kind == Popup || kind == ModalPopup) ? ImGuiCol_PopupBg : ImGuiCol_WindowBg;1148        changed = InputBindable(&style_bg, clr, ctx);1149        ImGui::SameLine(0, 0);1150        changed |= BindingButton("bg", &style_bg, ctx);1151        break;1152    }1153    case 1:1154        ImGui::Text("menuBarBg");1155        ImGui::TableNextColumn();1156        ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());1157        changed = InputBindable(&style_menuBg, ImGuiCol_MenuBarBg, ctx);1158        ImGui::SameLine(0, 0);1159        changed |= BindingButton("menuBarBg", &style_menuBg, ctx);1160        break;1161    case 2:1162    {1163        ImGui::Text("padding");1164        ImGui::TableNextColumn();1165        ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());1166        changed = InputDirectVal(&style_padding, ctx);1167        break;1168    }1169    case 3:1170    {1171        ImGui::Text("titlePadding");1172        ImGui::TableNextColumn();1173        ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());1174        changed = InputDirectVal(&style_titlePadding, ctx);1175        break;1176    }1177    case 4:1178    {1179        ImGui::Text("rounding");1180        ImGui::TableNextColumn();1181        ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());1182        changed = InputDirectVal(&style_rounding, ctx);1183        break;1184    }1185    case 5:1186    {1187        ImGui::Text("borderSize");1188        ImGui::TableNextColumn();1189        ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());1190        changed = InputDirectVal(&style_borderSize, ctx);1191        break;1192    }1193    case 6:1194    {1195        ImGui::Text("scrollbarSize");1196        ImGui::TableNextColumn();1197        ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());1198        changed = InputDirectVal(&style_scrollbarSize, ctx);1199        break;1200    }

Showing the first 1,200 of 1416 lines. Download the file for the rest.