1 #ifndef TERMOX_WIDGET_WIDGETS_TEXT_DISPLAY_HPP
2 #define TERMOX_WIDGET_WIDGETS_TEXT_DISPLAY_HPP
6 #include <signals_light/signal.hpp>
8 #include <termox/painter/brush.hpp>
9 #include <termox/painter/glyph_string.hpp>
10 #include <termox/painter/painter.hpp>
11 #include <termox/widget/align.hpp>
12 #include <termox/widget/point.hpp>
13 #include <termox/widget/widget.hpp>
14 #include <termox/widget/wrap.hpp>
25 Align alignment = Align::Left;
26 Wrap wrap = Wrap::Word;
55 Wrap
wrap = Wrap::Word,
81 [[nodiscard]] auto
alignment() const -> Align;
87 [[nodiscard]] auto
wrap() const -> Wrap;
120 [[nodiscard]] auto
row_length(
int y) const ->
int;
135 [[nodiscard]] auto
index_at(Point position) const ->
int;
150 [[nodiscard]] auto
line_at(
int index) const ->
int;
153 [[nodiscard]] auto
top_line() const ->
int;
159 [[nodiscard]] auto
last_line() const ->
int;
168 [[nodiscard]] auto
line_length(
int line) const ->
int;
171 [[nodiscard]] auto
end_index() const ->
int;
186 Glyph_string contents_;
191 std::vector<Line_info> display_state_ = {Line_info{0, 0}};
195 [[nodiscard]]
auto text_view(Glyph_string text = U
"",
196 Align alignment = Align::Left,
197 Wrap wrap = Wrap::Word)
198 -> std::unique_ptr<Text_view>;
201 [[nodiscard]]
auto text_view(Text_view::Parameters p)
202 -> std::unique_ptr<Text_view>;
Holds the look of any paintable object with Traits and Colors.
Definition: brush.hpp:13
Holds a collection of Glyphs with a similar interface to std::string.
Definition: glyph_string.hpp:19
Contains functions to paint Glyphs to a Widget's screen area.
Definition: painter.hpp:21
Non-interactive box to display a given Glyph_string.
Definition: text_view.hpp:21
void update_display(int from_line=0)
Recalculate the text layout via display_state_.
Definition: text_view.cpp:298
auto alignment() const -> Align
Return the currently used Alignment.
Definition: text_view.cpp:53
auto index_at(Point position) const -> int
Return the index into the contents from a physical Point on the Widget.
Definition: text_view.cpp:166
sl::Signal< void(int n)> scrolled_down
Emitted when text is scrolled down. Sends number of lines scrolled by.
Definition: text_view.hpp:39
auto paint_event(Painter &p) -> bool override
Paint the portion of contents that is currently visible on screen.
Definition: text_view.cpp:211
sl::Signal< void(int n)> scrolled_to
Emitted when text is scrolled, sends the top line.
Definition: text_view.hpp:42
Brush insert_brush
Brush to be applied to all new incoming Glyphs, but not existing Glyphs.
Definition: text_view.hpp:33
auto display_position(int index) const -> Point
Return the position of the Glyph at index.
Definition: text_view.cpp:183
void set_wrap(Wrap w)
Set the type of text wrapping at line boundaries.
Definition: text_view.cpp:55
auto last_index_at(int line) const -> int
Returns one past the last index of the last Glyph at line number line.
Definition: text_view.cpp:281
void pop_back()
Remove the last Glyph from the current contents. No-op if this->empty();.
Definition: text_view.cpp:101
auto wrap() const -> Wrap
Return the currently set text Wrap type.
Definition: text_view.cpp:61
void insert(Glyph_string text, int index)
Inserts text starting at index into the current contents.
Definition: text_view.cpp:63
auto bottom_line() const -> int
Return line number that is being displayed at the bottom of the Widget.
Definition: text_view.cpp:266
void set_top_line(int n)
Set the top line, by row index.
Definition: text_view.cpp:159
sl::Signal< void(int)> line_count_changed
Emitted when total line count changes.
Definition: text_view.hpp:48
auto first_index_at(int line) const -> int
Return the index of the first Glyph at line number line.
Definition: text_view.cpp:274
void update() override
Add call to Text_view::update_display() before posting Paint_event.
Definition: text_view.cpp:201
auto line_at(int index) const -> int
Return the line number that contains index.
Definition: text_view.cpp:252
virtual void scroll_up(int n=1)
Scroll the display up by n lines.
Definition: text_view.cpp:119
void append(Glyph_string text)
Inserts text to the end of the current contents.
Definition: text_view.cpp:79
auto end_index() const -> int
Return the index of the last Glyph in contents.
Definition: text_view.cpp:296
void erase(int index, int length=Glyph_string::npos)
Remove Glyphs from contents starting at index, for length Glyphs.
Definition: text_view.cpp:88
auto row_length(int y) const -> int
Return the length of the line at row y.
Definition: text_view.cpp:145
auto display_height() const -> int
Return the number of lines currently displayed.
Definition: text_view.cpp:151
virtual void scroll_down(int n=1)
Scroll the display down by n lines.
Definition: text_view.cpp:132
void clear()
Remove all Glyphs from the this text display.
Definition: text_view.cpp:110
auto text() -> Glyph_string &
Return the entire contents of the Text_view.
Definition: text_view.cpp:43
sl::Signal< void(Glyph_string const &)> contents_modified
Emitted when contents are modified. Sends a reference to the contents.
Definition: text_view.hpp:45
auto line_count() const -> int
Return the total number of lines in display_state_.
Definition: text_view.cpp:157
sl::Signal< void(int n)> scrolled_up
Emitted when text is scrolled up. Sends number of lines scrolled by.
Definition: text_view.hpp:36
Text_view(Glyph_string text=U"", Align alignment=Align::Left, Wrap wrap=Wrap::Word, Brush insert_brush=Brush{})
Construct a Text_view with initial Glyph_string text.
Definition: text_view.cpp:19
auto top_line() const -> int
Return the line number that is being displayed at the top of the Widget.
Definition: text_view.cpp:264
void set_alignment(Align type)
Set the Alignment, changing how the contents are displayed.
Definition: text_view.cpp:47
void set_text(Glyph_string text)
Replace the current contents with text.
Definition: text_view.cpp:34
auto last_line() const -> int
Return the index into display_state_ of the last line.
Definition: text_view.cpp:272
auto line_length(int line) const -> int
Return the number of Glyphs contained at line index line.
Definition: text_view.cpp:289
Definition: text_view.hpp:23