Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tpecholt committed Jul 3, 2024
1 parent 0de88b1 commit 00a3a43
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 26 deletions.
44 changes: 23 additions & 21 deletions src/cppgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ bool CppGen::ExportUpdate(
m_vname = (char)std::tolower(m_name[0]) + m_name.substr(1);
*/

//export node before ExportH
//TopWindow::Export generates some variables on the fly
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;
std::ostringstream code;
node->Export(code, ctx);
for (const std::string& e : ctx.errors)
err += e + "\n";

//export .h
auto hpath = fs::path(fname).replace_extension(".h");
if (!fs::exists(hpath) || fs::is_empty(hpath))
{
Expand All @@ -85,7 +100,8 @@ bool CppGen::ExportUpdate(
auto origNames = ExportH(fout, fprev, m_hname, node);
m_hname = hpath.filename().string();
fout.close();


//export .cpp
auto fpath = fs::path(fname).replace_extension(".cpp");
if (!fs::exists(fpath) || fs::is_empty(fpath))
{
Expand All @@ -104,7 +120,7 @@ bool CppGen::ExportUpdate(
fin.close();
fprev.seekg(0);
fout.open(fpath, std::ios::trunc);
err = ExportCpp(fout, fprev, origNames, params, node);
ExportCpp(fout, fprev, origNames, params, node, code.str());
return true;
}

Expand Down Expand Up @@ -415,13 +431,14 @@ CppGen::ExportH(
}

//follows fprev and overwrites generated members/functions only
std::string
void
CppGen::ExportCpp(
std::ostream& fout,
std::istream& fprev,
const std::array<std::string, 3>& origNames, //name, vname, old header name
const std::map<std::string, std::string>& params,
TopWindow* node
TopWindow* node,
const std::string& code
)
{
int level = 0;
Expand All @@ -432,19 +449,6 @@ CppGen::ExportCpp(
std::set<std::string> events;
auto animPos = node->animate ? (TopWindow::Placement)node->placement : TopWindow::None;

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;
std::ostringstream code;
node->Export(code, ctx);
std::string err;
for (const std::string& e : ctx.errors)
err += e + "\n";

//xpos == 0 => copy until current position
//xpos > 0 => copy until xpos
//xpos < 0 => copy except last xpos characters
Expand Down Expand Up @@ -487,7 +491,7 @@ CppGen::ExportCpp(
{
events.insert(name);
skip_to_level = level - 1;
WriteStub(fout, "Draw", node->kind, animPos, params, code.str());
WriteStub(fout, "Draw", node->kind, animPos, params, code);
}
else if (name == "Init")
{
Expand Down Expand Up @@ -571,7 +575,7 @@ CppGen::ExportCpp(
if (events.count(name))
continue;
std::ostringstream os;
if (WriteStub(os, name, node->kind, animPos, params, code.str())) {
if (WriteStub(os, name, node->kind, animPos, params, code)) {
events.insert(name);
fout << "\nvoid " << m_name << os.str() << "\n";
}
Expand All @@ -592,8 +596,6 @@ CppGen::ExportCpp(
fout << "const " << arg << "& args";
fout << ")\n{\n}\n";
}

return err;
}

//we always replace code of all generated functions because parameters and code depend
Expand Down
4 changes: 2 additions & 2 deletions src/cppgen.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class CppGen
void CreateH(std::ostream& out);
void CreateCpp(std::ostream& out);
auto ExportH(std::ostream& out, std::istream& prev, const std::string& origHName, TopWindow* node) -> std::array<std::string, 3>;
auto ExportCpp(std::ostream& out, std::istream& prev, const std::array<std::string, 3>& origNames, const std::map<std::string, std::string>& params, TopWindow* node) -> std::string;
bool WriteStub(std::ostream& fout, const std::string& id, TopWindow::Kind kind, TopWindow::Placement animPos, const std::map<std::string, std::string>& params = {}, const std::string& code = {});
void ExportCpp(std::ostream& out, std::istream& prev, const std::array<std::string, 3>& origNames, const std::map<std::string, std::string>& params, TopWindow* node, const std::string& code);
bool WriteStub(std::ostream& fout, const std::string& id, TopWindow::Kind kind, TopWindow::Placement animPos, const std::map<std::string, std::string>& params = {}, const std::string& code = {});
auto ImportCode(std::istream& in, std::map<std::string, std::string>& params) -> std::unique_ptr<TopWindow>;

bool ParseFieldDecl(const std::string& stype, const std::vector<std::string>& line, int flags);
Expand Down
5 changes: 3 additions & 2 deletions src/imrad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1934,6 +1934,8 @@ int main(int argc, const char* argv[])
// Setup Dear ImGui context
IMGUI_CHECKVERSION();
ImGui::CreateContext();
auto& g = *ImGui::GetCurrentContext();
g.ConfigNavWindowingKeyNext = g.ConfigNavWindowingKeyPrev = ImGuiKey_None; //disable imgui ctrl+tab menu
ImGui::GetIO().IniFilename = INI_FILE_NAME;
AddINIHandler();
ImGuiIO& io = ImGui::GetIO();
Expand All @@ -1945,9 +1947,8 @@ int main(int argc, const char* argv[])
// Setup Platform/Renderer backends
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init(glsl_version);

const ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);

GetStyles();
programState = (ProgramState)-1;
bool lastVisible = true;
Expand Down
6 changes: 5 additions & 1 deletion src/imrad.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ struct BoxLayout
it.size = size;
}
//for use in SetCursorX/Y
operator float()
float GetPos()
{
if (prevItems.size() <= items.size()) //stop positioning - widgets changed
return HORIZ ? ImGui::GetCursorPosX() : ImGui::GetCursorPosY();
Expand All @@ -262,6 +262,10 @@ struct BoxLayout
pos += prevItems[items.size()].spacing;
return pos;
}
operator float()
{
return GetPos();
}
//for use in SetNextItemWidth/ctor
float GetSize(bool sameLine = false)
{
Expand Down

0 comments on commit 00a3a43

Please sign in to comment.