Skip to content

Commit

Permalink
Add exclusive Activity.Open()
Browse files Browse the repository at this point in the history
  • Loading branch information
tope99 committed Dec 11, 2023
1 parent 59d2c54 commit f10cfbd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/cppgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ CppGen::ExportH(std::ostream& fout, std::istream& fprev, const std::string& orig
}
else if (kind == TopWindow::Activity)
{
out << INDENT << "void Open();\n\n";
out << INDENT << "void Draw();\n\n";
}
else
Expand Down Expand Up @@ -253,7 +254,8 @@ CppGen::ExportH(std::ostream& fout, std::istream& fprev, const std::string& orig
out << "\n";

//write special fields
if (kind == TopWindow::Popup || kind == TopWindow::ModalPopup)
if (kind == TopWindow::Popup || kind == TopWindow::ModalPopup ||
kind == TopWindow::Activity)
{
out << INDENT << "void Init();\n\n";
}
Expand Down Expand Up @@ -587,14 +589,27 @@ bool CppGen::WriteStub(
fout << "}";
return true;
}
else if (id == "Open" && kind == TopWindow::Activity)
{
fout << "::Open()\n{\n";
fout << INDENT << "auto* ioUserData = (ImRad::IOUserData*)ImGui::GetIO().UserData;\n";
fout << INDENT << "if (ioUserData->activeActivity != \"" << m_name << "\")\n";
fout << INDENT << "{\n";
fout << INDENT << INDENT << "ioUserData->activeActivity = \"" << m_name << "\";\n";
fout << INDENT << INDENT << "Init();\n";
fout << INDENT << "}\n";
fout << "}";
return true;
}
else if (id == "Close" && kind == TopWindow::Window)
{
fout << "::Close()\n{\n";
fout << INDENT << "isOpen = false;\n";
fout << "}";
return true;
}
else if (id == "Init" && (kind == TopWindow::ModalPopup || kind == TopWindow::Popup))
else if (id == "Init" &&
(kind == TopWindow::ModalPopup || kind == TopWindow::Popup || kind == TopWindow::Activity))
{
fout << "::Init()\n{\n";
fout << INDENT << "// TODO: Add your code here\n";
Expand Down
1 change: 1 addition & 0 deletions src/imrad.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ struct IOUserData
ImVec2 displayRectMinOffset;
ImVec2 displayRectMaxOffset;
int imeType = ImeText;
std::string activeActivity;
};

struct Animator
Expand Down
7 changes: 7 additions & 0 deletions src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,13 @@ void TopWindow::Export(std::ostream& os, UIContext& ctx)
{
os << ctx.ind << "ID = ImGui::GetID(\"###" << ctx.codeGen->GetName() << "\");\n";
}
else if (kind == Activity)
{
os << ctx.ind << "if (ioUserData->activeActivity != \"" << ctx.codeGen->GetName() << "\")\n";
ctx.ind_up();
os << ctx.ind << "return;\n";
ctx.ind_down();
}

if (style_font != "")
{
Expand Down

0 comments on commit f10cfbd

Please sign in to comment.