TermOx
textline_core.hpp
1 #ifndef TERMOX_WIDGET_WIDGETS_DETAIL_TEXTLINE_CORE_HPP
2 #define TERMOX_WIDGET_WIDGETS_DETAIL_TEXTLINE_CORE_HPP
3 #include <termox/painter/glyph.hpp>
4 #include <termox/painter/glyph_string.hpp>
5 #include <termox/widget/align.hpp>
6 
7 namespace ox::detail {
8 
11  public:
13  int display_length,
14  ox::Align alignment,
15  int cursor_index = 0);
16 
17  public:
19  void set_text(ox::Glyph_string x);
20 
22  [[nodiscard]] auto text() const noexcept -> ox::Glyph_string const&;
23 
25  void clear();
26 
28  void set_display_length(int x);
29 
31  [[nodiscard]] auto display_length() const noexcept -> int;
32 
34  void set_alignment(ox::Align x);
35 
37  [[nodiscard]] auto alignment() const noexcept -> ox::Align;
38 
40  void increment_cursor();
41 
43  void decrement_cursor();
44 
46  void move_cursor_to_display(int x);
47 
49  void set_cursor_to_index(int i);
50 
52  void cursor_home();
53 
55  void cursor_end();
56 
59 
61  void erase_at_cursor();
62 
64  void erase_before_cursor();
65 
67  [[nodiscard]] auto cursor_position() const noexcept -> int;
68 
70 
71  [[nodiscard]] auto display_substr() const -> ox::Glyph_string;
72 
73  private:
74  ox::Glyph_string text_;
75  int display_length_;
76  ox::Align alignment_;
77  int cursor_index_;
78  int anchor_index_ = 0; // The left most displayable index.
79 };
80 
81 } // namespace ox::detail
82 #endif // TERMOX_WIDGET_WIDGETS_DETAIL_TEXTLINE_CORE_HPP
Holds a collection of Glyphs with a similar interface to std::string.
Definition: glyph_string.hpp:19
Provides a view of a Glyph_string and cursor position over a fixed length.
Definition: textline_core.hpp:10
auto display_length() const noexcept -> int
Return the current display_length.
Definition: textline_core.cpp:59
void set_cursor_to_index(int i)
Move the cursor to the Glyph at index i into the text, scrolls.
Definition: textline_core.cpp:102
void increment_cursor()
Move the cursor one position to the right, scrolling the text if needed.
Definition: textline_core.cpp:76
void cursor_home()
Move the Cursor to the first index and scroll.
Definition: textline_core.cpp:113
auto display_substr() const -> ox::Glyph_string
Return a substring that fits within width, accounting for cursor scroll.
Definition: textline_core.cpp:161
void decrement_cursor()
Move the cursor one position to the left, scrolling the text if needed.
Definition: textline_core.cpp:85
void set_alignment(ox::Align x)
Set either Left or Right Alignment, display_length interacts with this.
Definition: textline_core.cpp:64
auto cursor_position() const noexcept -> int
Return the position along the display length that the cursor is at.
Definition: textline_core.cpp:156
void set_text(ox::Glyph_string x)
Clear and reset the text.
Definition: textline_core.cpp:24
void erase_at_cursor()
Remove the Glyph at the cursor index.
Definition: textline_core.cpp:133
void clear()
Erase all text and reset anchor and cursor indices.
Definition: textline_core.cpp:38
void cursor_end()
Move the Cursor to the last index and scroll.
Definition: textline_core.cpp:119
void move_cursor_to_display(int x)
Move the cursor to the closest index to display position x.
Definition: textline_core.cpp:93
void set_display_length(int x)
Set the number of cells that the text will be displayed in.
Definition: textline_core.cpp:45
void insert_at_cursor(ox::Glyph x)
Inserts x at the current cursor index.
Definition: textline_core.cpp:126
auto text() const noexcept -> ox::Glyph_string const &
Return the full text contents.
Definition: textline_core.cpp:33
auto alignment() const noexcept -> ox::Align
Return the current alignment.
Definition: textline_core.cpp:71
void erase_before_cursor()
Remove the Glyph at one less the cursor index, if valid.
Definition: textline_core.cpp:145
Holds a description of a paintable tile on the screen.
Definition: glyph.hpp:11