|
|
|
|
|
|
|
|
|
|
|
#include "ui_binding.h" |
|
|
#include "ui_new_field.h" |
|
|
#include "ui_message_box.h" |
|
|
#include "utils.h" |
|
|
|
|
|
BindingDlg bindingDlg; |
|
|
|
|
|
|
|
|
void BindingDlg::OpenPopup(std::function<void(ImRad::ModalResult)> clb) |
|
|
{ |
|
|
callback = clb; |
|
|
modalResult = ImRad::None; |
|
|
auto *ioUserData = (ImRad::IOUserData *)ImGui::GetIO().UserData; |
|
|
ioUserData->dimBgRatio = 1.f; |
|
|
ImGui::OpenPopup(ID); |
|
|
Init(); |
|
|
} |
|
|
|
|
|
void BindingDlg::ClosePopup(ImRad::ModalResult mr) |
|
|
{ |
|
|
modalResult = mr; |
|
|
auto *ioUserData = (ImRad::IOUserData *)ImGui::GetIO().UserData; |
|
|
ioUserData->dimBgRatio = 0.f; |
|
|
} |
|
|
|
|
|
void BindingDlg::Draw() |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
auto* ioUserData = (ImRad::IOUserData*)ImGui::GetIO().UserData; |
|
|
ID = ImGui::GetID("###BindingDlg"); |
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, { 10, 10 }); |
|
|
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, { 7, 7 }); |
|
|
ImGui::SetNextWindowSize({ 600, 480 }, ImGuiCond_FirstUseEver); |
|
|
ImGui::SetNextWindowSizeConstraints({ 0, 0 }, { FLT_MAX, FLT_MAX }); |
|
|
bool tmpOpen = true; |
|
|
if (ImGui::BeginPopupModal("Binding###BindingDlg", &tmpOpen, ImGuiWindowFlags_NoCollapse)) |
|
|
{ |
|
|
if (ioUserData->activeActivity != "") |
|
|
ImRad::RenderDimmedBackground(ioUserData->WorkRect(), ioUserData->dimBgRatio); |
|
|
if (modalResult != ImRad::None) |
|
|
{ |
|
|
ImGui::CloseCurrentPopup(); |
|
|
if (modalResult != ImRad::Cancel) |
|
|
callback(modalResult); |
|
|
} |
|
|
|
|
|
|
|
|
newFieldPopup.Draw(); |
|
|
messageBox.Draw(); |
|
|
|
|
|
|
|
|
hb1.BeginLayout(); |
|
|
ImGui::PushStyleColor(ImGuiCol_Text, 0xff4d4dff); |
|
|
ImGui::TextUnformatted(ImRad::Format(" {}=", name).c_str()); |
|
|
hb1.AddSize(0, ImRad::HBox::ItemSize); |
|
|
ImGui::PopStyleColor(); |
|
|
|
|
|
|
|
|
|
|
|
ImGui::SameLine(0, 1 * ImGui::GetStyle().ItemSpacing.x); |
|
|
ImRad::Dummy({ hb1.GetSize(), 20 }); |
|
|
hb1.AddSize(1, ImRad::HBox::Stretch(1)); |
|
|
|
|
|
|
|
|
|
|
|
ImGui::SameLine(0, 1 * ImGui::GetStyle().ItemSpacing.x); |
|
|
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled)); |
|
|
ImGui::TextUnformatted(ImRad::Format("{}", type + (forceReference ? " &" : "")).c_str()); |
|
|
hb1.AddSize(1, ImRad::HBox::ItemSize); |
|
|
ImGui::PopStyleColor(); |
|
|
|
|
|
|
|
|
|
|
|
ImGui::PushFont(font); |
|
|
ImGui::SetNextItemWidth(-1); |
|
|
ImGui::InputText("##expr", &expr, ImGuiInputTextFlags_CallbackCharFilter, IMRAD_INPUTTEXT_EVENT(BindingDlg, OnTextInputFilter)); |
|
|
if (ImGui::IsItemActive()) |
|
|
ioUserData->imeType = ImRad::ImeText; |
|
|
ImGui::PopFont(); |
|
|
if (ImGui::IsWindowAppearing()) |
|
|
ImGui::SetKeyboardFocusHere(-1); |
|
|
if (focusExpr) |
|
|
{ |
|
|
|
|
|
if (ImGui::IsItemFocused()) |
|
|
focusExpr = false; |
|
|
ImGui::SetKeyboardFocusHere(-1); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
hb3.BeginLayout(); |
|
|
ImRad::Spacing(1); |
|
|
ImGui::AlignTextToFramePadding(); |
|
|
ImGui::TextUnformatted("Available fields"); |
|
|
hb3.AddSize(0, ImRad::HBox::ItemSize); |
|
|
|
|
|
|
|
|
|
|
|
ImGui::SameLine(0, 1 * ImGui::GetStyle().ItemSpacing.x); |
|
|
ImRad::Dummy({ hb3.GetSize(), 20 }); |
|
|
hb3.AddSize(1, ImRad::HBox::Stretch(1)); |
|
|
|
|
|
|
|
|
|
|
|
ImGui::SameLine(0, 1 * ImGui::GetStyle().ItemSpacing.x); |
|
|
if (ImGui::Checkbox("show all", &showAll)) |
|
|
Refresh(); |
|
|
hb3.AddSize(1, ImRad::HBox::ItemSize); |
|
|
|
|
|
|
|
|
|
|
|
if (ImGui::BeginTable("table1", 2, ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersInnerH | ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_BordersOuterH | ImGuiTableFlags_BordersOuterV | ImGuiTableFlags_ScrollY, { 0, -48 })) |
|
|
{ |
|
|
ImGui::TableSetupColumn("Name", 0, 0); |
|
|
ImGui::TableSetupColumn("Type", 0, 0); |
|
|
ImGui::TableSetupScrollFreeze(0, 1); |
|
|
ImGui::TableHeadersRow(); |
|
|
|
|
|
for (int i = 0; i < vars.size(); ++i) |
|
|
{ |
|
|
ImGui::PushID(i); |
|
|
ImGui::TableNextRow(0, 0); |
|
|
ImGui::TableSetColumnIndex(0); |
|
|
|
|
|
|
|
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_SelectableTextAlign, { 0, 0 }); |
|
|
if (ImRad::Selectable(ImRad::Format("{}", vars[i].first).c_str(), false, ImGuiSelectableFlags_NoAutoClosePopups | ImGuiSelectableFlags_SpanAllColumns, { 0, 0 })) |
|
|
{ |
|
|
OnVarClicked(); |
|
|
} |
|
|
ImGui::PopStyleVar(); |
|
|
|
|
|
|
|
|
|
|
|
ImRad::TableNextColumn(1); |
|
|
ImGui::BeginDisabled(true); |
|
|
ImGui::PushStyleVar(ImGuiStyleVar_SelectableTextAlign, { 0, 0 }); |
|
|
ImRad::Selectable(ImRad::Format("{}", vars[i].second).c_str(), false, ImGuiSelectableFlags_NoAutoClosePopups, { 0, 0 }); |
|
|
ImGui::PopStyleVar(); |
|
|
ImGui::EndDisabled(); |
|
|
|
|
|
|
|
|
|
|
|
ImGui::PopID(); |
|
|
} |
|
|
ImGui::EndTable(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
hb5.BeginLayout(); |
|
|
ImRad::Spacing(1); |
|
|
if (ImGui::Button(" New Field... ", { 110, 30 })) |
|
|
{ |
|
|
OnNewField(); |
|
|
} |
|
|
hb5.AddSize(0, 110); |
|
|
|
|
|
|
|
|
|
|
|
ImGui::SameLine(0, 1 * ImGui::GetStyle().ItemSpacing.x); |
|
|
ImRad::Dummy({ hb5.GetSize(), 20 }); |
|
|
hb5.AddSize(1, ImRad::HBox::Stretch(1)); |
|
|
|
|
|
|
|
|
bool exprValid = true; |
|
|
|
|
|
|
|
|
|
|
|
if (type == "std::vector<std::string>" && |
|
|
(expr.empty() || expr[0] != '{' || expr.find('{', 1) != std::string::npos || expr.back() != '}')) |
|
|
exprValid = false; |
|
|
if (forceReference && expr.empty()) |
|
|
exprValid = false; |
|
|
|
|
|
|
|
|
ImGui::SameLine(0, 1 * ImGui::GetStyle().ItemSpacing.x); |
|
|
ImGui::BeginDisabled(!exprValid); |
|
|
if (ImGui::Button("OK", { 90, 30 })) |
|
|
{ |
|
|
OkButton_Change(); |
|
|
} |
|
|
hb5.AddSize(1, 90); |
|
|
ImGui::EndDisabled(); |
|
|
|
|
|
|
|
|
|
|
|
ImGui::SameLine(0, 1 * ImGui::GetStyle().ItemSpacing.x); |
|
|
if (ImGui::Button("Cancel", { 90, 30 }) || |
|
|
ImGui::Shortcut(ImGuiKey_Escape)) |
|
|
{ |
|
|
ClosePopup(ImRad::Cancel); |
|
|
} |
|
|
hb5.AddSize(1, 90); |
|
|
|
|
|
|
|
|
|
|
|
ImGui::EndPopup(); |
|
|
} |
|
|
ImGui::PopStyleVar(); |
|
|
ImGui::PopStyleVar(); |
|
|
|
|
|
} |
|
|
|
|
|
void BindingDlg::Refresh() |
|
|
{ |
|
|
vars = codeGen->GetVarExprs(showAll ? "" : type, true, curArray); |
|
|
} |
|
|
|
|
|
void BindingDlg::OnNewField() |
|
|
{ |
|
|
newFieldPopup.mode = NewFieldPopup::NewField; |
|
|
newFieldPopup.varType = ""; |
|
|
newFieldPopup.scope = ""; |
|
|
newFieldPopup.codeGen = codeGen; |
|
|
newFieldPopup.OpenPopup([this] { |
|
|
Refresh(); |
|
|
}); |
|
|
} |
|
|
|
|
|
void BindingDlg::OnVarClicked() |
|
|
{ |
|
|
int idx = ImGui::TableGetRowIndex() - 1; |
|
|
if (type == "std::string") |
|
|
expr += "{" + vars[idx].first + "}"; |
|
|
else if (type == "std::vector<std::string>") |
|
|
expr = "{" + vars[idx].first + "}"; |
|
|
else |
|
|
expr = vars[idx].first; |
|
|
focusExpr = true; |
|
|
} |
|
|
|
|
|
int BindingDlg::OnTextInputFilter(ImGuiInputTextCallbackData& data) |
|
|
{ |
|
|
return DefaultCharFilter(&data); |
|
|
} |
|
|
|
|
|
void BindingDlg::Init() |
|
|
{ |
|
|
showAll = type == "std::string"; |
|
|
Refresh(); |
|
|
} |
|
|
|
|
|
void BindingDlg::ResetLayout() |
|
|
{ |
|
|
|
|
|
hb1.Reset(); |
|
|
hb3.Reset(); |
|
|
hb5.Reset(); |
|
|
} |
|
|
|
|
|
void BindingDlg::OkButton_Change() |
|
|
{ |
|
|
if (forceReference && !cpp::is_lvalue(expr)) { |
|
|
messageBox.title = "Expression"; |
|
|
messageBox.message = "\"" + name + "\" field requires an l-value expression"; |
|
|
messageBox.buttons = ImRad::Ok; |
|
|
messageBox.OpenPopup(); |
|
|
return; |
|
|
} |
|
|
ClosePopup(ImRad::Ok); |
|
|
} |
|
|
|