Skip to content

Commit

Permalink
add initialActivity property
Browse files Browse the repository at this point in the history
  • Loading branch information
tpecholt committed Aug 18, 2024
1 parent ea7f065 commit fe1379d
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 27 deletions.
15 changes: 12 additions & 3 deletions src/cppgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#include <set>

const std::string GENERATED_WITH = "Generated with ";
const std::string CppGen::INDENT = " ";
const std::string CppGen::FOR_VAR = "i";
const std::string INDENT = " ";
const std::string FOR_VAR = "i";

const std::string SPEC_FUN[] = {
"Open", "Close", "OpenPopup", "ClosePopup", "ResetLayout", "Init", "Draw",
Expand Down Expand Up @@ -50,6 +50,16 @@ std::string CppGen::AltFName(const std::string& path)
return "";
}

std::string CppGen::GetIndent()
{
return INDENT;
}

std::string CppGen::DefaultForVarName()
{
return FOR_VAR;
}

bool CppGen::ExportUpdate(
const std::string& fname,
TopWindow* node,
Expand All @@ -72,7 +82,6 @@ bool CppGen::ExportUpdate(
UIContext ctx;
ctx.codeGen = this;
ctx.ind = INDENT;
ctx.forVarName = FOR_VAR;
auto uit = params.find("unit");
if (uit != params.end())
ctx.unit = uit->second;
Expand Down
18 changes: 9 additions & 9 deletions src/cppgen.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@
class CppGen
{
public:
static const std::string INDENT;
static const std::string FOR_VAR;

CppGen();
bool ExportUpdate(const std::string& fname, TopWindow* node, const std::map<std::string, std::string>& params, std::string& err);
auto Import(const std::string& path, std::map<std::string, std::string>& params, std::string& err) -> std::unique_ptr<TopWindow>;
static auto AltFName(const std::string& path) -> std::string;

const std::string& GetName() const { return m_name; }
const std::string& GetVName() const { return m_vname; }
//void SetName(const std::string& name) { m_name = name; }
//void SetVName(const std::string& name) { m_vname = name; }
void SetNamesFromId(const std::string& fname);

std::string GetIndent();
std::string DefaultForVarName();

struct Var
{
std::string type;
Expand All @@ -27,12 +33,6 @@ class CppGen
: name(n), type(t), init(i), flags(f) {}
};

const std::string& GetName() const { return m_name; }
const std::string& GetVName() const { return m_vname; }
//void SetName(const std::string& name) { m_name = name; }
//void SetVName(const std::string& name) { m_vname = name; }
void SetNamesFromId(const std::string& fname);

std::string CreateVar(const std::string& type, const std::string& init, int flags, const std::string& scope = "");
bool CreateNamedVar(const std::string& name, const std::string& type, const std::string& init, int flags, const std::string& scope = "");
bool RenameVar(const std::string& oldn, const std::string& newn, const std::string& scope = "");
Expand Down
5 changes: 2 additions & 3 deletions src/imrad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,9 +787,6 @@ void LoadStyle()
auto& io = ImGui::GetIO();
io.Fonts->Clear();

ctx.dashTexId = ImRad::LoadTextureFromFile(
(rootPath + "/style/dash.png").c_str(), GL_NEAREST, GL_NEAREST, GL_REPEAT, GL_REPEAT).id;

//reload ImRAD UI first
StyleColors();
io.Fonts->AddFontFromFileTTF(fontPath.c_str(), fontSize);
Expand Down Expand Up @@ -2035,6 +2032,8 @@ int main(int argc, const char* argv[])
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init(glsl_version);
const ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
ctx.dashTexId = ImRad::LoadTextureFromFile(
(rootPath + "/style/dash.png").c_str(), GL_NEAREST, GL_NEAREST, GL_REPEAT, GL_REPEAT).id;

GetStyles();
programState = (ProgramState)-1;
Expand Down
32 changes: 26 additions & 6 deletions src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,13 @@ void TopWindow::Export(std::ostream& os, UIContext& ctx)
}
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";
Expand Down Expand Up @@ -1209,6 +1216,10 @@ void TopWindow::Import(cpp::stmt_iterator& sit, UIContext& ctx)
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;
Expand Down Expand Up @@ -1451,6 +1462,7 @@ TopWindow::Properties()
{ "size_x", &size_x },
{ "size_y", &size_y },
{ "closeOnEscape", &closeOnEscape },
{ "initialActivity", &initialActivity },
{ "animate", &animate },
};
}
Expand Down Expand Up @@ -1634,6 +1646,14 @@ bool TopWindow::PropertyUI(int i, UIContext& ctx)
ImGui::EndDisabled();
break;
case 16:
ImGui::BeginDisabled(kind != Activity);
ImGui::Text("initialActivity");
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-ImGui::GetFrameHeight());
changed = InputDirectVal("##initact", &initialActivity, ctx);
ImGui::EndDisabled();
break;
case 17:
ImGui::BeginDisabled(kind != Popup && kind != ModalPopup);
ImGui::Text("animate");
ImGui::TableNextColumn();
Expand Down Expand Up @@ -7021,7 +7041,7 @@ void Table::DoExport(std::ostream& os, UIContext& ctx)

