Skip to content

Commit

Permalink
Split ims_gui.cpp into 5; Context menu for bufferwindow
Browse files Browse the repository at this point in the history
  • Loading branch information
Raais committed May 11, 2022
1 parent 6bf1ed0 commit 323b441
Show file tree
Hide file tree
Showing 9 changed files with 1,149 additions and 1,104 deletions.
83 changes: 82 additions & 1 deletion src/sources/ims_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,82 @@ void ImStudio::BufferWindow::drawall()
size = ImGui::GetWindowSize();
pos = ImGui::GetWindowPos();
{
if (ImGui::IsWindowHovered() && ImGui::GetIO().MouseClicked[1])
{
ImGui::OpenPopup("bwcontextmenu");

}
if (ImGui::BeginPopupContextWindow("bwcontextmenu"))
{
if (ImGui::BeginMenu("Add"))
{
if (ImGui::BeginMenu("Primitives"))
{
if (ImGui::MenuItem("Button"))
create("button",1);
if (ImGui::MenuItem("Radio Button"))
create("radio",1);
if (ImGui::MenuItem("Checkbox"))
create("checkbox",1);
if (ImGui::MenuItem("Text"))
create("text",1);
if (ImGui::MenuItem("Bullet"))
create("bullet",1);
if (ImGui::MenuItem("Arrow"))
create("arrow",1);
if (ImGui::MenuItem("Combo"))
create("combo",1);
if (ImGui::MenuItem("Listbox"))
create("listbox",1);
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Data Inputs"))
{
if (ImGui::MenuItem("Input Text"))
create("textinput",1);
if (ImGui::MenuItem("Input Int"))
create("inputint",1);
if (ImGui::MenuItem("Input Float"))
create("inputfloat",1);
if (ImGui::MenuItem("Input Double"))
create("inputdouble",1);
if (ImGui::MenuItem("Input Scientific"))
create("inputscientific",1);
if (ImGui::MenuItem("Input Float3"))
create("inputfloat3",1);
if (ImGui::MenuItem("Drag Int"))
create("dragint",1);
if (ImGui::MenuItem("Drag Int %"))
create("dragint100",1);
if (ImGui::MenuItem("Drag Float"))
create("dragfloat",1);
if (ImGui::MenuItem("Drag Float Small"))
create("dragfloatsmall",1);
if (ImGui::MenuItem("Slider Int"))
create("sliderint",1);
if (ImGui::MenuItem("Slider Float"))
create("sliderfloat",1);
if (ImGui::MenuItem("Slider Float Log"))
create("sliderfloatlog",1);
if (ImGui::MenuItem("Slider Angle"))
create("sliderangle",1);
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Color Pickers"))
{
if (ImGui::MenuItem("Color 1"))
create("color1",1);
if (ImGui::MenuItem("Color 2"))
create("color2",1);
if (ImGui::MenuItem("Color 3"))
create("color3",1);
ImGui::EndMenu();
}
ImGui::EndMenu();
}
ImGui::EndPopup();
}

for (auto i = objects.begin(); i != objects.end(); ++i)
{
Object &o = *i;
Expand All @@ -39,6 +115,7 @@ void ImStudio::BufferWindow::drawall()
}
}
}
hovered = ImGui::IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup);
}
ImGui::End();
ImGui::PopStyleColor(4);
Expand Down Expand Up @@ -79,7 +156,7 @@ ImStudio::BaseObject *ImStudio::BufferWindow::getbaseobj(int id)
return nullptr;
}

