美化一下输出结果void ArrangeHolder(string& Holder)
{
std::regex replaceAllPattern(R"(\|)");
std::string temp = std::regex_replace(Holder, replaceAllPattern, "-");
temp.replace(0, 1, 1, '|');
temp.replace(temp.size() - 4, 1, 1, '|');
Holder = temp;
}
void RetrieveChildren(Gtk::Widget* container)
{
static string Holder;
auto first_child = container->get_first_child();
auto curr_child = first_child;
if (first_child)
{
Holder += "|-- ";
while (curr_child)
{
ArrangeHolder(Holder);
std::cout << Holder << curr_child->get_name() << std::endl;
RetrieveChildren(curr_child) ;
curr_child = curr_child->get_next_sibling();
if (!curr_child)
{
Holder.erase(Holder.size() - 4);
std::cout << Holder << std::endl;
}
}
}
};
这样输出关系就可观一点:|-- gtkmm__GtkBox
|-- |-- gtkmm__GtkLabel
|--
|-- gtkmm__GtkBox
|-- |-- gtkmm__GtkLabel
|-- |-- gtkmm__GtkButton
|-- --- |-- gtkmm__GtkLabel
|-- ---
|--
|-- gtkmm__GtkBox
|-- |-- gtkmm__GtkLabel
|--
|-- gtkmm__GtkBox