1 /* Classes for printing labelled rulers.
2 Copyright (C) 2023-2024 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
5 This file is part of GCC.
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)
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.
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/>. */
21 #ifndef GCC_TEXT_ART_RULER_H
22 #define GCC_TEXT_ART_RULER_H
24 #include "text-art/canvas.h"
28 /* A way to annotate a series of ranges of canvas coordinates
29 with text labels either above or, in this example, below:
30 ├───────┬───────┼───────┬───────┼───────┬───────┤
32 label A label B label C
33 with logic to ensure that the text labels don't overlap
39 enum class label_dir
{ ABOVE
, BELOW
};
46 x_ruler (label_dir dir
)
48 m_size (canvas::size_t (0, 0)),
52 void add_label (const canvas::range_t
&r
,
55 label_kind kind
= label_kind::TEXT
);
57 canvas::size_t get_size ()
63 void paint_to_canvas (canvas
&canvas
,
64 canvas::coord_t offset
,
67 void debug (const style_manager
&sm
);
70 /* A particular label within an x_ruler.
73 # x: 01234567890123456789012345678901234567890123456789
74 # y: 0: ├───────┬───────┼───────┬───────┼───────┬───────┤
76 # 2: label A label B label C
91 and m_text_coord is (2, 6).
92 The y cooordinates are stored with respect to label_dir::BELOW;
93 for label_dir::ABOVE we flip them when painting the ruler. */
98 label (const canvas::range_t
&range
, styled_string text
, style::id_t style_id
,
101 bool operator< (const label
&other
) const;
104 canvas::range_t m_range
;
105 styled_string m_text
;
106 style::id_t m_style_id
;
108 canvas::rect_t m_text_rect
; // includes any border
112 void ensure_layout ();
113 void update_layout ();
114 int get_canvas_y (int rel_y
) const;
116 label_dir m_label_dir
;
117 std::vector
<label
> m_labels
;
118 canvas::size_t m_size
;
119 bool m_has_layout
= false;
123 } // namespace text_art
125 #endif /* GCC_TEXT_ART_RULER_H */