void ImStudio::BufferWindow::create(std::string type_)
void ImStudio::BufferWindow::create(std::string type_, bool atcursor)
{
idgen++;
if (!((open_child) &&
Expand All @@ -88,6 +165,10 @@ void ImStudio::BufferWindow::create(std::string type_)
{
// no child window open
Object widget(idgen, type_);
if (atcursor)
{
widget.pos = ImVec2(ImGui::GetMousePos().x - pos.x, ImGui::GetMousePos().y - pos.y);
}
objects.push_back(widget);
}
else
Expand Down
5 changes: 3 additions & 2 deletions src/sources/ims_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ namespace ImStudio
class BufferWindow
{
public:
bool state = false; //
bool state = true; //
ImVec2 size = {}; //
ImVec2 pos = {}; //
int idgen = 0; //
bool hovered = false; //
bool open_child = false; //
int open_child_id = -1; //
int selected_obj_id = -1; //
Expand All @@ -28,7 +29,7 @@ namespace ImStudio
void drawall ();
Object * getobj (int id);
BaseObject * getbaseobj (int id);
void create (std::string type_);
void create (std::string type_, bool atcursor = false);
};

}
109 changes: 109 additions & 0 deletions src/sources/ims_gui_menubar.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#include "ims_gui.h"

void ImStudio::GUI::ShowMenubar()
{
ImGui::SetNextWindowPos(mb_P);
ImGui::SetNextWindowSize(mb_S);
ImGui::Begin("Menubar", NULL,
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize |
ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse);

// MENU
if (ImGui::BeginMenuBar())
{
/// menu-file
if (ImGui::BeginMenu("File"))
{
#ifndef __EMSCRIPTEN__
if (ImGui::MenuItem("Export to clipboard"))
{
ImGui::LogToClipboard();
ImGui::LogText("%s", output.c_str());
ImGui::LogFinish();
};
#endif

if (ImGui::MenuItem("Exit"))
{
state = false;
};
ImGui::EndMenu();
}

/// menu-edit
if (ImGui::BeginMenu("Edit"))
{
if (ImGui::BeginMenu("Layout"))
{
ImGui::MenuItem("Compact", NULL, &compact);
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Behavior"))
{
ImGui::MenuItem("Static Mode", NULL, &bw.staticlayout);
ImGui::SameLine();
utils::HelpMarker("Toggle between static/linear layout and fixed/manual layout");

ImGui::EndMenu();
}
if (ImGui::MenuItem("Reset"))
{
bw.objects.clear();
bw.selected_obj_id = -1;
bw.open_child_id = -1;
bw.open_child = false;
bw.idgen = 0;
}

ImGui::EndMenu();
}

/// menu-tools
if (ImGui::BeginMenu("Tools"))
{
ImGui::MenuItem("Style Editor", NULL, &child_style);
ImGui::MenuItem("Demo Window", NULL, &child_demo);
ImGui::MenuItem("Metrics", NULL, &child_metrics);
ImGui::MenuItem("Stack Tool", NULL, &child_stack);
ImGui::MenuItem("Color Export", NULL, &child_color);
ImGui::EndMenu();
}

if (ImGui::BeginMenu("Help"))
{
if (ImGui::MenuItem("Resources")) child_resources = true;
if (ImGui::MenuItem("About ImStudio")) child_about = true;
ImGui::EndMenu();
}

ImGui::EndMenuBar();
}

// TAB
if (!compact)
{
if (ImGui::BeginTabBar("##Tabs", ImGuiTabBarFlags_None))
{
// tab-create
if (ImGui::BeginTabItem("Create"))
{
wksp_output = false;
wksp_create = true;
ImGui::EndTabItem();
}

// tab-output
if (ImGui::BeginTabItem("Output"))
{
wksp_create = false;
wksp_output = true;
ImGui::EndTabItem();
}

ImGui::EndTabBar();
}
}


ImGui::End();
}
21 changes: 21 additions & 0 deletions src/sources/ims_gui_output.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "ims_gui.h"

void ImStudio::GUI::ShowOutputWorkspace()
{
ImGui::SetNextWindowPos(ot_P);
ImGui::SetNextWindowSizeConstraints(ImVec2(0, -1), ImVec2(FLT_MAX, -1));
ImGui::SetNextWindowSize(ot_S);
ImGui::Begin("wksp_output", NULL, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar);
{
#ifdef __EMSCRIPTEN__
if(ImGui::Button("Copy")){
ImGui::LogToClipboard();
ImGui::LogText(output.c_str());
ImGui::LogFinish();
};
JsClipboard_SetClipboardText(ImGui::GetClipboardText());
#endif
ImStudio::GenerateCode(&output, &bw);
}
ImGui::End();
}
Loading

0 comments on commit 323b441

Please sign in to comment.