This commit is contained in:
T0b1
2023-06-29 02:13:07 +02:00
parent 83fb234d5c
commit 6f0b3b9e99
4 changed files with 65 additions and 17 deletions

View File

@@ -101,6 +101,10 @@ void Frontend::run_frame()
auto &entry = this->target->expr_cache[i];
if (!entry.used_this_frame)
{
if (entry.is_cstr)
{
this->target->backend->remove_data_node(entry.id2);
}
this->target->backend->remove_data_node(entry.id);
this->target->expr_cache.erase(this->target->expr_cache.begin() + i);
} else

View File

@@ -82,7 +82,9 @@ namespace dbgui::frontend
{
std::string expr_path;
size_t id;
size_t id2;
bool used_this_frame = false;
bool is_cstr = false;
};
Target(std::string filename);
@@ -115,26 +117,37 @@ namespace dbgui::frontend
return &*data_res_nodes[*idx];
}
size_t find_or_create_expr_path(std::string &&path)
size_t find_or_create_expr_path(std::string &&path, bool is_cstr = false)
{
for (auto &entry : expr_cache)
{
if (entry.expr_path == path)
{
entry.used_this_frame = true;
return entry.id;
return entry.is_cstr ? entry.id2 : entry.id;
}
}
using namespace data::source;
auto id = this->id++;
auto id = this->id++;
size_t cstr_id = -1;
this->backend->add_data_node(
Node{.id = id,
.type = Node::Type::source,
.data = Source{.type = Source::Type::variable,
.data = Source::Variable{.expr_path = path}}});
expr_cache.push_back(ExprCacheEntry{
.expr_path = std::move(path), .id = id, .used_this_frame = true});
if (is_cstr)
{
cstr_id = this->id++;
this->backend->add_data_node(Node{.id = cstr_id,
.type = Node::Type::read_cstr,
.data = ReadAsCStr{.src_id = id}});
}
expr_cache.push_back(ExprCacheEntry{.expr_path = std::move(path),
.id = id,
.id2 = cstr_id,
.used_this_frame = true,
.is_cstr = is_cstr});
return id;
}

View File

@@ -1283,9 +1283,10 @@ void WatchWindow::draw_value(Frontend &frontend,
if (!is_editing)
{
tree_open =
ImGui::TreeNodeEx(tree_id_buf, ImGuiTreeNodeFlags_SpanFullWidth, "%.*s",
static_cast<int>(name_end - name_begin), name_begin);
tree_open = ImGui::TreeNodeEx(
tree_id_buf,
ImGuiTreeNodeFlags_SpanFullWidth | ImGuiTreeNodeFlags_SpanAvailWidth,
"%.*s", static_cast<int>(name_end - name_begin), name_begin);
if (name.index() == 1
&& ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)
&& ImGui::IsItemHovered())
@@ -1542,20 +1543,33 @@ void WatchWindow::draw_value(Frontend &frontend,
{
// TODO: make this func be able to not print the "outer" line
// and just accept a bool to only draw the containing value
std::string path{"*"};
std::string path{};
if (type_id.sub_type != Type::i8)
{
// TODO: better check if this is really a string
path = "*";
}
// why cant i just path name_begin, name_end to string_view? :[
construct_expr_path(
path, expr_path,
std::string_view{name_begin,
static_cast<size_t>(name_end - name_begin)});
auto src_id =
frontend.target->find_or_create_expr_path(std::move(path));
auto src_id = frontend.target->find_or_create_expr_path(
std::move(path), type_id.sub_type == Type::i8);
auto res_idx = frontend.target->data_idx_for_src_id(src_id);
if (res_idx)
{
const auto &node = *frontend.target->data_res_nodes[*res_idx];
if (node.success && node.children.size() == 1)
if (type_id.sub_type == Type::i8 && node.success)
{
// TODO: make span whole row (see https://github.com/ocornut/imgui/issues/3565)
assert(node.type_id.type == Type::custom);
assert(node.vec_data().back() == '\0');
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(1);
ImGui::TextWrapped("\"%s\"", node.vec_data().data());
} else if (node.success && node.children.size() == 1)
{
auto data_idx = node.children[0];
const auto &data_node =