dlxjj/imradv3
0263
1// Generated with ImRAD 0.92// visit https://github.com/tpecholt/imrad3 4#include "ui_table_cols.h"5#include "ui_binding.h"6 7TableCols tableCols;8 9 10void TableCols::OpenPopup(std::function<void(ImRad::ModalResult)> clb)11{12 callback = clb;13 modalResult = ImRad::None;14 auto *ioUserData = (ImRad::IOUserData *)ImGui::GetIO().UserData;15 ioUserData->dimBgRatio = 1.f;16 ImGui::OpenPopup(ID);17 Init();18}19 20void TableCols::ClosePopup(ImRad::ModalResult mr)21{22 modalResult = mr;23 auto *ioUserData = (ImRad::IOUserData *)ImGui::GetIO().UserData;24 ioUserData->dimBgRatio = 0.f;25}26 27void TableCols::Init()28{29 sel = columns.size() ? 0 : -1;30 CheckErrors();31}32 33void TableCols::Draw()34{35 /// @style imrad36 /// @unit px37 /// @begin TopWindow38 auto* ioUserData = (ImRad::IOUserData*)ImGui::GetIO().UserData;39 ID = ImGui::GetID("###TableCols");40 ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, { 8, 5 });41 ImGui::SetNextWindowSize({ 550, 480 }, ImGuiCond_FirstUseEver); //{ 550, 480 }42 ImGui::SetNextWindowSizeConstraints({ 0, 0 }, { FLT_MAX, FLT_MAX });43 bool tmpOpen = true;44 if (ImGui::BeginPopupModal("Table Columns###TableCols", &tmpOpen, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoNavInputs))45 {46 if (ioUserData->activeActivity != "")47 ImRad::RenderDimmedBackground(ioUserData->WorkRect(), ioUserData->dimBgRatio);48 if (modalResult != ImRad::None)49 {50 ImGui::CloseCurrentPopup();51 if (modalResult != ImRad::Cancel)52 callback(modalResult);53 }54 /// @separator55 56 // TODO: Add Draw calls of dependent popup windows here57 bindingDlg.Draw();58 59 /// @begin Selectable60 vb1.BeginLayout();61 ImRad::Spacing(1);62 ImGui::BeginDisabled(true);63 ImGui::PushStyleVar(ImGuiStyleVar_SelectableTextAlign, { 0, 1.f });64 ImRad::Selectable("Columns:", false, ImGuiSelectableFlags_NoAutoClosePopups, { 0, 0 });65 ImGui::PopStyleVar();66 vb1.AddSize(1, ImRad::VBox::ItemSize);67 ImGui::EndDisabled();68 /// @end Selectable69 70 /// @begin Splitter71 ImGui::BeginChild("splitter1", { -1, vb1.GetSize() });72 {73 ImGui::PushStyleColor(ImGuiCol_Separator, 0x00000000);74 ImGui::PushStyleColor(ImGuiCol_SeparatorHovered, 0x00000000);75 ImRad::Splitter(true, 8, &sash, 10, 10);76 ImGui::PopStyleColor();77 ImGui::PopStyleColor();78 /// @separator79 80 /// @begin Table81 ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, { 7, 5 });82 ImGui::PushStyleColor(ImGuiCol_ChildBg, 0xffffffff);83 if (ImGui::BeginTable("table2", 1, ImGuiTableFlags_BordersOuterH | ImGuiTableFlags_BordersOuterV | ImGuiTableFlags_ScrollY, { sash, -1 }))84 {85 ImGui::TableSetupColumn("A", 0, 0);86 ImGui::TableSetupScrollFreeze(0, 0);87 88 for (int i = 0; i < columns.size(); ++i)89 {90 ImGui::PushID(i);91 ImGui::TableNextRow(0, 0);92 ImGui::TableSetColumnIndex(0);93 /// @separator94 95 /// @begin Selectable96 ImGui::PushStyleVar(ImGuiStyleVar_SelectableTextAlign, { 0, 0 });97 if (ImRad::Selectable(ImRad::Format("{}", columns[i].label.c_str()).c_str(), i==sel, ImGuiSelectableFlags_NoAutoClosePopups | ImGuiSelectableFlags_SpanAllColumns, { 0, 0 }))98 {99 Selectable_Change();100 }101 ImGui::PopStyleVar();102 /// @end Selectable103 104 /// @begin Text105 ImGui::SameLine(0, 1 * ImGui::GetStyle().ItemSpacing.x);106 ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled));107 ImGui::TextUnformatted(ImRad::Format("{}", columns[i].SizingPolicyString()).c_str());108 ImGui::PopStyleColor();109 /// @end Text110 111 /// @separator112 ImGui::PopID();113 }114 ImGui::EndTable();115 }116 ImGui::PopStyleColor();117 ImGui::PopStyleVar();118 /// @end Table119 120 /// @begin CustomWidget121 ImGui::SameLine(0, 1 * ImGui::GetStyle().ItemSpacing.x);122 Properties_Draw({ -1, -1 });123 /// @end CustomWidget124 125 /// @separator126 ImGui::EndChild();127 }128 vb1.AddSize(1, ImRad::VBox::Stretch(1));129 /// @end Splitter130 131 /// @begin Button132 if (ImGui::Button("\xef\x83\xbe", { 37, 0 }))133 {134 AddButton_Change();135 }136 vb1.AddSize(1, ImRad::VBox::ItemSize);137 if (ImGui::IsItemHovered(ImGuiHoveredFlags_ForTooltip))138 ImGui::SetTooltip("Add new column");139 /// @end Button140 141 /// @begin Button142 ImGui::SameLine(0, 1 * ImGui::GetStyle().ItemSpacing.x);143 ImGui::BeginDisabled(sel<0);144 if (ImGui::Button("\xef\x8b\xad", { 37, 0 }))145 {146 RemoveButton_Change();147 }148 vb1.UpdateSize(0, ImRad::VBox::ItemSize);149 ImGui::EndDisabled();150 if (ImGui::IsItemHovered(ImGuiHoveredFlags_ForTooltip))151 ImGui::SetTooltip("Remove column");152 /// @end Button153 154 /// @begin Button155 ImGui::SameLine(0, 2 * ImGui::GetStyle().ItemSpacing.x);156 ImGui::BeginDisabled(sel<=0);157 if (ImGui::ArrowButton("##button3", ImGuiDir_Up))158 {159 UpButton_Change();160 }161 vb1.UpdateSize(0, ImRad::VBox::ItemSize);162 ImGui::EndDisabled();163 if (ImGui::IsItemHovered(ImGuiHoveredFlags_ForTooltip))164 ImGui::SetTooltip("Move column up");165 /// @end Button166 167 /// @begin Button168 ImGui::SameLine(0, 1 * ImGui::GetStyle().ItemSpacing.x);169 ImGui::BeginDisabled(sel+1==columns.size());170 if (ImGui::ArrowButton("##button4", ImGuiDir_Down))171 {172 DownButton_Change();173 }174 vb1.UpdateSize(0, ImRad::VBox::ItemSize);175 ImGui::EndDisabled();176 if (ImGui::IsItemHovered(ImGuiHoveredFlags_ForTooltip))177 ImGui::SetTooltip("Move column down");178 /// @end Button179 180 /// @begin Selectable181 ImGui::SameLine(0, 1 * ImGui::GetStyle().ItemSpacing.x);182 ImGui::PushStyleColor(ImGuiCol_Text, 0xff0000ff);183 ImGui::PushStyleVar(ImGuiStyleVar_SelectableTextAlign, { 1.f, 0 });184 ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);185 ImRad::Selectable(ImRad::Format("{}##error", error).c_str(), false, ImGuiSelectableFlags_NoAutoClosePopups, { 0, 0 });186 ImGui::PopItemFlag();187 ImGui::PopStyleVar();188 vb1.UpdateSize(0, ImRad::VBox::ItemSize);189 ImGui::PopStyleColor();190 /// @end Selectable191 192 /// @begin Spacer193 hb4.BeginLayout();194 ImRad::Spacing(2);195 ImRad::Dummy({ hb4.GetSize(), 0 });196 vb1.AddSize(3, ImRad::VBox::ItemSize);197 hb4.AddSize(0, ImRad::HBox::Stretch(1));198 /// @end Spacer199 200 /// @begin Button201 ImGui::SameLine(0, 1 * ImGui::GetStyle().ItemSpacing.x);202 if (ImGui::Button("OK", { 100, 30 }))203 {204 ClosePopup(ImRad::Ok);205 }206 vb1.UpdateSize(0, 30);207 hb4.AddSize(1, 100);208 /// @end Button209 210 /// @begin Button211 ImGui::SameLine(0, 1 * ImGui::GetStyle().ItemSpacing.x);212 if (ImGui::Button("Cancel", { 100, 30 }) ||213 ImGui::Shortcut(ImGuiKey_Escape))214 {215 ClosePopup(ImRad::Cancel);216 }217 vb1.UpdateSize(0, 30);218 hb4.AddSize(1, 100);219 /// @end Button220 221 /// @separator222 ImGui::EndPopup();223 }224 ImGui::PopStyleVar();225 /// @end TopWindow226}227 228void TableCols::ResetLayout()229{230 // ImGui::GetCurrentWindow()->HiddenFramesCannotSkipItems = 2;231 vb1.Reset();232 hb4.Reset();233}234 235void TableCols::Selectable_Change()236{237 sel = ImGui::TableGetRowIndex();238}239 240void TableCols::AddButton_Change()241{242 columns.push_back(Table::ColumnData("New Column", ImGuiTableColumnFlags_None));243 sel = (int)columns.size() - 1;244}245 246void TableCols::RemoveButton_Change()247{248 if (sel >= 0)249 columns.erase(columns.begin() + sel);250 if (sel >= columns.size())251 --sel;252}253 254void TableCols::UpButton_Change()255{256 if (sel) {257 std::swap(columns[sel], columns[sel - 1]);258 --sel;259 }260}261 262void TableCols::DownButton_Change()263{264 if (sel + 1 < columns.size()) {265 std::swap(columns[sel], columns[sel + 1]);266 ++sel;267 }268}269 270void TableCols::Properties_Draw(const ImRad::CustomWidgetArgs& args)271{272 ImGui::PushStyleColor(ImGuiCol_ChildBg, 0xfffafafa);273 ImGui::PushStyleColor(ImGuiCol_TableBorderLight, 0xffe5e5e5);274 ImVec4 clr = ImGui::GetStyleColorVec4(ImGuiCol_Button);275 clr.w *= 0.5f;276 ImGui::PushStyleColor(ImGuiCol_Button, clr);277 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, { 0, 0 });278 ImVec2 framePad = ImGui::GetStyle().FramePadding;279 ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, { framePad.x * 0.5f, framePad.y * 0.5f });280 281 ImVec2 pgMin = ImGui::GetCursorScreenPos();282 static float pgHeight = 0;283 uint32_t borderClr = ImGui::ColorConvertFloat4ToU32(ImGui::GetStyleColorVec4(ImGuiCol_TableBorderLight));284 ImGuiTableFlags flags = ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersInnerH | ImGuiTableFlags_Resizable | ImGuiTableFlags_ScrollY;285 if (ImGui::BeginTable("pg", 2, flags, args.size))286 {287 ImGui::GetWindowDrawList()->AddRectFilled(288 pgMin,289 { pgMin.x + ImGui::GetStyle().IndentSpacing + 1, pgMin.y + pgHeight },290 borderClr291 );292 ImGui::TableSetupColumn("name", ImGuiTableColumnFlags_WidthStretch);293 ImGui::TableSetupColumn("value", ImGuiTableColumnFlags_WidthStretch);294 295 ImGui::TableNextRow();296 ImGui::TableSetColumnIndex(0);297 ImGui::AlignTextToFramePadding();298 ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, { 0.0f, ImGui::GetStyle().FramePadding.y });299 ImGui::PushFont(ctx->pgbFont);300 ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBg0,301 ImGui::ColorConvertFloat4ToU32(ImGui::GetStyleColorVec4(ImGuiCol_TableBorderLight)));302 ImGui::PushStyleColor(ImGuiCol_NavCursor, 0x0);303 ImGui::SetNextItemOpen(true);304 bool open = ImGui::TreeNodeEx("Behavior", ImGuiTreeNodeFlags_SpanAllColumns | ImGuiTreeNodeFlags_DefaultOpen);305 ImGui::PopStyleColor();306 ImGui::PopFont();307 ImGui::PopStyleVar();308 //ImGui::Indent();309 310 if (sel >= 0 && open)311 {312 int n = (int)columns[sel].Properties().size();313 for (int i = 0; i < n; ++i)314 {315 ImGui::TableNextRow();316 ImGui::TableSetColumnIndex(0);317 ImGui::AlignTextToFramePadding();318 if (columns[sel].PropertyUI(i, *ctx))319 CheckErrors();320 }321 }322 if (open)323 ImGui::TreePop();324 325 ImGui::EndTable();326 pgHeight = ImGui::GetItemRectSize().y;327 }328 329 ImGui::PopStyleVar(2);330 ImGui::PopStyleColor(3);331}332 333void TableCols::CheckErrors()334{335 error = "";336 int noPolicy = 0;337 for (const auto& cd : columns)338 if (!(cd.sizingPolicy & ImGuiTableColumnFlags_WidthMask_))339 ++noPolicy;340 if (noPolicy && noPolicy != columns.size())341 error = "specify sizingPolicy either for all columns or none";342}343 