TermOx
textbox_base.hpp
1 #ifndef TERMOX_WIDGET_WIDGETS_DETAIL_TEXTBOX_BASE_HPP
2 #define TERMOX_WIDGET_WIDGETS_DETAIL_TEXTBOX_BASE_HPP
3 #include <cstddef>
4 
5 #include <signals_light/signal.hpp>
6 
7 #include <termox/painter/glyph_string.hpp>
8 #include <termox/widget/point.hpp>
9 #include <termox/widget/widgets/text_view.hpp>
10 
11 namespace ox::detail {
12 
14 class Textbox_base : public Text_view {
15  private:
17 
18  protected:
20  explicit Textbox_base(Glyph_string text = U"",
21  Align alignment = Align::Left,
22  Wrap wrap = Wrap::Word,
24 
25  explicit Textbox_base(Parameters p);
26 
27  public:
29  sl::Signal<void(std::size_t n)> cursor_moved_left;
30 
32  sl::Signal<void(std::size_t n)> cursor_moved_right;
33 
35  sl::Signal<void(std::size_t n)> cursor_moved_up;
36 
38  sl::Signal<void(std::size_t n)> cursor_moved_down;
39 
40  public:
42  void set_cursor(Point position);
43 
45  void set_cursor(std::size_t index);
46 
48  void scroll_up(int n = 1) override;
49 
51  void scroll_down(int n = 1) override;
52 
54 
56  void cursor_up(int n = 1);
57 
59 
61  void cursor_down(int n = 1);
62 
64 
65  void cursor_left(int n = 1);
66 
68 
69  void cursor_right(int n = 1);
70 
71  protected:
73  [[nodiscard]] auto cursor_index() const -> int;
74 
76  auto resize_event(Area new_size, Area old_size) -> bool override;
77 
78  private:
80  void increment_cursor_right();
81 
83  void increment_cursor_left();
84 };
85 
86 } // namespace ox::detail
87 #endif // TERMOX_WIDGET_WIDGETS_DETAIL_TEXTBOX_BASE_HPP
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
Non-interactive box to display a given Glyph_string.
Definition: text_view.hpp:21
auto alignment() const -> Align
Return the currently used Alignment.
Definition: text_view.cpp:53
Brush insert_brush
Brush to be applied to all new incoming Glyphs, but not existing Glyphs.
Definition: text_view.hpp:33
auto wrap() const -> Wrap
Return the currently set text Wrap type.
Definition: text_view.cpp:61
auto text() -> Glyph_string &
Return the entire contents of the Text_view.
Definition: text_view.cpp:43
Implements cursor movement on top of a Text_view, for use by Textbox.
Definition: textbox_base.hpp:14
sl::Signal< void(std::size_t n)> cursor_moved_left
Emitted when the cursor moves left, passes along positions moved.
Definition: textbox_base.hpp:29
void cursor_right(int n=1)
Move the cursor n indices towards the end of contents.
Definition: textbox_base.cpp:80
Textbox_base(Glyph_string text=U"", Align alignment=Align::Left, Wrap wrap=Wrap::Word, Brush insert_brush=Brush{})
Construct with initial text, enable cursor.
Definition: textbox_base.cpp:9
void scroll_up(int n=1) override
Add cursor movement to Text_view::scroll_up.
Definition: textbox_base.cpp:31
void cursor_down(int n=1)
Move the cursor down n lines, scroll if at the bottom line.
Definition: textbox_base.cpp:59
void scroll_down(int n=1) override
Add cursor movement to Text_view::scroll_down.
Definition: textbox_base.cpp:41
sl::Signal< void(std::size_t n)> cursor_moved_up
Emitted when the cursor moves up, passes along positions moved.
Definition: textbox_base.hpp:35
sl::Signal< void(std::size_t n)> cursor_moved_down
Emitted when the cursor moves down, passes along positions moved.
Definition: textbox_base.hpp:38
void cursor_left(int n=1)
Move the cursor n indices towards the beginning of contents.
Definition: textbox_base.cpp:73
auto resize_event(Area new_size, Area old_size) -> bool override
Scroll to make the cursor visible if no longer on screen after resize.
Definition: textbox_base.cpp:92
void cursor_up(int n=1)
Move the cursor up n lines, scroll if at the top line.
Definition: textbox_base.cpp:48
auto cursor_index() const -> int
Return the index into contents that the cursor is located at.
Definition: textbox_base.cpp:87
void set_cursor(Point position)
Set the cursor to position, or the nearest Glyph if no glyph there.
Definition: textbox_base.cpp:20
sl::Signal< void(std::size_t n)> cursor_moved_right
Emitted when the cursor moves right, passes along positions moved.
Definition: textbox_base.hpp:32
Definition: text_view.hpp:23
Definition: widget.hpp:33