| 1 |
/* Tree diagrams. |
| 2 |
Copyright (C) 2024-2025 Free Software Foundation, Inc. |
| 3 |
Contributed by David Malcolm <[email protected]>. |
| 4 |
|
| 5 |
This file is part of GCC. |
| 6 |
|
| 7 |
GCC is free software; you can redistribute it and/or modify it |
| 8 |
under the terms of the GNU General Public License as published by |
| 9 |
the Free Software Foundation; either version 3, or (at your option) |
| 10 |
any later version. |
| 11 |
|
| 12 |
GCC is distributed in the hope that it will be useful, but |
| 13 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
General Public License for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License |
| 18 |
along with GCC; see the file COPYING3. If not see |
| 19 |
<http://www.gnu.org/licenses/>. */ |
| 20 |
|
| 21 |
#ifndef GCC_TEXT_ART_TREE_WIDGET_H |
| 22 |
#define GCC_TEXT_ART_TREE_WIDGET_H |
| 23 |
|
| 24 |
#include "text-art/canvas.h" |
| 25 |
#include "text-art/widget.h" |
| 26 |
|
| 27 |
namespace text_art { |
| 28 |
|
| 29 |
class dump_widget_info; |
| 30 |
|
| 31 |
class tree_widget : public widget |
| 32 |
{ |
| 33 |
public: |
| 34 |
tree_widget (std::unique_ptr<widget> node, |
| 35 |
const theme &theme, |
| 36 |
style::id_t style_id) |
| 37 |
: m_node (std::move (node)), |
| 38 |
m_theme (theme), |
| 39 |
m_style_id (style_id) |
| 40 |
{ |
| 41 |
} |
| 42 |
|
| 43 |
static std::unique_ptr<tree_widget> |
| 44 |
make (styled_string str, const theme &theme, style::id_t style_id); |
| 45 |
|
| 46 |
static std::unique_ptr<tree_widget> |
| 47 |
make (const dump_widget_info &dwi, pretty_printer *pp); |
| 48 |
|
| 49 |
static std::unique_ptr<tree_widget> |
| 50 |
make (const dump_widget_info &dwi, const char *str); |
| 51 |
|
| 52 |
static std::unique_ptr<tree_widget> |
| 53 |
from_fmt (const dump_widget_info &dwi, |
| 54 |
printer_fn format_decoder, |
| 55 |
const char *fmt, ...) |
| 56 |
ATTRIBUTE_GCC_PPDIAG(3, 4); |
| 57 |
|
| 58 |
const char *get_desc () const override; |
| 59 |
canvas::size_t calc_req_size () final override; |
| 60 |
void update_child_alloc_rects () final override; |
| 61 |
void paint_to_canvas (canvas &canvas) final override; |
| 62 |
|
| 63 |
void add_child (std::unique_ptr<widget> child) |
| 64 |
{ |
| 65 |
if (child) |
| 66 |
m_children.push_back (std::move (child)); |
| 67 |
} |
| 68 |
|
| 69 |
size_t get_num_children () const |
| 70 |
{ |
| 71 |
return m_children.size (); |
| 72 |
} |
| 73 |
|
| 74 |
private: |
| 75 |
std::unique_ptr<widget> m_node; |
| 76 |
std::vector<std::unique_ptr<widget>> m_children; |
| 77 |
const theme &m_theme; |
| 78 |
style::id_t m_style_id; |
| 79 |
}; |
| 80 |
|
| 81 |
} // namespace text_art |
| 82 |
|
| 83 |
#endif /* GCC_TEXT_ART_TREE_WIDGET_H */ |