variable WIP
This commit is contained in:
@@ -1069,19 +1069,13 @@ bool WatchWindow::draw(Frontend &frontend)
|
|||||||
for (size_t i = 0; i < extra_slots.size(); ++i)
|
for (size_t i = 0; i < extra_slots.size(); ++i)
|
||||||
{
|
{
|
||||||
auto res_idx = frontend.target->data_idx_for_src_id(extra_slots[i].id);
|
auto res_idx = frontend.target->data_idx_for_src_id(extra_slots[i].id);
|
||||||
|
auto no_success = true;
|
||||||
if (res_idx)
|
if (res_idx)
|
||||||
{
|
{
|
||||||
const auto &node = *frontend.target->data_res_nodes[*res_idx];
|
const auto &node = *frontend.target->data_res_nodes[*res_idx];
|
||||||
if (!node.success || node.children.size() != 1)
|
if (node.success && node.children.size() == 1)
|
||||||
{
|
|
||||||
// TODO: allow edit
|
|
||||||
ImGui::TableNextRow();
|
|
||||||
ImGui::TableSetColumnIndex(0);
|
|
||||||
ImGui::Text("%s", extra_slots[i].bak.c_str());
|
|
||||||
ImGui::TableNextColumn();
|
|
||||||
ImGui::TextDisabled("<not available>");
|
|
||||||
} else
|
|
||||||
{
|
{
|
||||||
|
no_success = false;
|
||||||
const auto &child_node =
|
const auto &child_node =
|
||||||
*frontend.target->data_res_nodes[node.children[0]];
|
*frontend.target->data_res_nodes[node.children[0]];
|
||||||
this->draw_value(frontend, child_node.type_id, &extra_slots[i],
|
this->draw_value(frontend, child_node.type_id, &extra_slots[i],
|
||||||
@@ -1096,6 +1090,69 @@ bool WatchWindow::draw(Frontend &frontend)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (no_success)
|
||||||
|
{
|
||||||
|
auto &slot = extra_slots[i];
|
||||||
|
ImGui::TableNextRow();
|
||||||
|
ImGui::TableSetColumnIndex(0);
|
||||||
|
|
||||||
|
auto is_editing = false;
|
||||||
|
if (slot.is_editing)
|
||||||
|
{
|
||||||
|
is_editing = true;
|
||||||
|
if (slot.edit_was_started)
|
||||||
|
{
|
||||||
|
slot.edit_was_started = false;
|
||||||
|
ImGui::SetKeyboardFocusHere();
|
||||||
|
}
|
||||||
|
if (ImGui::InputText("##dddd", slot.buf, sizeof(slot.buf),
|
||||||
|
ImGuiInputTextFlags_AutoSelectAll
|
||||||
|
| ImGuiInputTextFlags_EnterReturnsTrue)
|
||||||
|
&& ImGui::IsItemDeactivatedAfterEdit())
|
||||||
|
{
|
||||||
|
if (slot.buf[0] != '\0')
|
||||||
|
{
|
||||||
|
frontend.target->backend->remove_data_node(slot.id);
|
||||||
|
using namespace data::source;
|
||||||
|
frontend.target->backend->add_data_node(Node{
|
||||||
|
.id = slot.id,
|
||||||
|
.type = Node::Type::source,
|
||||||
|
.data =
|
||||||
|
Source{.type = Source::Type::variable,
|
||||||
|
.data = Source::Variable{.expr_path = slot.buf}}});
|
||||||
|
}
|
||||||
|
|
||||||
|
slot.bak = slot.buf;
|
||||||
|
slot.is_editing = false;
|
||||||
|
}
|
||||||
|
if (ImGui::IsItemDeactivated())
|
||||||
|
{
|
||||||
|
memcpy(slot.buf, slot.bak.data(), slot.bak.size());
|
||||||
|
slot.buf[slot.bak.size()] = '\0';
|
||||||
|
slot.is_editing = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_editing)
|
||||||
|
{
|
||||||
|
char tree_id_buf[128];
|
||||||
|
std::snprintf(tree_id_buf, sizeof(tree_id_buf), "slot%lu", i);
|
||||||
|
// TODO: better id
|
||||||
|
ImGui::TreeNodeEx(tree_id_buf,
|
||||||
|
ImGuiTreeNodeFlags_SpanFullWidth
|
||||||
|
| ImGuiTreeNodeFlags_Leaf
|
||||||
|
| ImGuiTreeNodeFlags_NoTreePushOnOpen,
|
||||||
|
"%s", slot.bak.c_str());
|
||||||
|
if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)
|
||||||
|
&& ImGui::IsItemHovered())
|
||||||
|
{
|
||||||
|
slot.is_editing = true;
|
||||||
|
slot.edit_was_started = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImGui::TableNextColumn();
|
||||||
|
ImGui::TextDisabled("<not available>");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::TableNextRow();
|
ImGui::TableNextRow();
|
||||||
|
|||||||
Reference in New Issue
Block a user