Skip to content

Commit

Permalink
app: reuses the same bottom-left zone to edit component
Browse files Browse the repository at this point in the history
  • Loading branch information
quesnel committed Jul 11, 2024
1 parent 2cc7b6c commit 1f60b70
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 74 deletions.
8 changes: 6 additions & 2 deletions app/gui/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
namespace irt {

template<class T, class M>
constexpr std::ptrdiff_t offset_of(const M T::*member)
constexpr std::ptrdiff_t offset_of(const M T::* member)
{
return reinterpret_cast<std::ptrdiff_t>(
&(reinterpret_cast<T*>(0)->*member));
Expand All @@ -44,7 +44,7 @@ constexpr std::ptrdiff_t offset_of(const M T::*member)
//! }
//! @endcode
template<class T, class M>
constexpr T& container_of(M* ptr, const M T::*member)
constexpr T& container_of(M* ptr, const M T::* member)
{
return *reinterpret_cast<T*>(reinterpret_cast<intptr_t>(ptr) -
offset_of(member));
Expand Down Expand Up @@ -284,6 +284,7 @@ class grid_component_editor_data

void show(component_editor& ed) noexcept;
void show_selected_nodes(component_editor& ed) noexcept;
bool need_show_selected_nodes(component_editor& ed) noexcept;

//! Get the underlying component_id.
component_id get_id() const noexcept { return m_id; }
Expand Down Expand Up @@ -314,6 +315,7 @@ class graph_component_editor_data

void show(component_editor& ed) noexcept;
void show_selected_nodes(component_editor& ed) noexcept;
bool need_show_selected_nodes(component_editor& ed) noexcept;

//! Get the underlying component_id.
component_id get_id() const noexcept { return m_id; }
Expand Down Expand Up @@ -363,6 +365,7 @@ class hsm_component_editor_data

void show(component_editor& ed) noexcept;
void show_selected_nodes(component_editor& ed) noexcept;
bool need_show_selected_nodes(component_editor& ed) noexcept;

// void load(component_id c_id, model_id m_id) noexcept;
// void load(model_id m_id) noexcept;
Expand Down Expand Up @@ -401,6 +404,7 @@ class generic_component_editor_data

void show(component_editor& ed) noexcept;
void show_selected_nodes(component_editor& ed) noexcept;
bool need_show_selected_nodes(component_editor& ed) noexcept;

//! Before running any ImNodes functions, pre-move all children to force
//! position for all new children.
Expand Down
107 changes: 53 additions & 54 deletions app/gui/component-editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ static void show_file_access(application& app, component& compo) noexcept

static void show_input_output_ports(component& compo) noexcept
{
if (ImGui::CollapsingHeader("X ports")) {
if (ImGui::CollapsingHeader("X ports", ImGuiTreeNodeFlags_DefaultOpen)) {
if (ImGui::BeginTable("X",
3,
ImGuiTableFlags_Resizable |
Expand Down Expand Up @@ -250,7 +250,7 @@ static void show_input_output_ports(component& compo) noexcept
}
}

if (ImGui::CollapsingHeader("Y ports")) {
if (ImGui::CollapsingHeader("Y ports", ImGuiTreeNodeFlags_DefaultOpen)) {
if (ImGui::BeginTable("Y",
3,
ImGuiTableFlags_Resizable |
Expand Down Expand Up @@ -301,74 +301,73 @@ static void show_data(application& app,
data_array<T, ID>& data,
std::string_view /*title*/) noexcept
{
T* del = nullptr;
T* element = nullptr;

while (data.next(element)) {
if (del) {
data.free(*del);
del = nullptr;
}
for (auto& element : data) {
const auto compo_id = element.get_id();
auto& compo = app.mod.components.get(compo_id);

auto tab_item_flags = ImGuiTabItemFlags_None;
if (auto* c = app.mod.components.try_to_get(element->get_id()); c) {
format(ed.title,
"{}##{}",
c->name.c_str(),
get_index(app.mod.components.get_id(c)));

if (ed.need_to_open(app.mod.components.get_id(c))) {
tab_item_flags = ImGuiTabItemFlags_SetSelected;
ed.clear_request_to_open();
}
format(ed.title, "{}##{}", compo.name.c_str(), get_index(compo_id));

bool open = true;
if (ImGui::BeginTabItem(ed.title.c_str(), &open, tab_item_flags)) {
static ImGuiTableFlags flags =
ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_RowBg |
ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable |
ImGuiTableFlags_Reorderable;
if (ed.need_to_open(compo_id)) {
tab_item_flags = ImGuiTabItemFlags_SetSelected;
ed.clear_request_to_open();
}

if (ImGui::BeginTable("##ed", 2, flags)) {
ImGui::TableSetupColumn(
"Settings", ImGuiTableColumnFlags_WidthStretch, 0.2f);
ImGui::TableSetupColumn(
"Graph", ImGuiTableColumnFlags_WidthStretch, 0.8f);
ImGui::TableHeadersRow();
auto open = true;
if (ImGui::BeginTabItem(ed.title.c_str(), &open, tab_item_flags)) {
constexpr auto flags =
ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_RowBg |
ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable |
ImGuiTableFlags_Reorderable;

if (ImGui::BeginTable("##ed", 2, flags)) {
ImGui::TableSetupColumn("Component settings",
ImGuiTableColumnFlags_WidthStretch,
0.2f);
ImGui::TableSetupColumn(
"Graph", ImGuiTableColumnFlags_WidthStretch, 0.8f);
ImGui::TableHeadersRow();

ImGui::TableNextRow();
ImGui::TableNextRow();

ImGui::TableSetColumnIndex(0);

ImGui::TableSetColumnIndex(0);
auto copy_name = c->name;
if (ImGui::InputFilteredString("Name", copy_name))
c->name = copy_name;
auto copy_name = compo.name;
if (ImGui::InputFilteredString("Name", copy_name))
compo.name = copy_name;

if (ImGui::CollapsingHeader("path"))
show_file_access(app, *c);
auto flags = ImGuiTabItemFlags_None;
if (element.need_show_selected_nodes(ed)) {
flags = ImGuiTabItemFlags_SetSelected;
}

show_input_output_ports(*c);
if (ImGui::BeginTabBar("Settings", ImGuiTabBarFlags_None)) {
if (ImGui::BeginTabItem("Save")) {
show_file_access(app, compo);
ImGui::EndTabItem();
}

if (ImGui::CollapsingHeader("selected"))
element->show_selected_nodes(ed);
if (ImGui::BeginTabItem("In/Out")) {
show_input_output_ports(compo);
ImGui::EndTabItem();
}

ImGui::TableSetColumnIndex(1);
element->show(ed);
if (ImGui::BeginTabItem("Specific", nullptr, flags)) {
element.show_selected_nodes(ed);
ImGui::EndTabItem();
}

ImGui::EndTable();
ImGui::EndTabBar();
}
ImGui::EndTabItem();
}

if (!open) {
del = element;
ImGui::TableSetColumnIndex(1);
element.show(ed);

ImGui::EndTable();
}
} else {
del = element;
ImGui::EndTabItem();
}
}

if (del)
data.free(*del);
}

void component_editor::show() noexcept
Expand Down
6 changes: 6 additions & 0 deletions app/gui/generic/modeling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1430,4 +1430,10 @@ void generic_component_editor_data::show_selected_nodes(
});
}

bool generic_component_editor_data::need_show_selected_nodes(
component_editor& /*ed*/) noexcept
{
return not selected_nodes.empty();
}

} // namespace irt
6 changes: 6 additions & 0 deletions app/gui/graph/modeling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,12 @@ void graph_component_editor_data::show_selected_nodes(
component_editor& /*ed*/) noexcept
{}

bool graph_component_editor_data::need_show_selected_nodes(
component_editor& /*ed*/) noexcept
{
return false;
}

graph_editor_dialog::graph_editor_dialog() noexcept
{
graph.resize(30, undefined<component_id>());
Expand Down
6 changes: 6 additions & 0 deletions app/gui/grid/modeling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,12 @@ void grid_component_editor_data::show_selected_nodes(
component_editor& /*ed*/) noexcept
{}

bool grid_component_editor_data::need_show_selected_nodes(
component_editor& /*ed*/) noexcept
{
return false;
}

grid_editor_dialog::grid_editor_dialog() noexcept
{
grid.resize(5, 5, undefined<component_id>());
Expand Down
34 changes: 16 additions & 18 deletions app/gui/hsm/modeling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,23 +804,7 @@ void hsm_component_editor_data::show(component_editor& ed) noexcept
ImGui::BeginChild("##table-editor", ImVec2(0, table_heigth), false);
if (ImGui::BeginTabBar("##hsm-editor")) {
if (ImGui::BeginTabItem("editor")) {
if (ImGui::BeginTable("editor",
2,
ImGuiTableFlags_Resizable |
ImGuiTableFlags_NoSavedSettings |
ImGuiTableFlags_Borders)) {
ImGui::TableSetupColumn("Editor",
ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn(
"Parameter", ImGuiTableColumnFlags_WidthFixed, 128.f);

ImGui::TableNextColumn();
show_graph(*hsm);
ImGui::TableNextColumn();
show_panel(*hsm);
ImGui::EndTable();
}

show_graph(*hsm);
ImGui::EndTabItem();
}

Expand All @@ -841,8 +825,22 @@ void hsm_component_editor_data::show(component_editor& ed) noexcept
}

void hsm_component_editor_data::show_selected_nodes(
component_editor& ed) noexcept
{
auto& app = container_of(&ed, &application::component_ed);

auto* hsm = app.mod.hsm_components.try_to_get(m_hsm_id);
if (not hsm)
return;

show_panel(*hsm);
}

bool hsm_component_editor_data::need_show_selected_nodes(
component_editor& /*ed*/) noexcept
{}
{
return not m_selected_nodes.empty();
}

hsm_component_editor_data::hsm_component_editor_data(
const component_id id,
Expand Down

0 comments on commit 1f60b70

Please sign in to comment.