if (!rowCount.empty())
{
os << "\n" << ctx.ind << rowCount.to_arg(ctx.forVarName) << "\n" << ctx.ind << "{\n";
os << "\n" << ctx.ind << rowCount.to_arg(ctx.codeGen->DefaultForVarName()) << "\n" << ctx.ind << "{\n";
ctx.ind_up();

if (!rowFilter.empty())
Expand All @@ -7032,7 +7052,7 @@ void Table::DoExport(std::ostream& os, UIContext& ctx)
ctx.ind_down();
}

os << ctx.ind << "ImGui::PushID(" << rowCount.index_name_or(CppGen::FOR_VAR) << ");\n";
os << ctx.ind << "ImGui::PushID(" << rowCount.index_name_or(ctx.codeGen->DefaultForVarName()) << ");\n";
}

os << ctx.ind << "ImGui::TableNextRow(0, ";
Expand Down Expand Up @@ -7354,7 +7374,7 @@ void Child::DoExport(std::ostream& os, UIContext& ctx)
}

if (!itemCount.empty()) {
os << ctx.ind << itemCount.to_arg(ctx.forVarName) << "\n" << ctx.ind << "{\n";
os << ctx.ind << itemCount.to_arg(ctx.codeGen->DefaultForVarName()) << "\n" << ctx.ind << "{\n";
ctx.ind_up();
}

Expand Down Expand Up @@ -8313,11 +8333,11 @@ void TabBar::DoExport(std::ostream& os, UIContext& ctx)

if (!tabCount.empty())
{
os << ctx.ind << tabCount.to_arg(ctx.forVarName) << "\n";
os << ctx.ind << tabCount.to_arg(ctx.codeGen->DefaultForVarName()) << "\n";
os << ctx.ind << "{\n";
ctx.ind_up();
//BeginTabBar does this
//os << ctx.ind << "ImGui::PushID(" << tabCount.index_name_or(CppGen::FOR_VAR) << ");\n";
//os << ctx.ind << "ImGui::PushID(" << tabCount.index_name_or(ctx.codeGen->DefaultForVarName()) << ");\n";
}
os << ctx.ind << "/// @separator\n\n";

Expand Down Expand Up @@ -8608,7 +8628,7 @@ void TabItem::DoExport(std::ostream& os, UIContext& ctx)
{
if (!tb->tabCount.empty())
{
idx = tb->tabCount.index_name_or(CppGen::FOR_VAR);
idx = tb->tabCount.index_name_or(ctx.codeGen->DefaultForVarName());
}
else
{
Expand Down
1 change: 1 addition & 0 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ struct TopWindow : UINode
direct_val<Placement> placement = None;
direct_val<bool> closeOnEscape = false;
direct_val<bool> animate = false;
direct_val<bool> initialActivity = false;

event<> onBackButton;
event<> onWindowAppearing;
Expand Down
6 changes: 3 additions & 3 deletions src/uicontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

void UIContext::ind_up()
{
ind += codeGen->INDENT;
ind += codeGen->GetIndent();
}

void UIContext::ind_down()
{
if (ind.size() >= codeGen->INDENT.size())
ind.resize(ind.size() - codeGen->INDENT.size());
if (ind.size() >= codeGen->GetIndent().size())
ind.resize(ind.size() - codeGen->GetIndent().size());
}
1 change: 0 additions & 1 deletion src/uicontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ struct UIContext
ImGuiStyle style;
const property_base* setProp = nullptr;
std::string setPropValue;
std::string forVarName;
ImTextureID dashTexId = 0;
bool* modified = nullptr;

Expand Down
2 changes: 0 additions & 2 deletions template/android/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ static void UpdateScreenRect();
void Draw()
{
// TODO: Call your drawing code here
//if (g_IOUserData.activeActivity == "")
// mainActivity.Open();
//mainActivity.Draw();

bool isOpen;
Expand Down

0 comments on commit fe1379d

Please sign in to comment.